#region 判斷系統(tǒng)是否裝excel
/**//// <summary>
/// 判斷系統(tǒng)是否裝excel
/// </summary>
/// <returns></returns>
public static bool IsInstallExcel()
{
RegistryKey machineKey = Registry.LocalMachine;
if( IsInstallExcelByVersion( "12.0", machineKey ) )
{
return true;
}
if( IsInstallExcelByVersion( "11.0", machineKey ) )
{
return true;
}
return false;
}
/**//// <summary>
/// 判斷系統(tǒng)是否裝某版本的excel
/// </summary>
/// <param name="strVersion">版本號(hào)</param>
/// <param name="machineKey"></param>
/// <returns></returns>
private static bool IsInstallExcelByVersion( string strVersion, RegistryKey machineKey )
{
try
{
RegistryKey installKey = machineKey.OpenSubKey( "Software" ).OpenSubKey( "Microsoft" ).OpenSubKey( "Office" ).OpenSubKey( strVersion ).OpenSubKey( "Excel" ).OpenSubKey( "InstallRoot" );
if( installKey == null )
{
return false;
}
return true;
}
catch
{
return false;
}
}
#endregion
#region 判斷系統(tǒng)是否裝word
/**//// <summary>
/// 判斷系統(tǒng)是否裝word
/// </summary>
/// <returns></returns>
public static bool IsInstallWord()
{
RegistryKey machineKey = Registry.LocalMachine;
if( IsInstallExcelByVersion( "12.0", machineKey ) )
{
return true;
}
if( IsInstallExcelByVersion( "11.0", machineKey ) )
{
return true;
}
return false;
}
/**//// <summary>
/// 判斷系統(tǒng)是否裝某版本的word
/// </summary>
/// <param name="strVersion">版本號(hào)</param>
/// <param name="machineKey"></param>
/// <returns></returns>
private static bool IsInstallWordByVersion( string strVersion, RegistryKey machineKey )
{
try
{
RegistryKey installKey = machineKey.OpenSubKey( "Software" ).OpenSubKey( "Microsoft" ).OpenSubKey( "Office" ).OpenSubKey( strVersion ).OpenSubKey( "Word" ).OpenSubKey( "InstallRoot" );
if( installKey == null )
{
return false;
}
return true;
}
catch
{
return false;
}
}
#endregion