分组和取消分组行和列
Contents
[
Hide
]
介绍
在 Microsoft Excel 文件中,您可以为数据创建一个大纲,以便通过单击鼠标来显示和隐藏详细信息级别。
点击大纲符号、1、2、3、+ 和 - 快速仅显示工作表中为各部分提供摘要或标题的行或列,或者您可以使用符号查看单个摘要或标题下的详细信息,如下图所示:
分组行和列。 |
---|
![]() |
行列分组管理
Aspose.Cells提供了一个类,工作簿表示 Microsoft Excel 文件。这工作簿类包含一个工作表集合允许访问 Excel 文件中的每个工作表。工作表由工作表班级。这工作表类提供了Cells代表工作表中所有单元格的集合。
这Cellscollection 提供了多种方法来管理工作表中的行或列,下面将详细讨论其中的一些方法。
分组行和列
可以通过调用组行和组列的方法Cells收藏。这两种方法都采用以下参数:
- 第一行/列索引,组中的第一行或第一列。
- 最后一行/列索引,组中的最后一行或最后一列。
- is hidden,布尔型参数,指定分组后是否隐藏行/列。
This file contains hidden or 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-.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 允许您配置组设置以显示:
- 详细信息下方的汇总行。
- 详细信息右侧的摘要列。
详细信息下方的汇总行
This file contains hidden or 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-.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"); |
详细信息右侧的摘要列
This file contains hidden or 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-.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收藏的解组行和取消组合列方法。两种方法都有两个参数:
- 第一行或第一列索引,要取消分组的第一行/列。
- 最后一行或最后一列索引,要取消分组的最后一行/列。
解组行有一个带有第三个布尔参数的重载。将其设置为真的删除所有分组信息。否则,仅删除外部组信息。
This file contains hidden or 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-.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(); |