ワークシートの行と列をグループ化する
Contents
[
Hide
]
可能な使用シナリオ
Aspose.Cellsを使用すると、Cells.GroupRows() や Cells.GroupColumns() メソッドを使用して、ワークシート内の行と列をグループ化できます。
ワークシートの行と列をグループ化する
次のサンプルコードは、行と列を3つのレベルまでグループ化する方法を示しています。このコードで生成された 出力エクセルファイル をご確認ください。2つのワークシートが含まれており、最初のワークシートには行のグループ化、2番目のワークシートには列のグループ化が含まれています。行のグループ化の効果を示すスクリーンショットもご覧ください。
サンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
Aspose::Cells::Startup(); | |
//Output directory path | |
U16String outPath(u"..\\Data\\Output\\"); | |
//Path of output excel file | |
U16String outputGroupRowsAndColumnsOfWorksheet = outPath + u"outputGroupRowsAndColumnsOfWorksheet.xlsx"; | |
//Create an empty workbook | |
Workbook wb; | |
//Add worksheet for grouping rows | |
Worksheet grpRows = wb.GetWorksheets().Get(0); | |
grpRows.SetName(u"GroupRows"); | |
//Add worksheet for grouping columns | |
int idx = wb.GetWorksheets().Add(); | |
Worksheet grpCols = wb.GetWorksheets().Get(idx); | |
grpCols.SetName(u"GroupColumns"); | |
//Add sample values in both worksheets | |
for (int i = 0; i < 50; i++) | |
{ | |
U16String str(u"Text"); | |
grpRows.GetCells().Get(i, 0).PutValue(str); | |
grpCols.GetCells().Get(0, i).PutValue(str); | |
} | |
//Grouping rows at first level | |
grpRows.GetCells().GroupRows(0, 10); | |
grpRows.GetCells().GroupRows(12, 22); | |
grpRows.GetCells().GroupRows(24, 34); | |
//Grouping rows at second level | |
grpRows.GetCells().GroupRows(2, 8); | |
grpRows.GetCells().GroupRows(14, 20); | |
grpRows.GetCells().GroupRows(28, 30); | |
//Grouping rows at third level | |
grpRows.GetCells().GroupRows(5, 7); | |
//Grouping columns at first level | |
grpCols.GetCells().GroupColumns(0, 10); | |
grpCols.GetCells().GroupColumns(12, 22); | |
grpCols.GetCells().GroupColumns(24, 34); | |
//Grouping columns at second level | |
grpCols.GetCells().GroupColumns(2, 8); | |
grpCols.GetCells().GroupColumns(14, 20); | |
grpCols.GetCells().GroupColumns(28, 30); | |
//Grouping columns at third level | |
grpCols.GetCells().GroupColumns(5, 7); | |
//Save the output excel file | |
wb.Save(outputGroupRowsAndColumnsOfWorksheet); | |
Aspose::Cells::Cleanup(); |