将多个工作簿合并为单个工作簿
Contents
[
Hide
]
有时,您需要将带有不同内容(如图像、图表和数据)的工作簿合并到单个工作簿中。Aspose.Cells支持此功能。本文演示了如何使用Aspose.Cells创建一个简单的应用程序,使用几行简单的代码将工作簿合并成一个。
合并工作簿
示例代码使用Aspose.Cells for Java将两个工作簿合并为一个工作簿。该代码加载源工作簿,使用Workbook.combine()方法将它们合并,并保存输出工作簿。
源工作簿
输出工作簿
屏幕截图
以下是源和输出工作簿的屏幕截图。
您可以使用任何源工作簿。这些图像仅用于说明目的。
图表工作簿的第一个工作表 - 堆叠
图表工作簿的第二个工作表 - 折线
图片工作簿的第一个工作表 - 图片
组合工作簿中的三个工作表 - 堆叠、线条、图片
以下代码片段显示了如何将多个工作簿合并成一个单一工作簿。
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"); |
其他资源
您可能会发现将多个工作表合并到单个工作表一文对您有所帮助。