-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I want block the edition of one specific cell. So the value can't be change by the final user.
I did use this code :
EditableCellStyle style = range.getCellStyleHelper().createCellStyle(range.getCellStyle()); style.setLocked(true); range.setCellStyle(style);
But it's not working ... And I don't know WHY ! No warning, no exception...
In fact any change on CellStyle don't apply... WHY ? My setCellValue that is make just after take effect...
And need a manual that is up to date... (Not some "this one is not updated, but you can look the new one that have nothing to say...")
Hello kolodz,
Did you try to protect sheet after set locked?
Here is a protect demo from zss essentials in ZSS 3.5.0 version:
protect.zul
<window hflex="1" vflex="1"
apply="org.zkoss.zss.essential.ProtectionComposer">
<hlayout hflex="1" vflex="1">
<spreadsheet id="ss" hflex="1" vflex="1" showFormulabar="true" showContextMenu="true"
showSheetbar="true" maxVisibleRows="100" maxVisibleColumns="40"
src="/WEB-INF/books/protection.xlsx" />
<vlayout width="300px" vflex="1">
<groupbox hflex="1" >
<caption label="Protection" />
<grid vflex="1" hflex="1">
<columns>
<column width="200px"/>
<column/>
</columns>
<rows>
<row>
Current Sheet Protection Status:
<label id="status" style="font-weight:bold"/>
</row>
<row spans="2" align="right">
<button id="toggleProtection" label="Toggle Protection"/>
</row>
<row>
Current Cell Locked Status:
<label id="lockStatus" style="font-weight:bold"/>
</row>
<row spans="2" align="right">
<button id="toggleLock" label="Toggle Lock"/>
</row>
</rows>
</grid>
</groupbox>
</vlayout>
</hlayout>
</window>
ProtectionComposer.java
package org.zkoss.zss.essential;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.Listen;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zss.api.Range;
import org.zkoss.zss.api.Ranges;
import org.zkoss.zss.api.model.CellStyle;
import org.zkoss.zss.api.model.EditableCellStyle;
import org.zkoss.zss.api.model.Sheet;
import org.zkoss.zss.ui.Spreadsheet;
import org.zkoss.zss.ui.event.CellSelectionEvent;
import org.zkoss.zss.ui.event.SheetSelectEvent;
import org.zkoss.zul.Label;
@SuppressWarnings("serial")
public class ProtectionComposer extends SelectorComposer<Component>{
@Wire
private Spreadsheet ss;
@Wire
private Label status;
@Wire
private Label lockStatus;
@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).unprotectSheet("mypass");
}else{
Ranges.range(selectedSheet).protectSheet("mypass",
true, //allowSelectingLockedCells
true, //allowSelectingUnlockedCells,
false, //allowFormattingCells
false, //allowFormattingColumns
false, //allowFormattingRows
false, //allowInsertColumns
false, //allowInsertRows
false, //allowInsertingHyperlinks
false, //allowDeletingColumns
false, //boolean allowDeletingRows
false, //allowSorting
false, //allowFiltering
false, //allowUsingPivotTables
false, //drawingObjects
false //boolean scenarios
);
}
updateSheetProtectionStatus(selectedSheet);
}
@Listen("onSheetSelect = #ss")
public void selectSheet(SheetSelectEvent event) {
updateSheetProtectionStatus(event.getSheet());
}
private void updateSheetProtectionStatus(Sheet sheet){
status.setValue(Boolean.toString(sheet.isProtected()));
}
@Listen("onClick = #toggleLock")
public void toggleLock(){
Range selection = Ranges.range(ss.getSelectedSheet(), ss.getSelection());
CellStyle oldStyle = selection.getCellStyle();
EditableCellStyle newStyle = selection.getCellStyleHelper().createCellStyle(oldStyle);
newStyle.setLocked(!oldStyle.isLocked());
selection.setCellStyle(newStyle);
updateCellLockedStatus(newStyle.isLocked());
}
@Listen("onCellSelection = #ss")
public void selectCells(CellSelectionEvent event) {
CellStyle style = Ranges.range(ss.getSelectedSheet(), ss.getSelection()).getCellStyle();
updateCellLockedStatus(style.isLocked());
}
private void updateCellLockedStatus(Boolean status){
lockStatus.setValue(status.toString());
}
}
Asked: 2014-07-16 13:07:09 +0800
Seen: 23 times
Last updated: Jul 17 '14
Some feedback about ZK SpreadSheet
Cannot add to Eclipse the ZK SPreadsheet jars
Zk Spreadsheet: Date in cells are displayed as GMT+0 while my locale is GMT+8
I want cancel the page part refresh ,how?
Spreadheet and pagination problem
Zk spreadsheet 2.0 beta3 - row copy/cut and paste not working
Zk spreadsheet - cell values changing automatically
how to make spreadsheet row un-editable & freeze???