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);
}