public void ExportToExcel(string FileName, string filePath)
{
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.gvOrder.RenderControl(htw); string strHtml = sw.ToString().Trim();
strHtml = strHtml.Substring(1, strHtml.Length - 1);
string FilePhysicialPathName = Request.PhysicalApplicationPath + filePath + "\\"; //生成的Excel文件名
string objectExcelFileName = Path.Combine(FilePhysicialPathName, FileName);
if (File.Exists(objectExcelFileName))
{
File.Delete(objectExcelFileName);
}
FileStream fs = new FileStream(objectExcelFileName, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs, Encoding.GetEncoding("GB2312"));
bw.Write(strHtml);
bw.Close();
fs.Close();
sw.Dispose();
htw.Dispose(); }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货