warning when opening generated xls file in excel 2007

Martin Huwa picture Martin Huwa · Sep 14, 2011 · Viewed 12.8k times · Source

I get the following warning when opening an XML file with the ending .xls but I want to use it as xls:

"The file you are trying to open, '[filename]', 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 | Help)

Quoted from the MSDN blog article 'Excel 2007 Extension Warning On Opening Excel Workbook from a Web Site' archive link original link (broken).

How to solve this?

I use .xls with this source code:

<?xml version="1.0" encoding="utf-8"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="Export">
<Table>

<Row> 
<Cell><Data ss:Type="Number">3</Data></Cell>

<Cell><Data ss:Type="Number">22123497</Data></Cell>

</Row>
</Table>
</Worksheet>
</Workbook>

Answer

Andreas J picture Andreas J · Nov 16, 2011

Well as the commenters already mentionend your example-document is definitly not an xls-file (as those are binary) and Excel rightly complains to that fact (because a document might trick you with the wrong extension).

What you should do is to save the document with file extension xml and add the processing-instruction for an office document (or in this case SpreadsheetML as oposed to the original binary/ propriatary excel-format)

<?xml version="1.0"?>
   <?mso-application progid="Excel.Sheet"?>
   <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
   ...

This used to work, but I just noticed that with Office 2007 the XML-processing component ("XML Editor") doesn't seem to be installed as default app for XML files. This did send XML-files to the correct application when they were opened (according to the processiong instuction). Maybe on your machine this works as it was intended to work (otherwise you might have to change this behaviour).

So this is basically the same the other commenters already said. Still I hope this helps.

Regards

Andreas