Click here to Skip to main content
15,892,737 members

Comments by Member 15777870 (Top 3 by date)

Member 15777870 20-Oct-22 10:20am View    
Just tried that...it's still closing my whole windows forms application when exiting out of my excel app in my panel.
Member 15777870 20-Oct-22 10:14am View    
Thanks, what is the proper way to do this in C#?
Member 15777870 20-Oct-22 9:28am View    
Here is how I'm using excel interop in C#

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
[DllImport("user32.dll")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

var projectspage = System.Windows.Forms.Application.OpenForms.OfType<projectspage>().FirstOrDefault();

excelApp.Workbooks.Open($@"C:\Users\daver\OneDrive\Documents\BMCalcs\{link}.xlsx");
excelApp.Visible = true;
excelApp.ScreenUpdating = true;
excelApp.EnableAutoComplete = false;
IntPtr excelHwnd = new IntPtr(excelApp.Application.Hwnd);
SetParent(excelHwnd, projectspage.pnl_ProjectDoc.Handle);
excelApp.WindowState = XlWindowState.xlMaximized;