views:

20

answers:

1

I currently have a method that receives a byte array of an excel file. It worked great, and I had it differentiating the file types (.xls, and .xlsx) based on the first two bytes in the file. If it's an .xlsx it started with a PK. Unfortunately, now I am getting .xlsm files sent, and I don't know what byte differs to tell them apart. I don't have the filename at this point to get the extension.

+1  A: 

The only difference between .xlsx and .xlsm is that the latter may include Macros. I'm quite sure you need further parsing of the file to find that out.

Note that the magic number "PK" (actually it is PK\x03\x04) in the beginning of the .xlsx refers to ZIP compressed data. To further parse the file, you first have to decode (uncompress) it according to ZIP file format.

ypnos
Thanks, I'll just add a method that also takes the file extension as a parameter. Save me the headache of trying to figure it out. Sucks that excel relies on that extension being correct all the time
Chad
'sucks' and 'excel' in one sentence.. looks familiar to me :D
ypnos