How to Copy Excel Sheet to Another Workbook in Java

This concise tutorial provides details about how to copy Excel sheet to another workbook in Java. You can load the input Excel file with XLSX or XLS file extension and then using Java copy excel worksheet function can be performed. You can copy any sheet using its index number or the sheet name as per your requirements.

Steps to Copy Excel Sheet to Another Workbook in Java

  1. Add a reference to Aspose.Cells from the Maven repository to copy an Excel sheet
  2. Load the source Excel file into the Workbook class object for copying input data
  3. Access the sheets of the output Excel file
  4. Copy the Excel sheet to another workbook using the index number of sheets
  5. Save output Excel workbook with the copied worksheet in it

We only need to make a few API calls to work with the Java Excel sheet copy feature. We can customize the copying worksheets process by changing the indexes of worksheets. For example, you can copy any worksheet from the source worksheet and paste it at any index in the output Excel workbook, only by changing the index numbers.

Code to Copy Excel Sheet to Another Workbook in Java

In this tutorial, we have explored how using Java copy Excel sheet to another workbook feature can be incorporated. You can control the copying operation by using the CopyOptions class object in copy() function that supports copying values only if the formula is not valid for the destination sheet, the option to copy names, the option to keep macros, and many other features as well.

This article has explained how to copy-paste data among Excel worksheets. However, if you want to learn the merging of cells, refer to the article on how to Merge Cells in Excel using Java.

 English