تجميع وإلغاء تجميع الصفوف والأعمدة
مقدمة
في ملف Microsoft Excel، يمكنك إنشاء مخطط للبيانات للسماح لك بإظهار وإخفاء مستويات التفاصيل بنقرة واحدة على الفأرة.
انقر على رموز المخطط، 1,2,3، + و - لعرض الصفوف أو الأعمدة التي توفر ملخصات أو عناوين للأقسام في ورقة العمل بسرعة، أو يمكنك استخدام الرموز لرؤية التفاصيل تحت ملخص أو عنوان فردي كما يظهر أدناه في الشكل:
تجميع الصفوف والأعمدة. |
---|
![]() |
إدارة تجميع الصفوف والأعمدة
توفر Aspose.Cells فئة، Workbook التي تمثل ملف Microsoft Excel. تحتوي الفئة Workbook على WorksheetCollection التي تسمح بالوصول إلى كل ورقة عمل في ملف Excel. يتم تمثيل ورقة العمل بواسطة الفئة Worksheet. توفر الفئة Worksheet مجموعة 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 لك بتكوين إعدادات التجميع لعرض:
- صفوف ملخصية أسفل التفاصيل.
- أعمدة ملخصية على يمين التفاصيل.
يمكن للمطورين تكوين إعدادات التجميع باستخدام خاصية Outline لفئة Worksheet.
صفوف ملخصية أسفل التفاصيل
من الممكن التحكم في ما إذا كانت الصفوف الملخصية تُعرض أسفل التفاصيل عن طريق تعيين خاصية SummaryRowBelow لفئة Outline إلى صحيح أو خطأ.
// 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"); |
أعمدة ملخصية على يمين التفاصيل
يمكن للمطورين أيضًا التحكم في عرض الأعمدة الملخصية على يمين التفاصيل عن طريق تعيين خاصية SummaryColumnRight لفئة Outline إلى صحيح أو خطأ.
// 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"); |
إلغاء تجميع الصفوف والأعمدة
لإلغاء تجميع أي صفوف أو أعمدة مجمعة، يُمكن استدعاء UngroupRows و UngroupColumns من مجموعة Cells. تأخذ كلا الطريقتين معلمتين:
- الصف الأول أو فهرس العمود، الصف/العمود الأول الذي سيتم إلغاء تجميعه.
- الصف/العمود الأخير الذي سيتم إلغاء تجميعه.
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(); |