行と列のグループ化とグループ解除

序章

Microsoft Excel ファイルでは、データのアウトラインを作成して、マウスを 1 回クリックするだけで詳細レベルを表示および非表示にすることができます。

クリック外形記号、1、2、3、+、および - を使用して、ワークシート内のセクションの要約または見出しを提供する行または列のみをすばやく表示するか、シンボルを使用して、下の図に示すように個々の要約または見出しの下に詳細を表示できます。 :

行と列のグループ化

todo:画像_代替_文章

行と列のグループ管理

Aspose.Cells はクラスを提供し、ワークブックMicrosoft Excel ファイルを表します。のワークブッククラスにはワークシートExcel ファイル内の各ワークシートにアクセスできるコレクション。ワークシートは、ワークシートクラス。のワークシートクラスはCellsワークシート内のすべてのセルを表すコレクション。

Cellscollection は、ワークシートの行または列を管理するためのいくつかの方法を提供します。これらのいくつかについては、以下で詳しく説明します。

行と列のグループ化

行または列をグループ化するには、[グループ行](https://reference.aspose.com/cells/java/com.aspose.cells/cells#groupRows(int,%20int,%20boolean) ) と[グループ列](https://reference.aspose.com/cells/java/com.aspose.cells/cells#groupColumns(int,%20int,%20boolean) のメソッドCellsコレクション。どちらのメソッドも、次のパラメーターを取ります。

  • 最初の行/列インデックス、グループ内の最初の行または列。
  • 最後の行/列インデックス、グループ内の最後の行または列。
  • グループ化後に行/列を非表示にするかどうかを指定するブール値パラメーターです。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(GroupingRowsandColumns.class) + "RowsAndColumns/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "Book1.xlsx");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
// Grouping first six rows (from 0 to 5) and making them hidden by
// passing true
cells.groupRows(0, 5, true);
// Grouping first three columns (from 0 to 2) and making them hidden by
// passing true
cells.groupColumns(0, 2, true);
// Setting SummaryRowBelow property to false
worksheet.getOutline().setSummaryRowBelow(true);
// Setting SummaryColumnRight property to false
worksheet.getOutline().setSummaryColumnRight(true);
// Saving the modified Excel file in default (that is Excel 2003) format
workbook.save(dataDir + "GroupingRowsandColumns_out.xlsx");

グループ設定

Microsoft Excel では、表示するグループ設定を構成することもできます。

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

グループ設定

todo:画像_代替_文章

Worksheet クラスの Outline プロパティを使用して、これらのグループ設定を構成することができます。

詳細の下の要約行

開発者は、概要クラス'概要RowBelow方法。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SummaryRowBelow.class) + "RowsAndColumns/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
// Grouping first six rows (from 0 to 5) and making them hidden by passing true
cells.groupRows(0, 5, true);
// Grouping first three columns (from 0 to 2) and making them hidden by passing true
cells.groupColumns(0, 2, true);
// Setting SummaryRowBelow property to false
worksheet.getOutline().setSummaryRowBelow(false);
// Saving the modified Excel file in default (that is Excel 2003) format
workbook.save(dataDir + "SummaryRowBelow_out.xls");

詳細の右側にある要約列

詳細の右側に要約列を表示するかどうかは、概要クラス'サマリー列右方法。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SummaryRowRight.class) + "RowsAndColumns/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "BookStyles.xls");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
// Grouping first six rows (from 0 to 5) and making them hidden by passing true
cells.ungroupRows(0, 5);
// Grouping first three columns (from 0 to 2) and making them hidden by passing true
cells.ungroupColumns(0, 2);
// Saving the modified Excel file in default (that is Excel 2003) format
workbook.save(dataDir + "SummaryRowRight_out.xls");

行と列のグループ解除

グループ化された行または列のグループ化を解除するには、Cellsコレクションの[行のグループ化を解除](https://reference.aspose.com/cells/java/com.aspose.cells/cells#ungroupRows(int,%20int) ) と列のグループ化を解除 メソッド。どちらのメソッドも同じパラメーターを取ります。

  • 最初の行または列のインデックス。グループ化を解除する最初の行/列。
  • 最後の行または列のインデックス、グループ化を解除する最後の行/列。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(UngroupingRowsandColumns.class) + "rows_cloumns/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "BookStyles.xls");
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
// Grouping first six rows (from 0 to 5) and making them hidden by
// passing true
cells.ungroupRows(0, 5);
// Grouping first three columns (from 0 to 2) and making them hidden by
// passing true
cells.ungroupColumns(0, 2);
// Saving the modified Excel file in default (that is Excel 2003) format
workbook.save(dataDir + "UngroupingRowsandColumns_out.xls");
// Print message
System.out.println("Rows and Columns ungrouped successfully.");