إعدادات الحماية المتقدمة منذ Excel XP

مقدمة

تقييد أو السماح للمستخدمين بـ:

  • حذف الصفوف أو الأعمدة.
  • تحرير المحتويات أو الكائنات أو السيناريوهات.
  • تنسيق الخلايا أو الصفوف أو الأعمدة.
  • إدراج الصفوف أو الأعمدة أو الروابط الفرعية.
  • تحديد الخلايا المقفلة أو غير المقفلة.
  • استخدام الجداول المحورية وأكثر من ذلك بكثير.

يدعم Aspose.Cells for Python via .NET جميع إعدادات الحماية المتقدمة التي تقدمها إكسل XP أو الإصدارات الأحدث.

إعدادات الحماية المتقدمة باستخدام Excel XP والإصدارات اللاحقة

لعرض إعدادات الحماية المتاحة في Excel XP:

  1. من القائمة أدوات, اختر الحماية ثم حماية الورقة. سيتم عرض مربع الحوار.

لاستعراض إعدادات الحماية المتوفرة في Excel 2016

  1. من القائمة ملف, اختر حماية الدفتر ثم حماية الورقة الحالية.
  2. حدد حماية الورقة في قائمة مراجعة.

باتباع الخطوات المذكورة أعلاه ستظهر مربع حوار حيث يمكنك السماح أو تقييد ميزات ورقات العمل أو تطبيق كلمة مرور على ورقة العمل.

إعدادات الحماية المتقدمة باستخدام Aspose.Cells for Python via .NET

يدعم Aspose.Cells for Python via .NET جميع إعدادات الحماية المتقدمة.

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

توفر فئة Worksheet الخاصية protection المستخدمة لتطبيق هذه الإعدادات المتقدمة للحماية. الخاصية Protection في الواقع هي كائن من فئة Protection الذي يغلف العديد من الخصائص المنطقية لتعطيل أو تمكين القيود.

فيما يلي مثال تطبيقي صغير. يفتح ملف Excel ويستخدم معظم إعدادات الحماية المتقدمة المدعومة من Excel XP والإصدارات اللاحقة.

from aspose.cells import SaveFormat, 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
excel = Workbook(fstream)
# Accessing the first worksheet in the Excel file
worksheet = excel.worksheets[0]
# Restricting users to delete columns of the worksheet
worksheet.protection.allow_deleting_column = False
# Restricting users to delete row of the worksheet
worksheet.protection.allow_deleting_row = False
# Restricting users to edit contents of the worksheet
worksheet.protection.allow_editing_content = False
# Restricting users to edit objects of the worksheet
worksheet.protection.allow_editing_object = False
# Restricting users to edit scenarios of the worksheet
worksheet.protection.allow_editing_scenario = False
# Restricting users to filter
worksheet.protection.allow_filtering = False
# Allowing users to format cells of the worksheet
worksheet.protection.allow_formatting_cell = True
# Allowing users to format rows of the worksheet
worksheet.protection.allow_formatting_row = True
# Allowing users to insert columns in the worksheet
worksheet.protection.allow_formatting_column = True
# Allowing users to insert hyperlinks in the worksheet
worksheet.protection.allow_inserting_hyperlink = True
# Allowing users to insert rows in the worksheet
worksheet.protection.allow_inserting_row = True
# Allowing users to select locked cells of the worksheet
worksheet.protection.allow_selecting_locked_cell = True
# Allowing users to select unlocked cells of the worksheet
worksheet.protection.allow_selecting_unlocked_cell = True
# Allowing users to sort
worksheet.protection.allow_sorting = True
# Allowing users to use pivot tables in the worksheet
worksheet.protection.allow_using_pivot_table = True
# Saving the modified Excel file
excel.save(dataDir + "output.xls", SaveFormat.EXCEL_97_TO_2003)
# Closing the file stream to free all resources
fstream.close()

مشكلة قفل الخلية

إذا كنت ترغب في تقييد المستخدمين من تحرير الخلايا يجب أن تكون الخلايا مقفلة قبل تطبيق أي إعدادات حماية. وإلا يمكن تحرير الخلايا حتى لو تم حماية ورقة العمل. في Microsoft Excel XP، يمكن قفل الخلايا من خلال المربع الحوار التالي:

مربع الحوار لقفل الخلايا في Excel XP
todo:image_alt_text

من الممكن أيضًا قفل الخلايا باستخدام واجهة برمجة التطبيقات Aspose.Cells for Python via .NET. يمكن لكل خلية الحصول على تنسيق Style الذي يحتوي على خاصية Boolean، is_locked. ضبط الخاصية is_locked على true أو false لقفل أو إلغاء قفل الخلية.

from aspose.cells import ProtectionType, 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 + "Book1.xlsx")
# Accessing the first worksheet in the Excel file
worksheet = workbook.worksheets[0]
worksheet.cells.get("A1").get_style().is_locked = True
# Finally, Protect the sheet now.
worksheet.protect(ProtectionType.ALL)
workbook.save(dataDir + "output.xlsx")