إنشاء المجاميع الفرعية
Contents
[
Hide
]
إنشاء المجاميع الفرعية
يُوضح الكود النموذجي التالي كيفية إنشاء مجاميع فرعية باستخدام Aspose.Cells. يقوم الكود بتحميل ملف الإكسل العيني وإنشاء المجاميع الفرعية على نطاق الخلايا B13:C19 ثم يقوم بحفظ ملف الإكسل الناتج. يُظهر اللقطة الشاشة التالية كيفية ظهور ملف الإكسل العيني والناتج بعد تنفيذ الكود.
الكود المثالي
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
Aspose::Cells::Startup(); | |
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Path of input | |
U16String dirPath(u""); | |
//Path of output | |
U16String outPath(u""); | |
//Path of input excel file | |
U16String sampleCreatingSubtotals = dirPath + u"sampleCreatingSubtotals.xlsx"; | |
//Path of output excel file | |
U16String outputCreatingSubtotals = outPath + u"outputCreatingSubtotals.xlsx"; | |
//Load sample excel file into a workbook object | |
Workbook wb(sampleCreatingSubtotals); | |
//Get first worksheet of the workbook | |
Worksheet ws = wb.GetWorksheets().Get(0); | |
//Get the cells collection of the worksheet | |
Cells cells = ws.GetCells(); | |
//Create cell area covering the cell range B3:C19 | |
CellArea ca = CellArea::CreateCellArea(u"B3", u"C19"); | |
//Create integer array of size 1 and set its first value to 1 | |
int data[1]{1}; | |
Vector<int> totalList(data,1); | |
//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); | |
Aspose::Cells::Cleanup(); |