Bloquear o desbloquear formas

Proteger todas las formas en una hoja de cálculo especificada

Para proteger todas las formas en una hoja de cálculo específica, use el método Worksheet.Protect(ProtectionType), como se muestra en el siguiente código de muestra.

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();

Desbloquear formas especificadas en una hoja de cálculo protegida

Para desbloquear una forma específica en una hoja de cálculo protegida, use shape.IsLocked y shape.SetIsLocked, como se muestra en el siguiente código de muestra.

Nota: shape.IsLocked y shape.SetIsLocked son significativos solo cuando la hoja de cálculo está protegida.

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();