Protection"

From Documentation
Line 47: Line 47:
 
* Line 21: Enable protection of the selected sheet.
 
* Line 21: Enable protection of the selected sheet.
  
= Unlock a Cell=
+
== Unlock Specific Area of a Protected Sheet ==
Spreadsheet supports unlock cells of a protected sheet configured in Excel.
+
When you protect a sheet in Excel, all cells are locked and cannot be edited by default. To enable some cells to be edited while leaving other cells locked, you can unlock the cells before you protect the worksheet.
 +
<ref>Steps to unlock cells in Excel 2007: select one or more cells first, right click on selected cells, select "Format Cells...", select "Protection" tab, uncheck "Locked" item. After this, the cell is still editable when its sheet is protection enabled.</ref>
  
describe how to unlock a cell in Excel.
+
Spreadsheet supports unlocked cells of a protected sheet configured in Excel. You can still edit the unlocked cells when loading it to Spreadsheet. The screenshot below is a sheet with B2 unlocked.
  
right click a cell, select "Format Cells...", select "Protection" tab, uncheck "Locked" item.
+
 
 +
 
 +
 
 +
<references/>

Revision as of 06:17, 26 September 2013

Protect a Sheet

If you enable "Protect Sheet" for a sheet in Excel (e.g. click Zss-essentials-protection-excel-icon.png of menu "Review" in Excel 2007), Spreadsheet can read the setting and prevent you from editing the protected sheet. Spreadsheet's API also allow you to enable / disable protection and get protection status of a sheet. Let's use a simple example to demonstrate the usage:

Zss-essentials-protection.png

The screenshot above is a simple application. There is a label on the right showing current sheet's protection status. The true means the sheet is under protection and cannot be edited. The "Toggle Protection" button can toggle protection status of current selected sheet.


The controller's source code of above application:

public class ProtectionComposer extends SelectorComposer<Component>{
	
	@Wire
	private Spreadsheet ss;
	@Wire
	private Label status;

	
	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		updateSheetProtectionStatus(ss.getSelectedSheet());
	}
	
	@Listen("onClick = #toggleProtection")
	public void toggleProtection(){
		Sheet selectedSheet = ss.getSelectedSheet();
		if (selectedSheet.isProtected()){
			Ranges.range(selectedSheet).protectSheet(null);
		}else{
			Ranges.range(selectedSheet).protectSheet("password");
		}
		updateSheetProtectionStatus(selectedSheet);
	}
	
	@Listen("onSheetSelect = #ss")
	public void selectSheet(SheetSelectEvent event) {
		updateSheetProtectionStatus(event.getSheet());
	}
	
	private void updateSheetProtectionStatus(Sheet sheet){
		status.setValue(Boolean.toString(sheet.isProtected()));
	}
}
  • Line 18: Get protection status of the selected sheet.
  • Line 19: Disable protection of the selected sheet.
  • Line 21: Enable protection of the selected sheet.

Unlock Specific Area of a Protected Sheet

When you protect a sheet in Excel, all cells are locked and cannot be edited by default. To enable some cells to be edited while leaving other cells locked, you can unlock the cells before you protect the worksheet. [1]

Spreadsheet supports unlocked cells of a protected sheet configured in Excel. You can still edit the unlocked cells when loading it to Spreadsheet. The screenshot below is a sheet with B2 unlocked.



  1. Steps to unlock cells in Excel 2007: select one or more cells first, right click on selected cells, select "Format Cells...", select "Protection" tab, uncheck "Locked" item. After this, the cell is still editable when its sheet is protection enabled.