StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
this.Grid_SalesValue.RenderControl(htw); //Grid_SalesValue为GridView控件
string strHtml = sw.ToString().Trim();
strHtml = strHtml.Substring(1, strHtml.Length - 1);
string ExcelFileName = this.userinfo.Uid.Trim() + "SalV.xls";
string FilePhysicialPathName = Request.PhysicalApplicationPath + "//DownloadExcel//";
//生成的Excel文件名
string objectExcelFileName = Path.Combine(FilePhysicialPathName, ExcelFileName);
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();
//将保存好的excel文件进行锁定
// LockedExcel();
//下载表格
Response.Write("<script> window.open('http://cgqh306a/Rolling_Forecast/downloadexcel/" + this.userinfo.Uid.Trim() + "SalV.xls" + "')</script>");