Creating Subtotals

Using Microsoft Excel

To add subtotals in Microsoft Excel:

  1. Create a simple data list in the first worksheet of the workbook (as shown in the figure below) and save the file as Book1.xls.
  2. Select any cell within your list.
  3. From the Data menu, select Subtotals. The Subtotals dialog will be displayed. Define what function to use and where to place the subtotals.

Using the Aspose.Cells API

Aspose.Cells provides a class, Workbook, that represents a Microsoft Excel file. The Workbook class contains a Worksheets collection that allows access to each worksheet in the Excel file.

A worksheet is represented by the Worksheet class. The class provides a wide range of properties and methods for managing worksheets and other objects. Each worksheet consists of a Cells collection. To add subtotals to a worksheet, use the Cells class' Subtotal method. Provide parameter values to the method to specify how the subtotal should be calculated and placed.

In the examples below, we have added subtotals to the first worksheet of the template file (Book1.xls) using the Aspose.Cells API. When the code is executed, a worksheet with subtotals is created.

The code snippets that follow show how to add subtotals to a worksheet with Aspose.Cells for .NET.

Advance topics