Reading xls binary signature

Does anyone know if there's a reliable way to read the binary signature of a .xls file from within a C++ application?

I need to programmatically determine whether a file is an actual Excel file without relying on the extension. The best way I can think of to do this is to examine the header signature.

Of course, if anyone has a better way, I'm open to suggestions...
Take a look at ExcelFormat:

http://www.codeproject.com/Articles/42504/ExcelFormat-Library

xls is a compressed format. You can open it with 7zip which leads to an xml format.
My problem is that I'm not trying to create or open an Excel file. What I need to do is add code to an application that can look at a file whose extension is .xls and determine whether or not it's actually an .xls file as opposed to a file where someone has changed the extension.

Customers changing the extension has been an issue so I need a way to authenticate the file on the fly.
Last edited on
My problem is that I'm not trying to ... open an Excel file.

If you want to look at a "signature" in the file to verify it's an Excel file, you're going to have to open it.

The following document gives a description of the various Excel file formats.
http://www.openoffice.org/sc/excelfileformat.pdf

You should be able to look at the BOF record (record id = 0x0809).
For a BIFF8 (Excel 8-11) format file, the BIFF version should be 0x0600.


Topic archived. No new replies allowed.