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

序章

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

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

行と列のグループ化。
todo:画像_代替_文章

行と列のグループ管理

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

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

行と列のグループ化

行または列をグループ化するには、グループ行グループ列のメソッドCellsコレクション。どちらのメソッドも、次のパラメーターを取ります。

  • 最初の行/列インデックス、グループ内の最初の行または列。
  • 最後の行/列インデックス、グループ内の最後の行または列。
  • グループ化後に行/列を非表示にするかどうかを指定するブール値パラメーターです。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Grouping first six rows (from 0 to 5) and making them hidden by passing true
worksheet.Cells.GroupRows(0, 5, true);
// Grouping first three columns (from 0 to 2) and making them hidden by passing true
worksheet.Cells.GroupColumns(0, 2, true);
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");
// Closing the file stream to free all resources
fstream.Close();

グループ設定

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

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

開発者は、概要のプロパティワークシートクラス。

詳細の下への要約行

を設定することで、要約行を詳細の下に表示するかどうかを制御できます。概要クラス'概要RowBelowプロパティへ真実また間違い.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Workbook workbook = new Workbook(dataDir + "sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Grouping first six rows and first three columns
worksheet.Cells.GroupRows(0, 5, true);
worksheet.Cells.GroupColumns(0, 2, true);
// Setting SummaryRowBelow property to false
worksheet.Outline.SummaryRowBelow = false;
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");

詳細の右側にある要約列

開発者は、詳細の右側に表示される集計列を制御することもできます。サマリー列右のプロパティ概要クラスへ真実また間違い.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Workbook workbook = new Workbook(dataDir + "sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Grouping first six rows and first three columns
worksheet.Cells.GroupRows(0, 5, true);
worksheet.Cells.GroupColumns(0, 2, true);
worksheet.Outline.SummaryColumnRight = true;
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");

行と列のグループ解除

グループ化された行または列のグループ化を解除するには、Cellsコレクションの行のグループ化を解除列のグループ化を解除メソッド。どちらのメソッドも次の 2 つのパラメーターを取ります。

  • 最初の行または列のインデックス。グループ化を解除する最初の行/列。
  • 最後の行または列のインデックス、グループ化を解除する最後の行/列。

行のグループ化を解除Boolean の 3 番目のパラメーターを取るオーバーロードがあります。に設定する真実グループ化されたすべての情報を削除します。それ以外の場合は、外側のグループ情報のみが削除されます。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Ungrouping first six rows (from 0 to 5)
worksheet.Cells.UngroupRows(0, 5);
// Ungrouping first three columns (from 0 to 2)
worksheet.Cells.UngroupColumns(0, 2);
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");
// Closing the file stream to free all resources
fstream.Close();