Search for jobs related to Excel spreadsheet food macronutrients or hire on the world's largest freelancing marketplace with 15m+ jobs. It's free to sign up and bid on jobs.
One Excel workbook has several worksheets (default 3) so that users can choose to protect Excel workbook or specified worksheets in this workbook. Solutions in this guide focus on demonstrating how to protect Excel workbook and worksheet in C# and VB.NET with Spire.XLS for .NET.
Spire.XLS for .NET provides a Workbook.Protect(String) method of Workbook class to prevent other from opening Excel file without a correct password.
Effect as screenshot below:
Workbook class contains a WorksheetCollection property to enable users to access specified worksheet. After accessing this worksheet, users can invoke Protect method of XlsWorksheetBase class to protect.
There are two possibilities to protect worksheet.
With Password: Pass String password to Protect worksheet to protect worksheet with a password. After protecting, users cannot do any actions on this worksheet.
With Password and Options: Pass String password and SheetProtectionType options to protect worksheet with password and specified permissions.
The following table presents 18 sheet protection types.
None | Represents none flags. |
Object | Protects shapes. |
Scenarios | Protects scenarios. |
FormattingCells | Allows users to format any cells on a protected worksheet. |
FormattingColumns | Allows users to format any columns on a protected worksheet. |
FormattingRows | Allows users to format any rows on a protected worksheet. |
InsertingColumns | Allows users to insert columns on a protected worksheet. |
InsertingRows | Allows users to insert rows on a protected worksheet. |
InsertingHyperlinks | Allows users to insert hyperlinks on a protected worksheet. |
DeletingColumns | Allows users to delete columns on a protected worksheet. |
DeletingRows | Allows users to delete rows on a protected worksheet. |
LockedCells | Protects locked cells. |
Sorting | Allows users to sort on a protected worksheet. |
Filtering | Allows users to set filters on a protected worksheet. |
UsingPivotTable | Allows users to use pivot table reports on a protected worksheet. |
UnlockedCells | Protects users interface, but not macros. |
Contents | Represents all flags. |
All | Represents default protection. |
Code to protect worksheet with password:
for repositories and installers. Ubuntu 14+/Centos6+, 64-bit.Python: Versions 2.7, 3.6, 3.7, and 3.8.To use Navigator in, you must be able to reach these sites, so you may need to add them to a whitelist in your network’s firewall settings. Windows 8 or newer, 32-bit or 64-bit. for conda-forge and other channels on Anaconda Cloud (anaconda.org). macOS 10.13+, 64-bit. Install anaconda for mac docs.contiuum.
Effect as screenshot below:
Spire.XLS, specified designed for developers, enables to generate, write, edit and save Excel workbooks (Excel 97-2003, Excel 2007 and Excel 2010) in .NET, Silverlight and WPF with C# and VB.NET.