Bloccare o sbloccare forme

Proteggere tutte le forme in un foglio di lavoro specificato

Per proteggere tutte le forme in un foglio di lavoro specificato, utilizzare il metodo Worksheet.Protect(ProtectionType), come mostrato nel seguente codice di esempio.

Aspose::Cells::Startup();
U16String text = u"This is a test";
Workbook 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(u"Locked.xlsx", SaveFormat::Xlsx);
Aspose::Cells::Cleanup();

Sbloccare forme specificate in un foglio di lavoro protetto

Per sbloccare una forma specificata in un foglio di lavoro protetto, utilizzare shape.IsLocked e shape.SetIsLocked, come mostrato nel seguente codice di esempio.

Nota: shape.IsLocked e shape.SetIsLocked sono significativi solo quando il foglio di lavoro è protetto.

Aspose::Cells::Startup();
Workbook workbook(u"Locked.xlsx");
//Get protected worksheet
Worksheet worksheet = workbook.GetWorksheets().Get(0);
//Get the specified shape to be unlocked
Shape shape = worksheet.GetShapes().Get(u"TextBox 1");
//Unlock the specified shape
if (!worksheet.GetProtection().GetAllowEditingObject() && shape.IsLocked())
{
shape.SetIsLocked(false);
}
workbook.Save(u"UnLocked.xlsx", SaveFormat::Xlsx);
Aspose::Cells::Cleanup();