تجميع الصفوف والأعمدة لورقة العمل
سيناريوهات الاستخدام المحتملة
تسمح Aspose.Cells لك بتجميع الصفوف والأعمدة في ورقة عمل باستخدام Cells.GroupRows() و Cells.GroupColumns() .
تجميع الصفوف والأعمدة لورقة العمل
يعرض الكود العينة التالي كيفية تجميع الصفوف والأعمدة. يقوم بتجميع الصفوف والأعمدة حتى المستوى 3. يرجى التحقق من ملف Excel الناتج الذي تم إنشاؤه باستخدام هذا الكود. يحتوي على ورقتي عمل، الأولى تحتوي على تجميع الصفوف والثانية تحتوي على تجميع الأعمدة. يرجى أيضًا رؤية اللقطة الشاشة التي توضح تجميع الصفوف في ورقة العمل الأولى.
الكود المثالي
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
Aspose::Cells::Startup(); | |
//Output directory path | |
U16String outPath(u"..\\Data\\Output\\"); | |
//Path of output excel file | |
U16String outputGroupRowsAndColumnsOfWorksheet = outPath + u"outputGroupRowsAndColumnsOfWorksheet.xlsx"; | |
//Create an empty workbook | |
Workbook wb; | |
//Add worksheet for grouping rows | |
Worksheet grpRows = wb.GetWorksheets().Get(0); | |
grpRows.SetName(u"GroupRows"); | |
//Add worksheet for grouping columns | |
int idx = wb.GetWorksheets().Add(); | |
Worksheet grpCols = wb.GetWorksheets().Get(idx); | |
grpCols.SetName(u"GroupColumns"); | |
//Add sample values in both worksheets | |
for (int i = 0; i < 50; i++) | |
{ | |
U16String str(u"Text"); | |
grpRows.GetCells().Get(i, 0).PutValue(str); | |
grpCols.GetCells().Get(0, i).PutValue(str); | |
} | |
//Grouping rows at first level | |
grpRows.GetCells().GroupRows(0, 10); | |
grpRows.GetCells().GroupRows(12, 22); | |
grpRows.GetCells().GroupRows(24, 34); | |
//Grouping rows at second level | |
grpRows.GetCells().GroupRows(2, 8); | |
grpRows.GetCells().GroupRows(14, 20); | |
grpRows.GetCells().GroupRows(28, 30); | |
//Grouping rows at third level | |
grpRows.GetCells().GroupRows(5, 7); | |
//Grouping columns at first level | |
grpCols.GetCells().GroupColumns(0, 10); | |
grpCols.GetCells().GroupColumns(12, 22); | |
grpCols.GetCells().GroupColumns(24, 34); | |
//Grouping columns at second level | |
grpCols.GetCells().GroupColumns(2, 8); | |
grpCols.GetCells().GroupColumns(14, 20); | |
grpCols.GetCells().GroupColumns(28, 30); | |
//Grouping columns at third level | |
grpCols.GetCells().GroupColumns(5, 7); | |
//Save the output excel file | |
wb.Save(outputGroupRowsAndColumnsOfWorksheet); | |
Aspose::Cells::Cleanup(); |