Aspose::Cells::Worksheet::Protect method

Worksheet::Protect(ProtectionType) method

Protects worksheet.

void Aspose::Cells::Worksheet::Protect(ProtectionType type)
ParameterTypeDescription
typeProtectionTypeProtection type.

Remarks

This method protects worksheet without password. It can protect worksheet in all versions of Excel file.

See Also

Worksheet::Protect(ProtectionType, const U16String&, const U16String&) method

Protects worksheet.

void Aspose::Cells::Worksheet::Protect(ProtectionType type, const U16String &password, const U16String &oldPassword)
ParameterTypeDescription
typeProtectionTypeProtection type.
passwordconst U16String&Password.
oldPasswordconst U16String&If the worksheet is already protected by a password, please supply the old password. Otherwise, you can set a null value or blank string to this parameter.

Remarks

This method can protect worksheet in all versions of Excel file.

Examples

Aspose::Cells::Startup();
//Instantiating a Workbook object
Workbook excel(u"template.xlsx");
//Accessing the first worksheet in the Excel file
Worksheet worksheet = excel.GetWorksheets().Get(0);
//Protecting the worksheet with a password
U16String val_1 = u"newPwd";
U16String val_2 = u"oldPwd";
worksheet.Protect(ProtectionType::All, val_1, val_2);
//Saving the modified Excel file in default (that is Excel 20003) format
excel.Save(u"output.xls");
Aspose::Cells::Cleanup();

See Also

Worksheet::Protect(ProtectionType, const char16_t*, const char16_t*) method

Protects worksheet.

void Aspose::Cells::Worksheet::Protect(ProtectionType type, const char16_t *password, const char16_t *oldPassword)
ParameterTypeDescription
typeProtectionTypeProtection type.
passwordconst char16_t*Password.
oldPasswordconst char16_t*If the worksheet is already protected by a password, please supply the old password. Otherwise, you can set a null value or blank string to this parameter.

Remarks

This method can protect worksheet in all versions of Excel file.

Examples

Aspose::Cells::Startup();
//Instantiating a Workbook object
Workbook excel(u"template.xlsx");
//Accessing the first worksheet in the Excel file
Worksheet worksheet = excel.GetWorksheets().Get(0);
//Protecting the worksheet with a password
worksheet.Protect(ProtectionType::All, u"aspose", nullptr);
//Saving the modified Excel file in default (that is Excel 20003) format
excel.Save(u"output.xls");

Aspose::Cells::Cleanup();

See Also