0

I am using ClosedXML to write my data into Excel. But here is the problem. When I write my data the old data gets removed and saves only data which I am calling. I know that is because of "new" and "Add" word I am using. Is there any other way I can specify to write files?

var workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add("Common");
worksheet.Cell(2, 1).Value = "Sent";
workbook.SaveAs(@"..\..\File.xlsx");

2 Answers2

0

You may be able to instantiate

var workbook = new XLWorkbook() 

in global scope and then append to it in whatever method you're using.

skypjack
  • 49,335
  • 19
  • 95
  • 187
0

Try this: This should work

string pathfile = @"..\..\File.xlsx";
XLWorkbook workbook = new XLWorkbook(pathfile);
IXLWorksheet worksheet = workbook.Worksheet("Common");
worksheet.Cell(2, 1).Value = "Sent";
workbook.Save();
user1413
  • 527
  • 4
  • 21