動作しているExcelCOMライブラリがあり、次の方法を使用して、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または間違ったバージョンのVisualStudioをターゲットにしています。
私のバージョン番号:
私が試した参考文献
これらの3つの参照はすべて、同じ例外を示しています。これをロードする方法はありますか?
問題は、異なるバージョンのOfficeからのtypelib登録にありました。インストールされなくなったOfficeのすべてのバージョンのレジストリエントリを削除することになりました。
これらのリンクは、それを機能させるために必要な情報を私に与えてくれました。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加