将多个工作簿合并为一个工作簿
Contents
[
Hide
]
有时,您需要将包含各种内容(例如图像、图表和数据)的工作簿合并到一个工作簿中。 Aspose.Cells 支持此功能。本文介绍如何使用 Aspose.Cells 创建一个简单的应用程序以将工作簿与几行简单的代码结合起来。
合并工作簿
示例代码使用 Aspose.Cells for Java 将两个工作簿组合成一个工作簿。代码加载源工作簿,使用[工作簿.combine()](https://reference.aspose.com/cells/java/com.aspose.cells/workbook#combine(com.aspose.cells.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"); |
其他资源
你可能会发现将多个工作表合并为一个工作表文章对更多信息有用。