Saving Excel Spreadsheet using Interop C#
- by Wesley
static void Main()
{
Application excelapp = new Application();
Workbook book = excelapp.Workbooks.Open(@"C:\HWYFAB.xlsx",
0, false, 5, "", "", false, XlPlatform.xlWindows , "",
true, false, 0, true, false, false);
Worksheet sheet = (Worksheet)book.Sheets[1];
Range cell = (Range)sheet.Cells[3, 2];
Console.WriteLine(cell.Text);
cell.ClearContents();
book.Close(true, "HWYFAB.xlsx", false);
excelapp.Quit();
}
This program runs and exits as expected. It does print the correct value that's in cell B3 to the console. When closing it asks if I want to replace the existing file. I click yes. When I open the spreadsheet in Excel, the value is still in cell B3 despite the cell.ClearContents().
Any thoughts?