2012-08-10 54 views
1

我試圖創建一個新的Excel工作簿,但它不起作用。我使用Visual Studio 2012與.net Freamework 4.5和Microsoft Office 15使用Office 15和VS 2012創建Excel工作簿C#

我看着這些文章:

http://csharp.net-informations.com/excel/csharp-excel-tutorial.htm

http://www.codeproject.com/Articles/248531/Export-Excel-File-for-Csharp

如果我嘗試創建一個new ApplicationClass("ApplicationClass xlsApp = new ApplicationClass();"),我得到此錯誤:

"Microsoft.Office.Interop.Excel.ApplicationClass' cannot be embedded. Use the applicable interface instead."

我使用Microsoft.Office.Interop.Excel

你知道解決方案嗎?先謝謝你。

回答

2

正如錯誤中明確規定,

Use the applicable interface instead.

new Application()
即使Application是一個接口,編譯器會將其轉換爲適當的COM激活代碼。

錯誤是由嵌入式PIA引起的;禁用(在參考屬性中)也會修復它。

+0

謝謝,但我如何做到這一點?或者究竟在哪裏?謝謝你的回答。 – detrist 2012-08-10 21:02:31

+1

哦,我找到了。如果我單擊Microsoft.Office.Interop.Excel屬性並將「嵌入Interop類型」設置爲False,則可以使用。謝謝。 – detrist 2012-08-10 22:52:39

相關問題