Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Spreadsheet .NET
>
Tutorial
> Protect Worksheet
The following example shows you how to protect/lock a worksheet.
C# example
using System; using Independentsoft.Office; using Independentsoft.Office.Spreadsheet; namespace Sample { class Program { static void Main(string[] args) { Worksheet sheet1 = new Worksheet(); sheet1["A1"] = new Cell(100); SheetProtection protection = new SheetProtection(); protection.SheetLocked = true; protection.ObjectsLocked = true; protection.ScenariosLocked = true; protection.Password = "test"; sheet1.SheetProtection = protection; Workbook book = new Workbook(); book.Sheets.Add(sheet1); book.Save("c:\\test\\output.xlsx", true); } } }
VB example
Imports System Imports Independentsoft.Office Imports Independentsoft.Office.Spreadsheet Module Module1 Sub Main(ByVal args As String()) Dim sheet1 As New Worksheet() sheet1("A1") = New Cell(100) Dim protection As New SheetProtection() protection.SheetLocked = True protection.ObjectsLocked = True protection.ScenariosLocked = True protection.Password = "test" sheet1.SheetProtection = protection Dim book As New Workbook() book.Sheets.Add(sheet1) book.Save("c:\test\output.xlsx", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*