Read the complete article on copying worksheets in Excel files using Java: https://blog.aspose.com/2021/07/08/copy-worksheets-in-excel-files-using-java/
Last active
July 9, 2021 04:49
-
-
Save aspose-com-gists/719efcb90f9408835ed72a0d8625d033 to your computer and use it in GitHub Desktop.
Copy or Move Worksheets in Excel Files 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 the Excel file using its path | |
Workbook wb = new Workbook("book1.xls"); | |
// Access the worksheets in the workbook | |
WorksheetCollection sheets = wb.getWorksheets(); | |
// Create a copy of the worksheet | |
sheets.addCopy("Sheet1"); | |
// Save the updated Excel file | |
wb.save("updated.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 the source Excel workbook | |
Workbook source = new Workbook("source.xls"); | |
// Load the destination Excel workbook | |
Workbook destination = new Workbook("destination.xls"); | |
// Copy the first sheet of the source workbook into second workbook | |
destination.getWorksheets().get(0).copy(source.getWorksheets().get(0)); | |
// Save the file. | |
destination.save("updated.xls", FileFormatType.EXCEL_97_TO_2003); |
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 the Excel file | |
Workbook wb = new Workbook("workbook.xls"); | |
// Get the first worksheet in the workbook | |
Worksheet sheet = wb.getWorksheets().get(0); | |
// Move the first sheet to the third position in the workbook | |
sheet.moveTo(2); | |
// Save the updated Excel file | |
wb.save("updated.xls"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment