【问题标题】:Opening Excel using EPPlus使用 EPPlus 打开 Excel
【发布时间】:2012-12-12 19:36:00
【问题描述】:

我正在尝试打开一个我使用 epplus 编写的 excel 文件。

我正在使用它打开它,它可以在开发服务器中工作,但在发布后就不行了。

System.Diagnostics.Process.Start(Server.MapPath("~\chart.xlsx"))

如何打开这个excel表格?

【问题讨论】:

    标签: asp.net vb.net excel epplus


    【解决方案1】:

    您的代码正在尝试打开 服务器上的 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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多