0

epplusを使って書いたExcelファイルを開こうとしています。

これを使用して開いています。開発サーバーでは機能しますが、公開後は機能しません。

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

このExcelシートを開くにはどうすればよいですか?

4

1 に答える 1

5

コードがサーバー上の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()
于 2012-12-12T19:57:09.043 に答える