Reputation: 141
I have a bash file that creates an xlsx file and a bunch of csv files. All the csv files are referenced inside the xlsx file, so xlsx file updates only when the xlsx file and all of the csv files are opened at the same time. Now, I have to create a C# application that calls the bash file, then opens all of the csv and xlsx files (in windows explorer), saves the newly updated xlsx file, then closes all of the files. I've managed to open the files by getting all the paths into a list, then launching processes for each path into a loop.
foreach(var path in paths)
{
Process.Start(path);
}
The problem is that I don't know how to save and close them after all of them are opened.
Upvotes: 1
Views: 1873
Reputation: 141
Apparently there is a better way to open xlsx and csv files than Process.Start. Using Microsoft.Office.Interlop.Excel, I can easily open the files, then save them and close them.
using Excel = Microsoft.Office.Interop.Excel;
var ExcelApp = new Excel.Application();
Excel.Workbook workbook = ExcelApp.Workbooks.Open(path);
ExcelApp.Visible = true;
workbook.Save();
workbook.Close();
ExcelApp.Quit();
Upvotes: 1