Creare subtotali in Excel usando C#

This short tutorial explains how to add a subtotal in Excel using C#. You will get details on how to set up the IDE, a list of steps, and sample code to create subtotals in Excel using C#. All details will be shared to customize the Excel file to outline the grouped data before saving the Excel file.

Passaggi per creare subtotali automatici con C#

  1. Configura l’ambiente per utilizzare Aspose.Cells for .NET per aggiungere un subtotale
  2. Set the license to use the library without evaluation limits.
  3. Create the workbook object and access its first sheet.
  4. Aggiungi etichette per le intestazioni nella prima riga
  5. Set the data in the rows using the array data.
  6. Define the data range excluding the header row.
  7. Use the Subtotal() method to group the data by Region and sum the Amount.
  8. Iterate through all outline levels to compress the grouped rows.
  9. Save the file to disk with the data and subtotals inside it.

I passaggi sopra riassumono come creare subtotali in Excel usando C#. Instantiate a Workbook, access the first sheet, add headers, insert some sample data, define the data range, and apply a subtotal grouping by Region in the Amount column. Configure the online behavior, add the summary row, compress the data, and auto-fit the columns before saving the Excel file.

Code to create automatic subtotals in Excel with C#.

This code demonstrates how to create subtotals in Excel using C#. It is possible to customize the output by sorting the group columns before calling the Subtotal function, adding more subtotal functions such as Sum and Average, and using SubtotalSetting to display the summary below or to the right of the data. It is also possible to set styles for subtotal rows, for example making them bold or filling them with color.

This article showed us the process to add a subtotal in the Excel file. To connect a slicer to multiple pivot tables, refer to the article Connect slicer to multiple pivot tables using C#.

 Italiano