2011-11-16 84 views
1

我使用comObject可以轉換爲Excel.ApplicationClass嗎?

(Excel.Application)Marshal.GetActiveObject("Excel.Application") 

它返回我_ComObject類型,但我不知道我怎麼會是能夠施展,爲Excel.ApplicationClass,我將如何去這樣做?

+0

是以下任何用途:http://stackoverflow.com/questions/7757255/com-returns-type-that-does-not-implement-any-interface –

回答

4

知識庫文章here定義以下內容將起作用。

//Excel Application Object 
Excel.Application oExcelApp; 

this.Activate(); 

//Get reference to Excel.Application from the ROT. 
oExcelApp = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application"); 

//Display the name of the object. 
MessageBox.Show(oExcelApp.ActiveWorkbook.Name); 

//Release the reference. 
oExcelApp = null; 
相關問題