tags:

views:

256

answers:

2

Hi All,

I'm using an OleDbConnection to connect to a spreadsheet from a C# program. One of the parameters in the connection string is the Excel version.

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Book1.xls;Extended Properties="Excel 8.0;HDR=YES"

Given the path of an Excel file how can I find out which Excel format version it uses?

Thanks in advance,

T.

+1  A: 

Download OLE File Property Reader. Register dsofile.dll with regsvr32 and add it as a reference in your application. The following code will output the type of Excel file. It will not work on xlsx/docx since those are not OLE compunds object files, but should work on all older Office formats (2007/2003/XP).

var doc = new OleDocumentPropertiesClass();            
doc.Open(@"c:\spreadhseet.xls", false, dsoFileOpenOptions.dsoOptionDefault);
Console.WriteLine(doc.OleDocumentType);
Mikael Svenson
+2  A: 

I addition to what was said and apart from using Excel automation to open the file you can try reading file version from your code:

xls files: those are saved as structured storage. you can use the technique from the article here: How To Determine Which Version of Excel Wrote a Workbook

xlsx files: you can open them as zip files. Version is in app.xml file AppVersion field.

serge_gubenko