Şekilleri kilitle veya kilidi aç
Bazı durumlarda, istenmeyen durumlar tarafından yok edilmekten korumak için belirli çalışma sayfalarındaki tüm şekilleri korumanız gerekebilir. Bu durumda, belirtilen çalışma sayfasındaki tüm şekilleri kilitlemeniz gerekir.
Bazı durumlarda, belirli korumalı çalışma sayfalarındaki belirli şekilleri değiştirmeniz gerekebilir; bu durumda, bu şekillerin kilidini açmanız gerekir.
Bu makale, belirtilen şekilleri kilitleme ve kilidini açma konusunda detaylı bir şekilde tanıtacaktır.
Belirtilen çalışma sayfasındaki tüm şekilleri koruma altına al
Belirtilen çalışma sayfasındaki tüm şekilleri korumak için Worksheet.protect(int type) methodunu kullanın, aşağıdaki örnek kodda gösterildiği gibi.
String text = "This is a test"; | |
Workbook workbook = new Workbook(); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
Shape shape = worksheet.getShapes().addTextBox(1, 0, 1, 0, 30, 100); | |
shape.setText(text); | |
shape = worksheet.getShapes().addRectangle(5, 0, 1, 0, 30, 100); | |
shape.setText(text); | |
shape = worksheet.getShapes().addButton(9, 0, 1, 0, 30, 100); | |
shape.setText(text); | |
shape = worksheet.getShapes().addOval(13, 0, 1, 0, 50, 100); | |
shape.setText(text); | |
//Protect all shapes in a specified worksheet | |
shape.getWorksheet().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("Locked.xlsx", SaveFormat.XLSX); |
Korumalı bir çalışma sayfasındaki belirtilen şekillerin kilidini aç
Korumalı bir çalışma sayfasındaki belirtilen şekillerin kilidini açmak için shape.IsLocked ve shape.setLocked methodlarını aşağıdaki örnek kodda gösterildiği gibi kullanın.
Not: shape.IsLocked ve shape.setLocked yalnızca çalışma sayfası korumalı olduğunda anlamlıdır.
Workbook workbook = new Workbook("Locked.xlsx"); | |
//Get protected worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
//Get the specified shape to be unlocked | |
Shape shape = worksheet.getShapes().get("TextBox 1"); | |
//Unlock the specified shape | |
if (!worksheet.getProtection().getAllowEditingObject() && shape.isLocked()) | |
{ | |
shape.setLocked(false); | |
} | |
workbook.save("UnLocked.xlsx", SaveFormat.XLSX); |