Combine Multiple Workbooks into a Single Workbook
Contents
[
Hide
]
Sometimes, you need to combine workbooks with various content like images, charts, and data into a single workbook. Aspose.Cells supports this feature. This article shows how to create a simple application to combine workbooks with a few, simple lines of code using Aspose.Cells.
Combining Workbooks
The example code combines two workbooks into a single workbook using Aspose.Cells for Java. The code loads the source workbooks, uses the Workbook.combine() method to combine them and saves the output workbook.
Source Workbooks
Output Workbooks
Screenshots
Below are screenshots of the source and output workbooks.
You can use any source workbooks. These images are just for illustration purposes.
The first worksheet of the charts workbook - stacked
Second worksheet of charts workbook - line
First worksheet of the picture workbook - picture
All three worksheets in the combined workbook - stacked, line, picture
The following code snippet shows how to combine multiple workbooks into a single workbook.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(CombineMultipleWorkbooks.class); | |
// Open the first excel file. | |
Workbook SourceBook1 = new Workbook(dataDir + "charts.xlsx"); | |
// Define the second source book. | |
// Open the second excel file. | |
Workbook SourceBook2 = new Workbook(dataDir + "picture.xlsx"); | |
// Combining the two workbooks | |
SourceBook1.combine(SourceBook2); | |
// Save the target book file. | |
SourceBook1.save(dataDir + "combined.xlsx"); |
Additional Resources
You may find the Combine Multiple Worksheets into a Single Worksheet article useful for more information.