Created
February 14, 2024 11:43
-
-
Save fileformat-cells-gists/b6a5f92bbea8c15fa60d83b0196f8d5f to your computer and use it in GitHub Desktop.
This C# example showcases how to programmatically insert rows into an Excel worksheet at a specified row index using the FileFormat.Cells library.
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
using FileFormat.Cells; | |
// Load the workbook from the specified file path | |
using (Workbook wb = new Workbook(filePath)) | |
{ | |
// Access the first worksheet in the workbook | |
Worksheet firstSheet = wb.Worksheets[0]; | |
// Define the starting row index and the number of rows to insert | |
uint startRowIndex = 5; | |
uint numberOfRows = 3; | |
// Insert the rows into the worksheet | |
firstSheet.InsertRows(startRowIndex, numberOfRows); | |
// Get the total row count after insertion | |
int rowsCount = firstSheet.GetRowCount(); | |
// Output the updated row count to the console | |
Console.WriteLine("Rows Count=" + rowsCount); | |
// Save the workbook to reflect the changes made | |
wb.Save(filePath); | |
Console.WriteLine("Rows inserted and workbook saved successfully."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment