Saving Excel Spreadsheet using Interop C#

Posted by Wesley on Stack Overflow See other posts from Stack Overflow or by Wesley
Published on 2010-04-22T17:37:33Z Indexed on 2010/04/22 20:43 UTC
Read the original article Hit count: 178

Filed under:
|
|
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?

© Stack Overflow or respective owner

Related posts about excel

Related posts about interop