تكوين المجاميع الفرعية
Contents
[
Hide
]
تكوين المجاميع الفرعية
يُظهر نموذج التعليمات البرمجية التالي كيفية إنشاء مجاميع فرعية باستخدام Aspose.Cells. يقوم الرمز بتحميل ملفنموذج ملف اكسل وينشئ مجاميع فرعية في نطاق الخلايا B13: C19 ويحفظ ملفملف اكسل الناتج. تُظهر لقطة الشاشة التالية كيف يبدو ملف العينة وملف excel الناتج بعد تنفيذ الكود.
عينة من الرموز
This file contains 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); |