我有一个工作的 Excel COM 库,我正在尝试使用以下方法来确定 excel 是否处于编辑模式
public bool IsEditMode(Microsoft.Office.Interop.Excel.Application xlApp)
{
//https://stackoverflow.com/questions/464196/workaround-to-see-if-excel-is-in-cell-edit-mode-in-net
//xlApp = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application;
var bars = xlApp.Application.CommandBars;
var commandBar = bars["Worksheet Menu Bar"];
var menu = commandBar.FindControl(
1, //the type of item to look for
18, //the item to look for
Type.Missing, //the tag property (in this case missing)
Type.Missing, //the visible property (in this case missing)
true);
if (menu != null)
{
// Check if "New" menu item is enabled or not.
if (!menu.Enabled)
{
return true;
}
}
return false;
}
当我的代码点击 xlApp.Application.CommandBars;我得到以下异常。
System.Runtime.InteropServices.COMException: 'Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY))'
我相信问题是因为我引用了错误版本的 office.dll。它的目标是错误的 office 版本或错误的 Visual Studio 版本。
我的版本号:
我尝试过的引用文献
所有这三个引用文献都给了我同样的异常(exception)。任何想法如何加载这个?
最佳答案
问题在于来自不同版本 Office 的 typelib 注册。我最终删除了不再安装的所有 Office 版本的注册表项。
这些链接为我提供了使其正常工作所需的信息。
https://social.msdn.microsoft.com/Forums/vstudio/en-US/ac50fa41-8d47-4fa9-81a3-914f262676af/0x80029c4a-typeecantloadlibrary?forum=vsto
http://kb.palisade.com/index.php?pg=kb.page&id=528
关于c# - 加载 Office.dll 时出错 COMException : 'Errorloading type library/DLL' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53048360/