将多个工作簿合并为一个工作簿
Contents
[
Hide
]
有时,您需要将包含图像、图表和数据等各种内容的工作簿合并到一个工作簿中。 Aspose.Cells 支持此功能。本文介绍如何使用 Aspose.Cells 在 Visual Studio 中创建控制台应用程序并将工作簿与几行简单的代码结合起来。
将工作簿与图像和图表相结合
示例代码使用 Aspose.Cells 将两个工作簿组合成一个工作簿。代码加载源工作簿,使用工作簿.combine()组合它们并保存输出工作簿的方法。
源工作簿
输出工作簿
截图
以下是源工作簿和输出工作簿的屏幕截图。
您可以使用任何源工作簿。这些图像仅用于说明目的。
图表工作簿的第一个工作表 - 堆叠
图表工作簿的第二个工作表 - 线
图片工作簿的第一个工作表——图片
组合工作簿中的所有三个工作表 - 堆叠、线条、图片
This file contains hidden or 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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Define the first source | |
// Open the first excel file. | |
Workbook SourceBook1 = new Workbook(dataDir+ "SampleChart.xlsx"); | |
// Define the second source book. | |
// Open the second excel file. | |
Workbook SourceBook2 = new Workbook(dataDir+ "SampleImage.xlsx"); | |
// Combining the two workbooks | |
SourceBook1.Combine(SourceBook2); | |
dataDir = dataDir + "Combined.out.xlsx"; | |
// Save the target book file. | |
SourceBook1.Save(dataDir); |