使用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() 

您还需要记住,可能有多个用户同时访问您的应用程序。 如果您dynamic生成chart.xlsx文件,则一个请求的文件可能会覆盖该文件以获取其他请求。 最好将文件直接保存到响应中:

 Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" Response.AppendHeader("Content-Disposition", "attachment;filename=chart.xlsx") YourExcelPackage.SaveAs(Response.OutputStream) Response.End()