質問

I am generating a report in an MVC project. The user has the option of getting the report in either .pdf format or .xls

I am using Aspose.Cells for the Excel file generation. The ActionResult method below is called.

    [HttpGet]
    public ActionResult GenerateReport(string format, string filterDate = "")
    {
      //Processing occurs here to get the appropriate info from Db.
      var fileFormat   = format.ToUpper() == "PDF" ? Format.Pdf : Format.Csv;
      var contentType  = fileFormat == Format.Pdf ? "application/pdf" : "application/vnd.ms-excel";
      var makePdf      = fileFormat == Format.Pdf;
      var fileContents = register.GetReport(makePdf, filterDate);

      return File(fileContents, contentType, "Report");
    }

register.GetReport() merely determines if GetExcelVersion() or GetPdfVersion() is called.

    private void GetExcelVersion(MemoryStream stream, string name, string dateRequested = "")
    {

      var license = new Aspose.Cells.License();
      license.SetLicense("Aspose.Total.lic");
      var workbook = new Workbook();
      var worksheet = workbook.Worksheets[0];
      var cells = worksheet.Cells;
      //writes out the appropriate information to the excel spreadsheet here           

      workbook.Save(stream, new XlsSaveOptions(Aspose.Cells.SaveFormat.Excel97To2003));
     }

This works a charm in Firefox and IE10 but when testing on IE8 I receive the following alert from Excel:-

The File you are trying to open 'XXXXX', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now? Yes/No

Any ideas on what I am doing wrong?

Cheers!

役に立ちましたか?

解決

As Saqib Razzaq mentioned in the comments above. Turn off compatibility mode as mentioned here

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top