我正在使用
(Excel.Application)Marshal.GetActiveObject("Excel.Application")
它返回_ComObject
类型,但我想知道如何将其转换为Excel.ApplicationClass
,我将如何进行此操作?
答案 0 :(得分: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;