複数のワークブックを1つに結合する(C++)
Contents
[
Hide
]
時には、画像やチャート、データなど様々な内容を持つワークブックを1つに結合する必要があります。Aspose.Cellsはこの機能をサポートしています。この記事では、Visual Studioでコンソールアプリケーションを作成し、数行のコードでワークブックを結合する方法を示します。
画像とグラフを使用したワークブックの結合
例のコードは、Aspose.Cellsを使用して2つのワークブックを1つのワークブックに結合します。コードはソースワークブックを読み込み、Workbook::Combine()メソッドを使用してそれらを結合し、出力ワークブックを保存します。
ソースワークブック
出力ワークブック
スクリーンショット
以下は、ソースおよび出力ワークブックのスクリーンショットです。
ソースワークブックを好きなものを使用できます。これらの画像は、イメージ説明のためのものです。
チャートワークブックの最初のワークシート - 積み重ね
チャートワークブックの2番目のワークシート - 折れ線
画像ワークブックの最初のワークシート - 画像
結合されたワークブックの3つのワークシート - 積み重ね、折れ線、画像
#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();
}