I exporting some data to existing excel file. Problem is that, user can have this file opened.
For reading and writing to excel I use Microsoft.Office.Interop.Excel.
Is possible edit file with showing changes in Excel desktop app? Or is possible to check if file is opened in excel?
this is how I open that file:
xlApp = new Excel.Application();
xlApp.DisplayAlerts = false;
workbook = xlApp.Workbooks;
xlWorkBook = workbook.Open(filePath, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", true, false, 0, true, false, false);
var worksheets = xlWorkBook.Worksheets;
than I iterate over all sheets and fill data with writing values to Cells
Excel.Worksheet xlWorkSheet = worksheets.get_Item(sheetIndex);
Excel.Range range = GetRange(xlWorkSheet);
range.Cells[row,column] = value;
Then I save file:
xlWorkBook.Save();
Thank you Jakub