After my program creates an Excel file, I let the user see that file.
Excel.Application xlApp = new Excel.Application();
xlApp.Visible = true;
Excel.Workbook excelWorkbook = xlApp.Workbooks.Open(xlsx.saveLocation + "\\" + xlsx.fileName,
0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);
Whenever I close the Excel window, the process (EXCEL.EXE) remains (I’m hitting the red X in the top right). Am I missing a setting or something? I want the Excel window to be independent of the C# program, so that if I end the latter the former will still be visible.
If you want true independence, then you should use
Process.Startto start Excel.The simplest version you’d need would be:
though I’d recommend using the proper
Pathmethods for combining the directory and filename into a complete path.Path.CombineSource
If your path or filename has spaces then you need to wrap the whole thing in quotes:
(Though a
StringBuildermay be overkill in this scenario)