Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JSpreadsheet
>
Tutorial
> Protect Worksheet
The following example shows you how to protect/lock a worksheet.
import com.independentsoft.office.spreadsheet.Cell; import com.independentsoft.office.spreadsheet.SheetProtection; import com.independentsoft.office.spreadsheet.Workbook; import com.independentsoft.office.spreadsheet.Worksheet; public class Example { public static void main(String[] args) { try { Worksheet sheet1 = new Worksheet(); sheet1.set("A1",new Cell(100)); SheetProtection protection = new SheetProtection(); protection.setSheetLocked(true); protection.setObjectsLocked(true); protection.setScenariosLocked(true); protection.setPassword("test"); sheet1.setSheetProtection(protection); Workbook book = new Workbook(); book.getSheets().add(sheet1); book.save("c:\\test\\output.xlsx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*