Creating Subtotals

Using Microsoft Excel

To create 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 is displayed. Define what function to use and where to place the subtotals.

    Selecting a data range to add subtotals


The Subtotal dialog


Using Aspose.Cells API

Aspose.Cells provides a class, Workbook that represents a Microsoft Excel file. The Workbook class contains a WorksheetCollection 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 a worksheet and other objects. Each worksheet consists of a Cells collection. To create subtotals in a worksheet, use the Cells class' subtotal method. Provide appropriate values for the parameters of the method to get the result you want.

The example below shows how to create subtotals in the first worksheet of the template file (Book1.xls) using Aspose.Cells API.

When the code is executed, a worksheet with subtotals is created.

Applying subtotals