Lås eller lås upp figurer

Skydda alla figurer i ett angivet arbetsblad

För att skydda alla former i ett angivet kalkylblad, använd metoden Worksheet.Protect(ProtectionType) enligt följande exempelkod.

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

Lås upp angivna figurer i ett skyddat arbetsblad

För att låsa upp en angiven form i ett skyddat kalkylblad, använd shape.IsLocked och shape.SetIsLocked enligt följande exempelkod.

Observera: shape.IsLocked och shape.SetIsLocked har endast betydelse när kalkylarket är skyddat.

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