C#判断电脑是否安装了EXCEL
时间: 2023-07-12 12:03:56 浏览: 89
可以使用 Microsoft.Office.Interop.Excel 库来判断计算机是否安装了 Excel。代码如下:
```csharp
using System;
using System.Reflection;
namespace ExcelAvailabilityCheck
{
class Program
{
static void Main(string[] args)
{
Type excelType = Type.GetTypeFromProgID("Excel.Application");
if (excelType == null)
{
Console.WriteLine("Excel is not installed on this machine.");
}
else
{
Console.WriteLine("Excel is installed on this machine.");
}
Console.ReadLine();
}
}
}
```
此代码尝试获取 Excel 应用程序的类型。如果 Excel 已安装,则返回 Excel 应用程序的类型;否则,返回 null。因此,我们可以检查 excelType 是否为 null 来判断计算机是否安装了 Excel。