5

I generate an excel file using XML format outlined on stackoverflow in the following post: Generate excel file in .net

However, when I open it up in excel 07, I get the following message:

The file you are trying to open, "blah.xls", is in a different format than spefied by the file extension. Verify that the file i snot corrupted and is from a trusted source before opening the file. Do you want to open the file now?

What is causing the error message and how can I get rid of it? Thanks!

Community
  • 1
  • 1
laconicdev
  • 6,360
  • 11
  • 63
  • 89

2 Answers2

5

Try calling the file blah.xlsx instead of blah.xls. Excel apparently wants XML files to have an "xlsx" extension. The "xls" extension is for the binary format files.

Edit in response to your comment:
I was wrong: xlsx files aren't just the XML files, they're zip archives containing the XML format plus other metadata. All in all, it's a little complex to set up. I'd try renaming the file to blah.xml, and see if that works. Otherwise I'm afraid you might have to look at how to make these zip files. There are two options:

  • Use Microsoft's OOXML SDK: see http://msdn.microsoft.com/en-us/library/bb448854.aspx.
  • Do it yourself (much harder). You'll have to look at the OOXML standard. Part 1 contains an overview, and a description of each XML file. Part 2 describes the package format (i.e. the zip archive format). There are additional requirements on xlsx files above what part 2 says you need, so read part 2 first, then part 1.
Doug
  • 8,780
  • 2
  • 27
  • 37
  • 3
    When I use .xlsx extension, I get a different error message: Excel cannot open the file blah.xlsx because the file or format or file extension is not valid... without any options to open the file at all – laconicdev Apr 14 '09 at 12:29
  • The workbook in this comment: http://stackoverflow.com/questions/150339/generating-an-excel-file-in-asp-net/150368#150368 works correctly for me with an xlsx extension. Is it possible that the file you're trying to open has a mismatched tag or other syntax error? – Doug Apr 15 '09 at 12:55
  • We could also use the "xml" extension and add an extra tag to make sure Excel opens the file. http://stackoverflow.com/a/1159717/880772 – approxiblue Feb 08 '13 at 21:07
0

Microsoft office 2007 on wards, the office files are stored in xml format (office open xml package). Earlier versions (2003 and below) are not stored as xml files. So you cannot see markup of xls files. Off course you can see markup of xlsx file. You do not require any editors. If you have WinRar installed in your system, that is sufficient to open any MS-Office file.
If you are trying to open it programmatically, then you will get DocumentFormat.xml.dll library (its free) (for .net) and OpenXml4J (for java).

Pramod
  • 72
  • 3