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

مقدمة

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

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

تجميع الصفوف والأعمدة.
todo:image_alt_text

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

توفر Aspose.Cells for Python via .NET فئة، Workbook التي تمثل ملف Microsoft Excel. تحتوي الفئة Workbook على WorksheetCollection يسمح بالوصول إلى كل ورقة عمل في ملف Excel. تمثل ورقة عمل بواسطة الفئة Worksheet. توفر الفئة Worksheet مجموعة Cells تمثل جميع الخلايا في الورقة العمل.

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

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

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

  • مؤشر الصف أو العمود الأول في المجموعة.
  • مؤشر الصف أو العمود الأخير في المجموعة.
  • يتم إخفاءها، معلمة منطقية تحدد ما إذا كان سيتم إخفاء الصفوف/الأعمدة بعد التجميع أم لا.
from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Grouping first six rows (from 0 to 5) and making them hidden by passing true
worksheet.cells.group_rows(0, 5, True)
# Grouping first three columns (from 0 to 2) and making them hidden by passing true
worksheet.cells.group_columns(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.

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

من الممكن التحكم في ما إذا كانت الصفوف الملخصية تُعرض أسفل التفاصيل عن طريق تعيين خاصية summary_row_below لفئة Outline إلى صحيح أو خطأ.

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
workbook = Workbook(dataDir + "sample.xlsx")
worksheet = workbook.worksheets[0]
# Grouping first six rows and first three columns
worksheet.cells.group_rows(0, 5, True)
worksheet.cells.group_columns(0, 2, True)
# Setting SummaryRowBelow property to false
worksheet.outline.summary_row_below = False
# Saving the modified Excel file
workbook.save(dataDir + "output.xls")

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

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

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
workbook = Workbook(dataDir + "sample.xlsx")
worksheet = workbook.worksheets[0]
# Grouping first six rows and first three columns
worksheet.cells.group_rows(0, 5, True)
worksheet.cells.group_columns(0, 2, True)
worksheet.outline.summary_column_right = True
# Saving the modified Excel file
workbook.save(dataDir + "output.xls")

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

لإلغاء تجميع أي صفوف أو أعمدة مجمعة، يُمكن استدعاء ungroup_rows و ungroup_columns من مجموعة Cells. تأخذ كلا الطريقتين معلمتين:

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

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

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Creating a file stream containing the Excel file to be opened
fstream = open(dataDir + "book1.xls", "rb")
# Instantiating a Workbook object
# Opening the Excel file through the file stream
workbook = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
# Ungrouping first six rows (from 0 to 5)
worksheet.cells.ungroup_rows(0, 5)
# Ungrouping first three columns (from 0 to 2)
worksheet.cells.ungroup_columns(0, 2)
# Saving the modified Excel file
workbook.save(dataDir + "output.xls")
# Closing the file stream to free all resources
fstream.close()