簡體   English   中英

無法打開導出的xlsx文件

[英]Unable to open exported xlsx file

我正在嘗試以xlsx格式導出到excel,但是在嘗試打開文件時遇到此錯誤。 Excel無法打開文件'CertificationMetricsReport.xlsx',因為文件格式或文件擴展名無效。 確認文件未損壞,並且文件擴展名與文件格式匹配。

如果我將提供文件名CertificationReport.xls,則可以打開它。

這是代碼片段

 public void RenderedReportContent(byte[] fileContent)
    {
        try
        {
            Response.Clear();
            Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            Response.AddHeader("Content-Length", fileContent.Length.ToString());
            Response.AddHeader("Content-Disposition", "attachment; filename="CertificationReport.xlsx");
            Response.BinaryWrite(fileContent);
            Response.End();
        }
        catch (Exception ex)
        {
            if (!(ex is System.Threading.ThreadAbortException))
            {
                //Other error handling code here
            }
        }
    }

當我嘗試下載CertificationMetricsReport.xls時,它工作正常。

請幫助我下載xlsx文件。

也許您可以嘗試更改內容類型

到contenttype =“ application / vnd.ms-excel”; 或應用程序/八比特流

                    Response.Clear();
                    Response.Buffer = True;
                    Response.ContentType = "application/octet-stream";
                    Response.AddHeader("Content-Disposition", "attachment;filename=yourfile.xslx"
                    Response.BinaryWrite(YourFile);
                    Response.End();

您也可以嘗試使用response.flush

最后,在其他瀏覽器(如IE,Chrome,Firefox)中嘗試一下...

編輯: http ://social.msdn.microsoft.com/forums/en-US/3d539969-51c4-42bc-8289-6d70d8db7aff/prompt-while-downloading-a-file-for-open-or-save編輯2: 如何在HttpResponse中發送文件?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM