This project has moved and is read-only. For the latest updates, please go here.

Open.Excelwritter generates file is in a different file format than its extension indicates

Jul 17, 2012 at 11:13 AM

DoddleReport.OpenXml used as reference:

The output from the excel writer generates a warning while trying to open with Excel 2010.

indicating a file is in a different file format than its extension indicates.

 

Have installed from nuget, and take note of:

Install-Package DoddleReport.OpenXml and the warning to

use DoddleReport.OpenXml.ExcelReportWriter.

Code to generate is below where reportDoddle is the source of the data table in the form of a list.

 

 reportWriter = new DoddleReport.Writers.ExcelReportWriter();
                    ReportResult finalReport = new    ReportResult(reportDoddle, reportWriter, "");

 

Any ideas gratefully recieved.

 

Lower Bound

Jul 17, 2012 at 11:42 AM
Edited Jul 17, 2012 at 1:59 PM

Ok switched the writer to OpenXML namespace as below.

 

reportWriter = new DoddleReport.OpenXml.ExcelReportWriter();

 

I still have the warning when I try and open the file in Excel - indicating a file is in a different file format than its extension indicates.

 

The file output was xls, I switched to xlsx and Excel opens without complaint.


Jul 29, 2012 at 8:53 AM
Edited Jul 29, 2012 at 8:54 AM

Hi Lower Bound,

I'm experiencing the same issue but I'm using a ashx file within a Web Forms project.

Do you happen to know how I can get around this problem in my web forms project please ?

Thanks.

Jul 30, 2012 at 11:44 AM
hastings wrote:

Hi Lower Bound,

I'm experiencing the same issue but I'm using a ashx file within a Web Forms project.

Do you happen to know how I can get around this problem in my web forms project please ?

Thanks.

#1 Are you open the doddle report into a html window or exporting the file?

#2 Are we talking about the report flagging a content problem when opening in Excel?

Jul 30, 2012 at 6:39 PM
Edited Jul 30, 2012 at 6:40 PM

Hi Lower Bound,

Thanks for your reply.

I'm referencing a ASHX file directly from a hyperlink, exactly as per the suggested method of integrating the component within a Web Forms project.

The file downloads, but with a .xls file extension and then Excel pops up a dialog with the following text:-

'The file you are trying to open 'MySpreadsheet.xls' 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 ?'

If I click 'Yes' then it opens fine.

Jul 30, 2012 at 6:49 PM

Hi guys,

As lowerbound mentioned, you need to use the DoddleReport.OpenXml.ExcelReportWriter to regenerate an xlsx file, which will not have the security prompt. This is in a separate assembly outside of the code DoddleReport.dll. You need DoddleReport.OpenXml.dll

Also, if you want to map the OpenXML ExcelReportWriter to the .xlsx extension see the following URL: http://doddlereport.codeplex.com/wikipage?title=Configuration

If you are creating the ReportWriter manually then make sure you are new'ing up the correct one.

-Matt

Jul 30, 2012 at 7:00 PM

Hi Mat,

Thanks for contributing this reply.

I will certainly give that a try.

Am I correct in saying that the ASHX method can only generate .xls files and not .xlsx files ?

Nick

Jul 30, 2012 at 7:09 PM

An ASHX endpoint can return anything, including xlsx.

If you inherit from the WebReport class and you web.config is setup to map the .xlsx extension with the OpenXl.ExcelReportWriter then it will take care of everything for you. If you want to do it manually you just have to new up the correct ExcelReportWriter and write to the output stream, and set the content-disposition header to give it a .xlsx extension.

WebReport is described here http://doddlereport.codeplex.com/wikipage?title=Web%20Reporting

Jul 30, 2012 at 7:10 PM

Hi Mat,

Thanks, that's absolutely brilliant.

Many thanks indeed for that and I hope this will help many others as well.

Thanks again.

Nick