在Windows上查找OleDb驱动程序

时间:2017-07-06 12:57:56

标签: .net excel windows oledb

我有一个使用OleDB连接打开Excel工作簿的项目。不同的人安装了不同版本的Office。

如果连接字符串是这样创建的:

var connectionString = $"Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0 XML;Data Source={workBookFilePath}";

有些用户会遇到异常:

System.InvalidOperationException : 
    The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

如何智能地获取计算机上可用的提供程序,并且只有在没有任何提示的情况下才会抛出异常?

0 个答案:

没有答案