.net 导出excel 并保存至服务器指定路径,求样例,急!正确即采纳

2024年11月16日 19:57
有1个网友回答
网友(1):

//导出Excel
Workbook workBook = new Workbook();
....

//保存
string path = Request.PhysicalApplicationPath + "Upload\\Excel\\" + DateTime.Now.ToString("yyMMddHHmmss") + ".xls";
workBook.Save(path);//保存
//输出Excel
System.IO.FileInfo file = new System.IO.FileInfo(path);
Response.Clear();
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
Response.ContentType = "application/ms-excel";
Response.WriteFile(file.FullName);
Response.End();