Creazione di subtotali
Contents
[
Hide
]
Creazione di subtotali
Il seguente codice di esempio mostra come creare subtotali utilizzando Aspose.Cells. Il codice carica ilfile excel di esempio e crea subtotali nell’intervallo di celle B13:C19 e salva il filefile excel di output. Lo screenshot seguente mostra come il file excel di esempio e di output si occupa dell’esecuzione del codice.
Codice d’esempio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input excel file | |
StringPtr sampleCreatingSubtotals = dirPath->StringAppend(new String("sampleCreatingSubtotals.xlsx")); | |
//Path of output excel file | |
StringPtr outputCreatingSubtotals = outPath->StringAppend(new String("outputCreatingSubtotals.xlsx")); | |
//Load sample excel file into a workbook object | |
intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook(sampleCreatingSubtotals); | |
//Get first worksheet of the workbook | |
intrusive_ptr<IWorksheet> ws = wb->GetIWorksheets()->GetObjectByIndex(0); | |
//Get the cells collection of the worksheet | |
intrusive_ptr<ICells> cells = ws->GetICells(); | |
//Create cell area covering the cell range B3:C19 | |
intrusive_ptr<ICellArea> ca = ICellArea::CreateICellArea(new String("B3"), new String("C19")); | |
//Create integer array of size 1 and set its first value to 1 | |
intrusive_ptr<Array1D<int>> totalList = new Array1D<int>(1); | |
totalList->SetValue(1, 0); | |
//Apply subtotal, the consolidation function is Sum and it will be applied to second column | |
cells->Subtotal(ca, 0, ConsolidationFunction_Sum, totalList); | |
//Save the workbook in xlsx format | |
wb->Save(outputCreatingSubtotals); |