Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created July 23, 2021 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/b6f33bfc3832977297cceccb0264743e to your computer and use it in GitHub Desktop.
Save aspose-com-gists/b6f33bfc3832977297cceccb0264743e to your computer and use it in GitHub Desktop.
Copy Rows and Columns in Excel using Java

Read the complete article on copying the rows and columns in Excel worksheets using Java:

// 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");
// 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