C++を使用してワークシート内の結合セルを検出
Contents
[
Hide
]
この記事では、ワークシート内の結合セル領域を取得する方法について説明しています。
Aspose.Cells を使用して、ワークシート内の結合セル領域を取得することができます。それらを分割することも可能です。この記事は、Aspose.Cells API を使用してタスクを実行するための最も簡単なコードを示しています。
このコンポーネントは、すべての結合セルを取得できる Cells::GetMergedAreas() メソッドを提供します。以下のコード例はワークシート内の結合セルを検出する方法を示しています。
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
Workbook workbook(srcDir + u"SampleInput.xlsx");
Worksheet wkSheet = workbook.GetWorksheets().Get(u"Sheet2");
wkSheet.GetCells().Clear();
Vector<CellArea> areas = wkSheet.GetCells().GetMergedAreas();
for (int i = 0; i < areas.GetLength(); ++i)
{
int frow = areas[i].StartRow;
int fcol = areas[i].StartColumn;
int erow = areas[i].EndRow;
int ecol = areas[i].EndColumn;
int trows = erow - frow + 1;
int tcols = ecol - fcol + 1;
wkSheet.GetCells().UnMerge(frow, fcol, trows, tcols);
}
U16String outputPath = outDir + u"MergeTrial.out.xlsx";
workbook.Save(outputPath);
std::cout << "Worksheet processing completed successfully." << std::endl;
Aspose::Cells::Cleanup();
}