إظهار وإخفاء الصفوف والأعمدة وأشرطة التمرير
إظهار وإخفاء الصفوف والأعمدة
توفر Aspose.Cells لـ Python via .NET فئة، Workbook، تمثل ملف Excel من Microsoft. تحتوي فئة Workbook على مجموعة worksheets تتيح للمطورين الوصول إلى كل ورقة عمل في الملف. تمثل ورقة العمل بواسطة الفئة Worksheet. توفر الفئة Worksheet مجموعة cells التي تمثل جميع الخلايا في ورقة العمل. توفر مجموعة Cells عدة طرق لإدارة الصفوف أو الأعمدة في ورقة العمل. نناقش بعضًا منها أدناه.
إظهار الصفوف والأعمدة
يمكن للمطورين عرض أي صف أو عمود مخفي عن طريق استدعاء طرق unhide_row وunhide_column من مجموعة 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") | |
# 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] | |
# Unhiding the 3rd row and setting its height to 13.5 | |
worksheet.cells.unhide_row(2, 13.5) | |
# Unhiding the 2nd column and setting its width to 8.5 | |
worksheet.cells.unhide_column(1, 8.5) | |
# Saving the modified Excel file | |
workbook.save(dataDir + "output.xls") | |
# Closing the file stream to free all resources | |
fstream.close() |
إخفاء الصفوف والأعمدة
يمكن للمطورين إخفاء صف أو عمود عن طريق استدعاء طرق hide_row وhide_column من مجموعة 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") | |
# 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] | |
# Hiding the 3rd row of the worksheet | |
worksheet.cells.hide_row(2) | |
# Hiding the 2nd column of the worksheet | |
worksheet.cells.hide_column(1) | |
# Saving the modified Excel file | |
workbook.save(dataDir + "output.out.xls") | |
# Closing the file stream to free all resources | |
fstream.close() |
إخفاء صفوف وأعمدة متعددة
يمكن للمطورين إخفاء عدة صفوف أو أعمدة دفعة واحدة عن طريق استدعاء طرق hide_rows وhide_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") | |
# 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] | |
# Hiding 3,4 and 5 rows in the worksheet | |
worksheet.cells.hide_rows(2, 3) | |
# Hiding 2 and 3 columns in the worksheet | |
worksheet.cells.hide_columns(1, 2) | |
# Saving the modified Excel file | |
workbook.save(dataDir + "outputxls") | |
# Closing the file stream to free all resources | |
fstream.close() |
إظهار وإخفاء شريط التمرير
يُستخدم شريط التمرير للتنقل في محتويات أي ملف. عادة ما تكون هناك نوعين من شرائط التمرير:
- شرائط التمرير العمودية
- شرائط التمرير الأفقية
كما توفر Microsoft Excel أشرطة تمرير أفقية وعمودية بحيث يمكن للمستخدمين التمرير خلال محتويات ورقة العمل. باستخدام Aspose.Cells لـ Python via .NET، يمكن للمطورين التحكم في رؤية نوعي أشرطة التمرير في ملفات Excel.
التحكم في رؤية شرائط التمرير
توفر Aspose.Cells لـ Python via .NET فئة، Workbook، التي تمثل ملف Excel. توفر الفئة Workbook مجموعة واسعة من الخصائص والطرق لإدارة ملف Excel. للتحكم في رؤية أشرطة التمرير، استخدم خصائص WorkbookSettings.is_v_scroll_bar_visible وWorkbookSettings.is_h_scroll_bar_visible من الفئة Workbook. WorkbookSettings.is_v_scroll_bar_visible و WorkbookSettings.is_h_scroll_bar_visible هما خاصيتا Boolean، مما يعني أن هذه الخصائص يمكن أن تخزن فقط قيم true أو false.
جعل أشرطة التمرير مرئية
اجعل شرائط التمرير مرئية عن طريق تعيين خصائص الفئة Workbook WorkbookSettings.is_v_scroll_bar_visible أو WorkbookSettings.is_h_scroll_bar_visible إلى صحيحة.
إخفاء أشرطة التمرير
إخفاء أشرطة التمرير عن طريق تعيين خصائص الصنف Workbook WorkbookSettings.is_v_scroll_bar_visible أو WorkbookSettings.is_h_scroll_bar_visible إلى false.
كود عينة
بالأسفل يوجد شيفرة كاملة تفتح ملف إكسل، book1.xls، ثم تخفي كلتي الشريطين وتحفظ الملف المعدل بشكل output.xls.
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) | |
# Hiding the vertical scroll bar of the Excel file | |
workbook.settings.is_v_scroll_bar_visible = False | |
# Hiding the horizontal scroll bar of the Excel file | |
workbook.settings.is_h_scroll_bar_visible = False | |
# Saving the modified Excel file | |
workbook.save(dataDir + "output.xls") | |
# Closing the file stream to free all resources | |
fstream.close() |