This guide page provides users with detailed explanations for adding and changing XLSX and XLS cell value in C# code.

// Load excel workbook from local file
Workbook workBook = new Workbook("sample.xlsx");
// Get worksheet by name
Sheet sheet = workBook.GetSheet("Sheet1");
// Get row by row index
Row row = sheet.GetRow(0);
if (row != null)
{
// If the cell is the same as the original cell type,// you can update the cell value directly.// For example, the original cell value is Int value "123", // now you want to change the cell value to Int "456"
Cell cellUpdate = row.GetCell(0);
if (cellUpdate != null)
{
cellUpdate.SetValue(456);
}
// If the cell is different from the original cell type,// you need to create a new cell to replace the original one.// For example, the original cell value is Int value "123", // now you wan to change the cell value to String "XsExcel"
Cell cellNew = row.CreateCell(1);
cellNew.SetValue("XsExcel");
}
// Save and show the spreedsheetif (File.Exists("sample.xlsx")) File.Delete("sample.xlsx");
workBook.Save("sample.xlsx");
Process.Start("sample.xlsx");

Notice - If you used the trial version of XsExcel SDK, can only edit, insert or get the first 300 row data!