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

2024-11-16 19:57:49
推荐回答(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();