Read the complete article on how to insert and delete rows and columns in Excel sheets using Java: https://blog.aspose.com/cells/insert-delete-rows-columns-in-excel-java/
Insert and Delete Rows and Columns in Excel using Java
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
// Load Excel file | |
Workbook workbook = new Workbook("Book1.xls"); | |
// Access the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Delete a column from the worksheet at 2nd position | |
worksheet.getCells().deleteColumns(1, 1, true); | |
// Save the modified Excel file in default format | |
workbook.save("Delete Columns.xls"); |
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
// Load Excel file | |
Workbook workbook = new Workbook("Book1.xls"); | |
// Access the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Delete 10 rows from the worksheet starting from 3rd row | |
worksheet.getCells().deleteRows(2, 10, true); | |
// Save the modified Excel file in default format | |
workbook.save("Delete Rows.xls"); |
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
// Load Excel file | |
Workbook workbook = new Workbook("Book1.xls"); | |
// Access the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Insert a column into the worksheet at 2nd position | |
worksheet.getCells().insertColumns(1, 1); | |
// Save the modified Excel file in default format | |
workbook.save("Insert Column.xls"); |
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
// Load Excel file | |
Workbook workbook = new Workbook("Book1.xls"); | |
// Access the first worksheet in the Excel file | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Insert a row into the worksheet at 3rd position | |
worksheet.getCells().insertRows(2, 1); | |
// Save the modified Excel file in default format | |
workbook.save("Insert Rows.xls"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment