应用小计和更改明细下方大纲汇总行的方向
Contents
[
Hide
]
本文将说明如何将小计应用于数据以及更改明细下方大纲汇总行的方向。
您可以使用将小计应用于数据工作表.Cells.小计()方法。它采用以下参数。
- 单元格区域 应用小计的范围
- 通过…分组 分组依据的字段,作为从零开始的整数偏移量
- 功能 小计功能。
- 总表 一个从零开始的字段偏移数组,指示要添加小计的字段。
- 代替 表示是否替换当前小计
- 分页符 - 表示组间是否加分页符
- 汇总以下数据 指示是否在数据下方添加摘要。
此外,您还可以控制 Outline 的方向详细信息下方的摘要行如以下屏幕截图所示,使用 Worksheet.Outline.SummaryRowBelow 属性。您可以使用 Microsoft Excel 打开此设置数据 > 大纲 > 设置
源文件和输出文件的图像
以下屏幕截图显示了以下示例代码中使用的源 Excel 文件,其中包含 A 列和 B 列中的一些数据。
以下屏幕截图显示了示例代码生成的输出 Excel 文件。如您所见,小计已应用于范围 A2:B11,大纲的方向是详细信息下方的汇总行。
C# 应用小计和更改大纲摘要行方向的代码
这是实现如上所示输出的示例代码。
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-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook from source Excel file | |
Workbook workbook = new Workbook(dataDir + "Book1.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Get the Cells collection in the first worksheet | |
Cells cells = worksheet.Cells; | |
// Create a cellarea i.e.., A2:B11 | |
CellArea ca = CellArea.CreateCellArea("A2", "B11"); | |
// Apply subtotal, the consolidation function is Sum and it will applied to Second column (B) in the list | |
cells.Subtotal(ca, 0, ConsolidationFunction.Sum, new int[] { 1 }, true, false, true); | |
// Set the direction of outline summary | |
worksheet.Outline.SummaryRowBelow = true; | |
// Save the excel file | |
workbook.Save(dataDir + "output_out.xlsx"); |