Read the complete article on copying the rows and columns in Excel worksheets using Java:
Created
July 23, 2021 16:35
-
-
Save aspose-com-gists/b6f33bfc3832977297cceccb0264743e to your computer and use it in GitHub Desktop.
Copy 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
// Instantiating a Workbook object | |
Workbook workbook = new Workbook("workbook.xlsx"); | |
// Obtaining the reference of the first worksheet by passing its sheet index | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Copy the first column from the first worksheet of the workbook | |
worksheet.getCells().copyColumn(worksheet.getCells(), worksheet.getCells().getColumns().get(0).getIndex(), worksheet.getCells().getColumns().get(2).getIndex()); | |
// Saving the Excel file | |
workbook.save("output.xlsx"); |
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
// Instantiating a Workbook object | |
Workbook workbook = new Workbook("workbook.xlsx"); | |
// Obtaining the reference of the first worksheet by passing its sheet index | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Copy the second row with data, formating, images and drawing objects to the 16th row in the worksheet | |
worksheet.getCells().copyRow(worksheet.getCells(), 1, 15); | |
// Saving the Excel file | |
workbook.save("output.xlsx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment