Copy Worksheets from one Workbook to another in Java

Monday, 12 July 2021 03:23 Written by  support iceblue
Rate this item
(0 votes)

This article shows how to copy a worksheet from an Excel document to anther by using Spire.XLS for Java.

import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;

public class CopySheetBetweenWorkbooks {
    public static void main(String[] args) {

        //Create a Workbook object to load the source document
        Workbook srcWorkbook = new Workbook();

        //Get the specific worksheet to copy
        Worksheet originalSheet = srcWorkbook.getWorksheets().get(0);

        //Create another Workbook object to load the destination document
        Workbook destWorkbook = new Workbook();

        //Add the copy of selected sheet to destination document
        Worksheet newSheet = destWorkbook.getWorksheets().addCopy(originalSheet);

        //Copy the theme of source document to destination document

        //Save to another file

Copy Worksheets from one Workbook to another in Java

Additional Info

  • tutorial_title:
Last modified on Wednesday, 01 September 2021 02:29