Web サイトで Excel 2007 を開くための ashx ファイルを既に作成しています。
test.aspx のコードは次のとおりです (test.htm を呼び出してポップアップを開きます)。
<a href="test.htm" target="_blank">Export</a>
test.htm のコードは次のとおりです: (iframe を使用して Excel ファイルを読み込みます)
<iframe src="handler1.ashx" style="height: 421px; width: 800px" ></iframe>
handle.ashx のコードは次のとおりです。
void ProcessRequest(HttpContext context)
{
string filePath = "E:/test.xlsx";
string filename = Path.GetFileName(filePath);
context.Response.Clear();
context.Response.AddHeader("Content-Disposition", "inline;filename=test.xlsx");
context.Response.Charset = "";
context.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
context.Response.WriteFile(filePath);
context.Response.Flush();
context.Response.End();
}
ただし、Excel ファイルは常に Microsoft Excel アプリケーションによって開かれます。私を助けてください。
どうもありがとう。