I create an instance of Microsoft Excel in a .NET application (if that matters WPF), and I embed it inside:
var excelType = Type.GetTypeFromProgID("Excel.Application");
var excelObj = Activator.CreateInstance(excelType);
excelType.InvokeMember("Visible", BindingFlags.SetProperty, null, excelObj, new object[] { true }, ComCulture);
var excelHwnd = new IntPtr((int)excelType.InvokeMember("Hwnd", BindingFlags.GetProperty, null, excelObj, new object[0], ComCulture));
var managedWindowHwnd = new WindowInteropHelper(Application.Current.MainWindow).Handle;
SetParent(excelHwnd, managedWindowHwnd);
MoveWindow(excelHwnd, 0, 0, Convert.ToInt32(Width), Convert.ToInt32(Height), true);
All works except Excel do not load add-ons. If I start Excel through the Start menu, it loads the add-ons.
I think I need to specify some arguments in Excel to enable loading add-ons. But I have no idea what / how ...
source
share