Programmatically finding an Excel file's Excel version

萝らか妹 提交于 2019-11-26 16:57:17

问题


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:


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);



回答2:


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.



来源:https://stackoverflow.com/questions/2070985/programmatically-finding-an-excel-files-excel-version

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!