分组、取消分组行和列
介绍
在 Microsoft Excel 文件中,您可以创建一个数据大纲,以便通过单击鼠标来显示和隐藏不同级别的细节。
单击大纲符号 1、2、3、+ 和 -,快速显示工作表中提供摘要或标题的行或列,或者您可以使用这些符号来查看摘要或标题下的详细信息。
行和列的分组管理
Aspose.Cells 提供了一个类,Workbook,它表示一个 Microsoft Excel 文件。Workbook 类包含一个 Worksheets 集合,允许访问 Excel 文件中的每个工作表。一个工作表由 Worksheet 类表示。Worksheet 类提供了一个 Cells 集合,表示工作表中的所有单元格。
Cells 集合提供了几种管理工作表中行或列的方法,下面更详细地讨论了其中的一些。
分组行和列
可以通过调用 Cells 和 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 方法。这两种方法都需要两个参数:
- 第一个要取消分组的行或列索引。
- 最后一个要取消分组的行或列索引。
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(); |