创建分类汇总
使用Microsoft Excel
在Microsoft Excel中添加小计:
- 在工作簿的第一个工作表中创建一个简单的数据列表(如下图所示),并将文件保存为 Book1.xls。
- 选择列表中的任何单元格。
- 从数据菜单中选择小计。将显示小计对话框。定义要使用的函数和放置小计的位置。
使用Aspose.Cells for Node.js via C++ API
Aspose.Cells for Node.js via C++提供一个类Workbook,表示一个Microsoft Excel文件。Workbook类包含一个Worksheets集合,允许访问Excel文件中的每个工作表。
工作表由Worksheet类表示。该类提供了广泛的属性和方法来管理工作表和其他对象。每个工作表都包含一个Cells集合。要向工作表添加小计,请使用Cells类的subtotal方法。向该方法提供参数值以指定如何计算和放置小计。
以下示例中,我们使用Aspose.Cells for Node.js via C++ API在模板文件的第一个工作表中添加了小计。当代码执行时,会创建一个带有小计的工作表。
以下代码片段展示了如何使用Aspose.Cells for Node.js via C++为工作表添加小计。
const AsposeCells = require("aspose.cells.node"); | |
// Instantiate a new workbook | |
// Open the template file | |
var workbook = new AsposeCells.Workbook("book1.xlsx"); | |
// Get the Cells collection in the first worksheet | |
var cells = workbook.getWorksheets().get(0).getCells(); | |
// Create a cellarea i.e.., B3:C19 | |
var ca = new AsposeCells.CellArea(); | |
ca.startRow = 2; | |
ca.startColumn = 1; | |
ca.endRow = 18; | |
ca.endColumn = 2; | |
// Apply subtotal, the consolidation function is Sum and it will applied to | |
// Second column (C) in the list | |
cells.subtotal(ca, 0, AsposeCells.ConsolidationFunction.Sum, [1]); | |
// Save the excel file | |
workbook.save("output.out.xlsx"); |