Excelが32ビットで実行されているか64ビットで実行されているかをMicrosoft.Office.Interop.Excel.ApplicationClassから判断することはできますか?
編集
ソリューションは、Excel2010とExcel2007の両方で機能するはずです
3662 次
2 に答える
9
このコードは、Excel の「ビットネス」を提供するはずです。
Microsoft.Office.Interop.Excel.ApplicationClass app = new Microsoft.Office.Interop.Excel.ApplicationClass();
if (System.Runtime.InteropServices.Marshal.SizeOf(app.HinstancePtr) == 8)
{
// excel 64-bit
}
else
{
// excel 32-bit
}
編集: これは、以前のバージョンの Excel でも機能するはずの別のバージョンです。それに ApplicationClass 参照を渡すだけです。
public static ExcelVersion GetExcelVersion(object applicationClass)
{
if (applicationClass == null)
throw new ArgumentNullException("applicationClass");
PropertyInfo property = applicationClass.GetType().GetProperty("HinstancePtr", BindingFlags.Instance | BindingFlags.Public);
if (property == null)
return ExcelVersion.Excel;
return (System.Runtime.InteropServices.Marshal.SizeOf(property.GetValue(applicationClass, null)) == 8) ? ExcelVersion.Excel2010_64 : ExcelVersion.Excel2010_32;
}
public enum ExcelVersion
{
Excel, // before 2010, so 32 bits
Excel2010_32,
Excel2010_64
}
于 2011-05-31T13:11:41.940 に答える