Looking for some help here. I have a situation I am getting data in a byte array tab by tab.
Hi,
Please see how to copy all the worksheets inside a source workbook into a new workbook. Please see the source workbook and the output workbook generated by the following code. I have attached them.
Java
String dirPath=“f:\downloads\”;
//Open the source workbook
Workbook sourceWorkbook=new Workbook();
sourceWorkbook.open(dirPath + “source.xlsx”);
//Create a new destination workbook and remove its
//only sheet
Workbook destWorkbook=new Workbook();
destWorkbook.getWorksheets().removeSheet(0);
//Get the source sheets
Worksheets wsheets = sourceWorkbook.getWorksheets();
//Copy all source sheets into destination workbook
for(int i=0; i<wsheets.size(); i++)
{
Worksheet sourceSheet= sourceWorkbook.getWorksheets().getSheet(i);
destWorkbook.getWorksheets().addSheet();
int destSheetIdx=destWorkbook.getWorksheets().size() - 1;
Worksheet destSheet = destWorkbook.getWorksheets().getSheet(destSheetIdx);
destSheet.copy(sourceSheet);
}
//Write the destination workbook on disk
destWorkbook.save(dirPath + “destOutput.xlsx”, FileFormatType.XLSX);