Posted on: 12/19/2014 9:37:44 PM | Views : 488

I have a windows form. I am trying to write to an excel sheet when I hit submit. Right now, each time I hit submit the excel file is being deleted and recreated. I have been unable to figure out how to just append/update  to the same excel file. Any ideas please? Below is my code:
private void btnSubmit_Click(object sender, EventArgs e) { string fileTest = "C:\\Temp\\test.xlsx"; Excel.Application oApp; Excel.Worksheet oSheet; Excel.Workbook oBook; if (File.Exists(fileTest)) { File.Delete(fileTest); } oApp = new Excel.Application(); oBook = oApp.Workbooks.Add(); oSheet = (Excel.Worksheet)oBook.Worksheets.get_Item(1); oSheet.Cells[1, 1] = "some value"; oBook.SaveAs(fileTest); oBook.Close(); ...

Go to the complete details ...