don't call:
var excelApp = new Excel.Application();
until you need it.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a winforms program. In certain parts of the program there is the ability to export data to Excel. To do this I have added a reference to Microsoft.Office.Interop.Excel. This seems to create an instance of excel that runs in the background (even before I use any of the Excel related programs within the app).
I have noticed that on PCs where MS Office is not installed, having this background instance of Excel running really slows down the performance of the program. It can take up to a minute just to load all the buttons, labels etc on a form. (It takes less than a second normally). As soon as I End the Excel Process in the Task Manager, the program loads up instantly.
Is there anyway I can have a reference to the Microsoft.Office.Interop.Excel without it starting an actual Instance of Excel in the background ?
Regards,
John
don't call:
var excelApp = new Excel.Application();
until you need it.
Hi folks,
I think I have tracked down the source of the problem....
try
{
Type officeType = Type.GetTypeFromProgID("Excel.Application");
dynamic xlApp = Activator.CreateInstance(officeType);
xlApp.Visible = false;
pathToExcel = xlApp.Path + @"\Excel.exe";
xlApp.Quit();
xlApp.Dispose();
}
In my code, I try and get the path to the Excel exe (as some PCs may have had 32 / 64 bit versions). Once I had the path, I could then just call Start.Process(pathtoExcel). It would seem even calling xlApp.Quit() and xlApp.Dispose() does not kill the process.
But now, I have reconfigured my code so that I dont need to know the path anymore.
Thanks again,
John