قفل أو فتح الشكل
Contents
[
Hide
]
أحيانًا، تحتاج إلى حماية جميع الأشكال في بعض الأوراق لمنع تدميرها من قبل مواقف غير مرغوب فيها. في هذه الحالة، تحتاج إلى قفل جميع الأشكال في الورقة المحددة.
أحيانًا، تحتاج إلى تعديل بعض الأشكال في بعض الأوراق المحمية، في هذه الحالة، تحتاج إلى فتح هذه الأشكال.
سيقدم هذا المقال كيفية قفل وفتح الأشكال المحددة بالتفصيل.
حماية جميع الأشكال في ورقة عمل محددة
لحماية جميع الأشكال في ورقة العمل المحددة، استخدم الأسلوب Worksheet.Protect(type)، كما هو موضح في الشيفرة المثالية التالية.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook, FileFormatType,SaveFormat,ProtectionType | |
text = "This is a test"; | |
workbook = Workbook(); | |
worksheet = workbook.worksheets.get(0); | |
shape = worksheet.shapes.add_text_box(1, 0, 1, 0, 30, 100); | |
shape.text = text; | |
shape = worksheet.shapes.add_rectangle(5, 0, 1, 0, 30, 100); | |
shape.text = text; | |
shape = worksheet.shapes.add_button(9, 0, 1, 0, 30, 100); | |
shape.text = text; | |
shape = worksheet.shapes.add_oval(13, 0, 1, 0, 50, 100); | |
shape.text = text; | |
#Protect all shapes in a specified worksheet | |
shape.worksheet.protect(ProtectionType.OBJECTS);#Protects the entire worksheet. | |
#or shape.worksheet.protect(ProtectionType.All);//Protects all shapes in the specified worksheet. | |
#or worksheet.protect(ProtectionType.Objects);//Protects the entire worksheet. | |
#or worksheet.protect(ProtectionType.All);//Protects all shapes in the specified worksheet. | |
workbook.save(r"Locked.xlsx", SaveFormat.XLSX); |
فتح الأشكال المحددة في ورقة عمل محمية
لفتح شكل معين في ورقة العمل المحمية، استخدم shape.is_locked، كما هو موضح في الشيفرة المثالية التالية.
ملاحظة: shape.is_locked له معنى فقط عندما تكون ورقة العمل محمية.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook, FileFormatType,SaveFormat,ProtectionType | |
workbook = Workbook(r"Locked.xlsx") | |
#Get protected worksheet | |
worksheet = workbook.worksheets[0] | |
#Get the specified shape to be unlocked | |
shape = worksheet.shapes[0] | |
#Unlock the specified shape | |
if (not worksheet.protection.allow_editing_object and shape.is_locked): | |
shape.is_locked = False; | |
workbook.save(r"UnLocked.xlsx", SaveFormat.XLSX); |