如何检查在C#中的Excel文件的版本? [英] How can I check the version of Excel files in C#?

查看:819
本文介绍了如何检查在C#中的Excel文件的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要区分选定的文件与Excel 2010或Excel 2013的版本,服务器选择的Excel文件和Excel应用程序的创建必须以继续匹配。

I need to differentiate that a selected file is created with Excel 2010 or Excel 2013 version of a selected Excel file and Excel application on server must match in order to continue.

我可以得到服务器的Excel应用程序版本:

I can get the server's Excel application version:

 xApp = new Microsoft.Office.Interop.Excel.Application();
// getting version of Server's Excel Application
string versionName = xApp.Version;
int length = versionName.IndexOf('.');
versionName = versionName.Substring(0, length);
object missing = Type.Missing;
object trueObject = true;
xApp.Visible = false;
xApp.DisplayAlerts = false;
xWorkBook = 
xApp.Workbooks.Open(ExcelFilePath, missing, trueObject, 
                    missing, missing, missing,
                    missing, missing, missing,
                    missing, missing, missing, missing, missing, missing);



但我怎样才能得到打开Excel文件的Excel版本?
在目前的情况下,的versionName 收益 14.0 ,这是Office 2010。

But how can I get the Excel version of opened Excel files? In the current case, versionName returns 14.0, which is for Office 2010.

推荐答案

发现的 OLE文件属性阅读

var doc = new OleDocumentPropertiesClass();
doc.Open(ExcelFilePath, false, dsoFileOpenOptions.dsoOptionDefault);
string DocFileVersion = doc.SummaryProperties.Version.ToString();

这将返回Excel文件的应用程序版本的版本...

this will return version of Application Version of excel file...

这篇关于如何检查在C#中的Excel文件的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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