创建分类汇总

使用Microsoft Excel

在Microsoft Excel中添加小计:

  1. 在工作簿的第一个工作表中创建一个简单的数据列表(如下图所示),并将文件保存为 Book1.xls。
  2. 选择列表中的任何单元格。
  3. 数据菜单中选择小计。将显示小计对话框。定义要使用的函数和放置小计的位置。

使用Aspose.Cells for Python via .NET API

Aspose.Cells for Python via .NET提供一个代表Microsoft Excel文件的类,WorkbookWorkbook类包含一个worksheets集合,允许访问Excel文件中的每个工作表。

工作表由Worksheet类表示。该类提供了广泛的属性和方法来管理工作表和其他对象。每个工作表都包含一个Cells集合。要向工作表添加小计,请使用Cells类的subtotal方法。向该方法提供参数值以指定如何计算和放置小计。

在下面的示例中,我们使用Aspose.Cells for Python via .NET API向模板文件(Book1.xls)的第一个工作表添加了小计。当执行代码时,将创建一个带有小计的工作表。

接下来的代码片段展示了如何使用Aspose.Cells for Python via .NET向工作表添加小计。

from aspose.cells import CellArea, ConsolidationFunction, Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Instantiate a new workbook
# Open the template file
workbook = Workbook(dataDir + "book1.xls")
# Get the Cells collection in the first worksheet
cells = workbook.worksheets[0].cells
# Create a cellarea i.e.., B3:C19
ca = CellArea()
ca.start_row = 2
ca.start_column = 1
ca.end_row = 18
ca.end_column = 2
# Apply subtotal, the consolidation function is Sum and it will applied to
# Second column (C) in the list
cells.subtotal(ca, 0, ConsolidationFunction.SUM, [1 ])
# Save the excel file
workbook.save(dataDir + "output.out.xls")

高级主题