Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save openize-cells-gists/d87fc6c0d11344b8a6d91ab40ebe48f2 to your computer and use it in GitHub Desktop.
Save openize-cells-gists/d87fc6c0d11344b8a6d91ab40ebe48f2 to your computer and use it in GitHub Desktop.
Add Worksheet to a Workbook in C#
string filePath = "/path/to/existing/spreadsheet.xlsx"; // Replace with the path to your file
// Open the existing workbook.
using (var workbook = new Workbook(filePath))
{
// Add a new worksheet to the workbook.
Worksheet newSheet = workbook.AddSheet("NewWorksheetName"); // Replace 'NewWorksheetName' with the desired name
// You can also add some content to the new worksheet if needed.
Cell cellA1 = newSheet.Cells["A1"];
cellA1.PutValue("Hello from the new sheet!");
// Save the workbook with the added worksheet.
workbook.Save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment