Advanced Protection Settings since Excel XP
Introduction
These protection settings restrict or allow users to:
- Delete rows or columns.
- Edit contents, objects or scenarios.
- Format cells, rows or columns.
- Insert rows, columns or hyperlinks.
- Select locked or unlocked cells.
- Use pivot tables and much more.
Aspose.Cells supports all the advanced protection settings offered by Excel XP or later versions.
Advanced Protection Settings Using Excel XP and Later Versions
To view the protection settings available in Excel XP:
- From the Tools menu, select Protection followed by Protect Sheet. A dialog will be displayed.
To view the protection settings available in Excel 2016
- From the File menu, select Protect Workbook followed by Protect Current Sheet.
- Select the Protect Sheet in the Review menu.
Following the steps mention above will show a dialog where you can allow or restrict worksheets features or apply a password to the worksheet.
Advanced Protection Settings Using Aspose.Cells
Aspose.Cells supports all of the advanced protection settings.
Aspose.Cells provides a class, Workbook, that represents a Microsoft Excel file. The Workbook class contains a Worksheets collection that allows access to each worksheet in the Excel file. A worksheet is represented by the Worksheet class.
The Worksheet class provides the Protection property that is used to apply these advanced protection settings. The Protection property is in fact an object of the Protection class that encapsulates several Boolean properties for disabling or enabling restrictions.
Below is a small example application. It opens an Excel file and uses most of the advanced protection settings supported by Excel XP and later versions.
Cell Locking Issue
If you want to restrict users from editing cells the cells must be locked before any protection settings are applied. Otherwise, the cells can be edited even if the worksheet is protected. In Microsoft Excel XP, cells can be locked through the following dialog:
Dialog to lock cells in Excel XP |
---|
It is possible to lock cells using the Aspose.Cells API too. Each cell can get Style formatting that contains a Boolean property, IsLocked. Set the IsLocked property to true or false to lock or unlock the cell.