Merging Two excel files as two sheets in one workbook in java

user3274923 picture user3274923 · Feb 5, 2014 · Viewed 24.9k times · Source

I have two xlsx files at folder C:\DemoFilesExcel\demo1.xlsx and C:\DemoFilesExcel\demo2.xlsx.

I want to create a new xlsx C:\DemoFilesExcel\merged.xlsx that will have these two files as two sheets in merged.xlsx workbook.

This is to be done using apache POI in java. Any idea how to do

Answer

Zi Kai picture Zi Kai · Mar 17, 2015
//Open the first excel file.
Workbook SourceBook1 = new Workbook("F:\\Downloads\\charts.xlsx");

//Define the second source book.
//Open the second excel file.
Workbook SourceBook2 = new Workbook("F:\\Downloads\\picture.xlsx");

//Combining the two workbooks
SourceBook1.combine(SourceBook2);

//Save the target book file.
SourceBook1.save("F:\\Downloads\\combined.xlsx");

http://www.aspose.com/docs/display/cellsjava/Combine+Multiple+Workbooks+into+a+Single+Workbook