行と列のグルーピングおよびグループ解除

紹介

Microsoft Excelファイルでは、データの概要を作成して、1回のマウスクリックで詳細のレベルを表示したり非表示にしたりできます。

「アウトライン記号」の**1、2、3、+、-**をクリックして、ワークシート内のセクションの要約または見出しを提供する行または列のみをすばやく表示するか、個々の要約または見出しの下に詳細を表示するためにこの記号を使用できます。

行と列のグループ管理

Aspose.Cellsは、Microsoft Excelファイルを表すWorkbookクラスを提供しています。Workbookクラスには、Excelファイル内の各ワークシートにアクセスを許可するWorksheetsコレクションが含まれています。ワークシートはWorksheetクラスによって表されます。Worksheetクラスは、ワークシート内のすべてのセルを表すCellsコレクションを提供します。

Cellsコレクションには、ワークシート内の行や列を管理するためのいくつかのメソッドが提供されており、そのうちのいくつかについて詳しく説明します。

行と列のグループ化

CellsコレクションのGroupRowsおよびGroupColumnsメソッドを呼び出すことで、行または列をグループ化することができます。両方のメソッドは、以下のパラメータを取ります:

  • 最初の行/列インデックス、グループ内の最初の行または列。
  • 最後の行/列インデックス、グループ内の最後の行または列。
  • 非表示かどうか、グループ化後に行または列を非表示にするかどうかを指定するブールパラメータ。
Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input
U16String dirPath(u"");
//Path of output
U16String outPath(u"");
//Path of input excel file
U16String sampleGroupingUngroupingRowsAndColumns = dirPath + u"sampleGroupingUngroupingRowsAndColumns.xlsx";
//Path of output excel file
U16String outputGroupingUngroupingRowsAndColumns = outPath + u"outputGroupingUngroupingRowsAndColumns.xlsx";
//Read input excel file
Workbook workbook(sampleGroupingUngroupingRowsAndColumns);
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.GetWorksheets().Get(0);
//Grouping first seven rows and first four columns
worksheet.GetCells().GroupRows(0, 6, true);
worksheet.GetCells().GroupColumns(0, 3, true);
//Save the Excel file.
workbook.Save(outputGroupingUngroupingRowsAndColumns);
Aspose::Cells::Cleanup();

グループ設定

Microsoft Excelでは、以下を表示するためのグループ設定を構成できます:

  • 詳細の下の要約行。
  • 詳細の右側の要約列。

行と列のグループ解除

グループ化された行や列を解除するには、CellsコレクションのUngroupRowsおよびUngroupColumnsメソッドを呼び出します。両方のメソッドは2つのパラメータを取ります:

  • 最初の行または列インデックス、解除される最初の行または列。
  • 最後の行または列インデックス、解除される最後の行または列。
Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Path of input
U16String dirPath(u"");
//Path of output
U16String outPath(u"");
//Path of input excel file
U16String sampleGroupingUngroupingRowsAndColumns = dirPath + u"sampleGroupingUngroupingRowsAndColumns.xlsx";
//Path of output excel file
U16String outputGroupingUngroupingRowsAndColumns = outPath + u"outputGroupingUngroupingRowsAndColumns.xlsx";
//Read input excel file
Workbook workbook(sampleGroupingUngroupingRowsAndColumns);
//Accessing the second worksheet in the Excel file
Worksheet worksheet = workbook.GetWorksheets().Get(1);
//UnGroup first seven rows and first four columns
worksheet.GetCells().UngroupRows(0, 6);
worksheet.GetCells().UngroupColumns(0, 3);
//Save the Excel file.
workbook.Save(outputGroupingUngroupingRowsAndColumns);
Aspose::Cells::Cleanup();