通过的Microsoft.Office.Interop.Excel确定Excel版本/文化 [英] Determine Excel Version/Culture via Microsoft.Office.Interop.Excel
本文介绍了通过的Microsoft.Office.Interop.Excel确定Excel版本/文化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能做到这一点的.NET / C#?
How can I achieve that in .NET/C#?
推荐答案
您可以使用此code段:(从我的一个项目中获得,所以不能保证工作的开箱即用)
You could use this code snippet: (taken from one of my projects, so not guaranteed to work out of the box)
Microsoft.Office.Interop.Excel.Application tExcel = new Application();
CultureInfo cSystemCulture = Thread.CurrentThread.CurrentCulture;
CultureInfo cExcelCulture = new CultureInfo(tExcel.LanguageSettings.get_LanguageID(
Microsoft.Office.Core.MsoAppLanguageID.msoLanguageIDUI));
try
{
Thread.CurrentThread.CurrentCulture = cExcelCulture;
double tVersion;
bool tParseSucceded = double.TryParse(tExcel.Version, out tVersion);
// 12 is the first version with .xlsx extension
if (tVersion > 11.5)
cDefaultExtension = ".xlsx";
else
cDefaultExtension = ".xls";
}
catch (Exception aException)
{
cLogger.Debug("error retrieving excel version.", aException);
cLogger.Error("error retrieving excel version.");
}
finally
{
Thread.CurrentThread.CurrentCulture = cSystemCulture;
}
这篇关于通过的Microsoft.Office.Interop.Excel确定Excel版本/文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文