Created
May 22, 2024 12:53
-
-
Save openize-cells-gists/d87fc6c0d11344b8a6d91ab40ebe48f2 to your computer and use it in GitHub Desktop.
Add Worksheet to a Workbook in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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