以编程方式查找Excel文件的Excel版本 [英] Programmatically finding an Excel file's Excel version

查看:254
本文介绍了以编程方式查找Excel文件的Excel版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OleDbConnection从C#程序连接到电子表格。连接字符串中的一个参数是Excel版本。

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;数据源= C:\Book1 .xls;扩展属性= Excel 8.0 ; HDR = YES

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

给定Excel文件的路径如何找出使用哪种Excel格式版本?

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

提前感谢

T。

推荐答案

下载 OLE文件属性读取器。使用regsvr32注册dsofile.dll并将其添加为应用程序中的参考,以下代码将输出Excel文件的类型它不会在xlsx / docx上工作,因为它们不是OLE compunds对象文件,而应该适用于所有较旧的Office格式(2007/2003 / XP)。

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

这篇关于以编程方式查找Excel文件的Excel版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆