تجميع وإلغاء تجميع الصفوف والأعمدة

مقدمة

في ملف Excel Microsoft ، يمكنك إنشاء مخطط تفصيلي للبيانات للسماح لك بإظهار مستويات التفاصيل وإخفائها بنقرة واحدة بالماوس.

انقر علىرموز المخطط التفصيلي، 1 ، 2 ، 3 ، + و - لعرض الصفوف أو الأعمدة التي توفر ملخصات أو عناوين للأقسام في ورقة العمل فقط بسرعة ، أو يمكنك استخدام الرموز لمشاهدة التفاصيل ضمن ملخص فردي أو عنوان كما هو موضح أدناه في الشكل :

تجميع الصفوف والأعمدة.
ما يجب القيام به: image_بديل_نص

إدارة المجموعة للصفوف والأعمدة

Aspose.Cells يوفر فصل دراسي ،دفتر العمل يمثل ملف Excel Microsoft. الدفتر العمل فئة تحتوي علىورقة العمل يسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطةورقة عمل صف دراسي. الورقة عمل فئة توفر أCellsمجموعة تمثل جميع الخلايا في ورقة العمل.

الCellsتوفر المجموعة عدة طرق لإدارة الصفوف أو الأعمدة في ورقة العمل ، وقد تمت مناقشة القليل منها أدناه بمزيد من التفصيل.

تجميع الصفوف والأعمدة

من الممكن تجميع الصفوف أو الأعمدة عن طريق استدعاءGroupRows وGroupColumns طرقCells مجموعة. تأخذ كلتا الطريقتين المعلمات التالية:

  • أول صف / فهرس العمود ، أول صف أو عمود في المجموعة.
  • فهرس الصف / العمود الأخير ، الصف أو العمود الأخير في المجموعة.
  • مخفي ، معلمة منطقية تحدد ما إذا كان سيتم إخفاء الصفوف / الأعمدة بعد التجميع أم لا.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Grouping first six rows (from 0 to 5) and making them hidden by passing true
worksheet.Cells.GroupRows(0, 5, true);
// Grouping first three columns (from 0 to 2) and making them hidden by passing true
worksheet.Cells.GroupColumns(0, 2, true);
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");
// Closing the file stream to free all resources
fstream.Close();

إعدادات المجموعة

Microsoft يسمح لك Excel بتكوين إعدادات المجموعة لعرض:

  • صفوف التلخيص أدناه التفاصيل.
  • أعمدة التلخيص على يمين التفاصيل.

يمكن للمطورين تكوين إعدادات المجموعة هذه باستخدام ملفالخطوط العريضة ممتلكاتورقة عملصف دراسي.

صفوف الملخص إلى أسفل التفاصيل

من الممكن التحكم في عرض صفوف التلخيص أدناه بالتفصيل عن طريق تعيينالخطوط العريضة صف دراسي'ملخص ملكية لحقيقي أوخاطئة.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Workbook workbook = new Workbook(dataDir + "sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Grouping first six rows and first three columns
worksheet.Cells.GroupRows(0, 5, true);
worksheet.Cells.GroupColumns(0, 2, true);
// Setting SummaryRowBelow property to false
worksheet.Outline.SummaryRowBelow = false;
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");

أعمدة التلخيص إلى يمين التفاصيل

يمكن للمطورين أيضًا التحكم في عرض أعمدة الملخص على يمين التفاصيل عن طريق تعيينملخص العمود ممتلكاتالخطوط العريضة الفئة الىحقيقي أوخاطئة.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
Workbook workbook = new Workbook(dataDir + "sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Grouping first six rows and first three columns
worksheet.Cells.GroupRows(0, 5, true);
worksheet.Cells.GroupColumns(0, 2, true);
worksheet.Outline.SummaryColumnRight = true;
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");

فك تجميع الصفوف والأعمدة

لفك تجميع أي صفوف أو أعمدة مجمعة ، قم باستدعاءCells المجموعةUngroupRows وUngroupColumnsأساليب. تأخذ كلتا الطريقتين معلمتين:

  • الصف الأول أو فهرس العمود ، الصف / العمود الأول المراد فك تجميعه.
  • فهرس الصف أو العمود الأخير ، الصف / العمود الأخير المراد فك تجميعه.

UngroupRows يحتوي على حمل زائد يأخذ المعلمة المنطقية الثالثة. ضبطه علىحقيقييزيل كافة المعلومات المجمعة. خلاف ذلك ، تتم إزالة معلومات المجموعة الخارجية فقط.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
// Ungrouping first six rows (from 0 to 5)
worksheet.Cells.UngroupRows(0, 5);
// Ungrouping first three columns (from 0 to 2)
worksheet.Cells.UngroupColumns(0, 2);
// Saving the modified Excel file
workbook.Save(dataDir + "output.xls");
// Closing the file stream to free all resources
fstream.Close();