将多个工作簿合并成一个单一工作簿,使用C++实现
Contents
[
Hide
]
有时,您需要将包含图像、图表和数据的多个工作簿合并到一个工作簿中。Aspose.Cells支持此功能。本文演示如何在Visual Studio中创建控制台应用程序,并使用几行简单的代码合并工作簿。
将具有图像和图表的工作簿合并
示例代码使用Aspose.Cells将两个工作簿合并为单个工作簿。该代码加载源工作簿,使用Workbook::Combine()方法将它们合并,并保存输出工作簿。
源工作簿
输出工作簿
屏幕截图
以下是源和输出工作簿的屏幕截图。
您可以使用任何源工作簿。这些图像仅用于说明目的。
图表工作簿的第一个工作表 - 堆叠
图表工作簿的第二个工作表 - 折线
图片工作簿的第一个工作表 - 图片
组合工作簿中的三个工作表 - 堆叠、线条、图片
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Path of the first source excel file
U16String sourceFile1 = srcDir + u"SampleChart.xlsx";
// Path of the second source excel file
U16String sourceFile2 = srcDir + u"SampleImage.xlsx";
// Open the first excel file.
Workbook sourceBook1(sourceFile1);
// Open the second excel file.
Workbook sourceBook2(sourceFile2);
// Combining the two workbooks
sourceBook1.Combine(sourceBook2);
// Define the output file path
U16String outputFilePath = srcDir + u"Combined.out.xlsx";
// Save the target book file.
sourceBook1.Save(outputFilePath);
std::cout << "Workbooks combined and saved successfully!" << std::endl;
Aspose::Cells::Cleanup();
}