简体   繁体   中英

How to open an excel file from VSTO plugin and get VSTO workbook?

I already know how to open file and get Workbook from Microsoft.Office.Interop.Excel namespace. But is there a way to get Workbook from Microsoft.Office.Tools.Excel namespace? Casting between the two does not work. I know this sound simple, but I'm stuck - all answers on SO point to Interop solutions.

According to the documentation on MSDN, the Workbook interface in the Microsoft.Office.Tools.Excel namespace is an "extended object" which "add[s] functionality to objects that exist natively in the Word or Excel object models (called native Office objects)".

The relevant code from that page on how you can create such an extended object is:

Microsoft.Office.Interop.Excel.Workbook nativeWorkbook = 
    Globals.ThisAddIn.Application.ActiveWorkbook;
if (nativeWorkbook != null)
{
    Microsoft.Office.Tools.Excel.Workbook vstoWorkbook = 
        Globals.Factory.GetVstoObject(nativeWorkbook);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM