Drf*_*ink 0 vb.net asp.net excel epplus
我正在尝试打开使用epplus编写的Excel文件。
我使用它打开它,它可以在开发服务器中使用,但发布后不能使用。
System.Diagnostics.Process.Start(Server.MapPath("~\chart.xlsx"))
Run Code Online (Sandbox Code Playgroud)
我该如何打开这个Excel表格?
您的代码正在尝试打开服务器上的 Excel文件。即使您在服务器上安装了Excel,也可能没有人坐在服务器前才能看到它。
我怀疑您要在客户端上打开文件:
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AppendHeader("Content-Disposition", "attachment;filename=chart.xlsx")
Response.WriteFile(Server.MapPath("~/chart.xlsx"))
Response.End()
Run Code Online (Sandbox Code Playgroud)
您还需要记住,可能有多个用户同时访问您的应用程序。如果chart.xlsx动态生成文件,则一个请求的文件可能会覆盖另一个请求的文件。最好将文件直接保存到响应中:
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AppendHeader("Content-Disposition", "attachment;filename=chart.xlsx")
YourExcelPackage.SaveAs(Response.OutputStream)
Response.End()
Run Code Online (Sandbox Code Playgroud)