0

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 アプリケーションによって開かれます。私を助けてください。

どうもありがとう。

4

1 に答える 1

0

context.Response.WriteFile(filePath); // ファイル ブロックに書き込もうとしています。

その前に、すべてのデータをメモリにフェッチする必要があります。このように変更

context.Response.Write(YourExcelData);
于 2012-05-04T03:51:51.307 に答える