#region 判断系统是否装excel
/**//// <summary>
/// 判断系统是否装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>
/// 判断系统是否装某版本的excel
/// </summary>
/// <param name="strVersion">版本号</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 判断系统是否装word
/**//// <summary>
/// 判断系统是否装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>
/// 判断系统是否装某版本的word
/// </summary>
/// <param name="strVersion">版本号</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