使用 Office Web Components (OWC) 出現錯誤【類別未登錄 (發生例外狀況於 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))】

  • 10621
  • 0

使用 Office Web Components (OWC) 出現錯誤【類別未登錄 (發生例外狀況於 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))】

 

使用 Office Web Components (OWC) 出現錯誤【類別未登錄 (發生例外狀況於 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))】,如下圖所示:

image

 

環境說明:

1. Windows 7 專業版 32 位元

2. Visual Studio 2008 SP1

3. Office 2007 SP1

 

網路上大致上看到的解決方法:

1. 安裝 Office 2003 增益集:Office 網頁元件

2. 將專案【平台目標】設定為 x86

3. Office 2003 PIA,參考文章 在 .Net 中參考 OWC11 元件

 

不過這些網路上的解法,在我遇到的問題都無法解決,最後透過了微軟文章的方式解決

HOW TO: Handle Events for the Office 2003 Web Components in Visual Studio .NET

 

1. 先安裝 Office 2003 增益集:Office 網頁元件

2. 開啟【Visual Studio 命令提示字元】。

image

3. 輸入

md c:\owc11

cd c:\owc11

aximp "c:\program files\common files\microsoft shared\web components\11\owc11.dll" /source

del c:\owc11\axowc11.dll

image

 

4. 開啟檔案總管,切換至 C:\owc11 資料夾,編輯【AxOWC11.cs】。

image

 

5. 在以下 Class 加上 [System.ComponentModel.ToolboxItem(true)]

Chart Component

[System.ComponentModel.ToolboxItem(true)]
public class AxChartSpace : System.Windows.Forms.AxHost {

}

image

Spreadsheet Component

[System.ComponentModel.ToolboxItem(true)]

public class AxSpreadsheet : System.Windows.Forms.AxHost {

}

image

PivotTable Component

[System.ComponentModel.ToolboxItem(true)]

public class AxPivotTable : System.Windows.Forms.AxHost {

}

image

 

6. 在【Visual Studio 命令提示字元】輸入

set lib=c:\program files\microsoft.net\primary interop assemblies;%path%

copy %windir%\assembly\GAC\Microsoft.Office.Interop.Owc11\11.0.0.0__71e9bce111e9429c\Microsoft.Office.Interop.Owc11.dll

copy %windir%\assembly\GAC\mscomctl\10.0.4504.0__31bf3856ad364e35\mscomctl.dll

csc /t:library /r:microsoft.office.interop.owc11.dll /r:adodb.dll /r:msdatasrc.dll /r:mscomctl.dll axowc11.cs

image

 

7. 在 c:\owc11 資料夾中,將產生的 dll 參考重新加入專案中。

image

 

8. 加入後,可正常開啟使用 OWC 的專案。

image