0
我想打开一个使用epplus编写的excel文件。使用EPPlus打开Excel
我打开它使用它,它在开发服务器中工作,但不是在发布后。
System.Diagnostics.Process.Start(Server.MapPath("~\chart.xlsx"))
我怎样才能打开这个Excel工作表?
我想打开一个使用epplus编写的excel文件。使用EPPlus打开Excel
我打开它使用它,它在开发服务器中工作,但不是在发布后。
System.Diagnostics.Process.Start(Server.MapPath("~\chart.xlsx"))
我怎样才能打开这个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()
您还需要记住,有可能是多个用户在同一时间访问您的应用程序。如果动态生成chart.xlsx
文件,则一个请求的文件可能会覆盖该文件以获取其他请求。将文件直接保存到响应中会更好:
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Response.AppendHeader("Content-Disposition", "attachment;filename=chart.xlsx")
YourExcelPackage.SaveAs(Response.OutputStream)
Response.End()
谢谢我今天学到了一些新东西 –