Get or Set Value, Formula, or Formatted Text"
Line 4: | Line 4: | ||
===Purpose=== | ===Purpose=== | ||
− | ZK Spreadsheet use <javadoc method="getEditText()">org.zkoss.zss.model.Range</javadoc> to get cell's edit text, and <javadoc method="setEditText(java.lang.String)">org.zkoss.zss.model.Range</javadoc>to set cell's text as input by user. | + | ZK Spreadsheet use <javadoc directory="zss" method="getEditText()">org.zkoss.zss.model.Range</javadoc> to get cell's edit text, and <javadoc directory="zss" method="setEditText(java.lang.String)">org.zkoss.zss.model.Range</javadoc>to set cell's text as input by user. |
===ZUML=== | ===ZUML=== | ||
Line 43: | Line 43: | ||
====Cell Position==== | ====Cell Position==== | ||
− | First, we need to get the current cell's position. We can get row, column index from CellEvent, then use <javadoc method="getRowtitle(java.lang.String)">org.zkoss.zss.ui.Spreadsheet</javadoc> and <javadoc method="getColumntitle((java.lang.String)">org.zkoss.zss.ui.Spreadsheet</javadoc> to get current cell's title. | + | First, we need to get the current cell's position. We can get row, column index from CellEvent, then use <javadoc directory="zss" method="getRowtitle(java.lang.String)">org.zkoss.zss.ui.Spreadsheet</javadoc> and <javadoc directory="zss" method="getColumntitle((java.lang.String)">org.zkoss.zss.ui.Spreadsheet</javadoc> to get current cell's title. |
<source lang="java" high="4"> | <source lang="java" high="4"> | ||
Line 54: | Line 54: | ||
====Cell Value==== | ====Cell Value==== | ||
− | After we get cell's position, we can get cell's value from <javadoc method="getEditText()">org.zkoss.zss.model.Range</javadoc> | + | After we get cell's position, we can get cell's value from <javadoc directory="zss" method="getEditText()">org.zkoss.zss.model.Range</javadoc> |
<source lang="java" high="7"> | <source lang="java" high="7"> |
Revision as of 01:04, 20 December 2010
Purpose
ZK Spreadsheet use Range.getEditText() to get cell's edit text, and Range.setEditText(String)to set cell's text as input by user.
ZUML
<zk>
<div width="100%" height="100%" apply="demo.EditorComposer" >
<div height="3px"></div>
<combobox id="focusCombobox" mold="rounded" style="text-align:center;">
</combobox>
<textbox id="formulaEditor" cols="100"/>
<div height="3px"></div>
<spreadsheet id="spreadsheet" src="/demo_sample.xls"
maxrows="200"
maxcolumns="40"
width="100%"
height="450px"></spreadsheet>
</div>
</zk>
Composer
Current Cell Text
We can use onCellFocused event to get current focus cell and display cell's text
public void onCellFocused$spreadsheet(CellEvent event) {
int row = event.getRow();
int col = event.getColumn();
focusCombobox.setText(spreadsheet.getRowtitle(row) + spreadsheet.getColumntitle(col));
Sheet sheet = spreadsheet.getSelectedSheet();
currentCell = Utils.getCell(sheet, row, col);
currentRange = Ranges.range(sheet, row, col);
formulaEditor.setText(currentRange.getEditText());
}
Cell Position
First, we need to get the current cell's position. We can get row, column index from CellEvent, then use Spreadsheet.getRowtitle(String) and Spreadsheet.getColumntitle((String) to get current cell's title.
public void onCellFocused$spreadsheet(CellEvent event) {
int row = event.getRow();
int col = event.getColumn();
focusCombobox.setText(spreadsheet.getRowtitle(row) + spreadsheet.getColumntitle(col));
...
Cell Value
After we get cell's position, we can get cell's value from Range.getEditText()
public void onCellFocused$spreadsheet(CellEvent event) {
...
Sheet sheet = spreadsheet.getSelectedSheet();
currentCell = Utils.getCell(sheet, row, col);
currentRange = Ranges.range(sheet, row, col);
formulaEditor.setText(currentRange.getEditText());
}
Editor
For editor, we can use onOK event, which menus when user click Enter keyboard, set cell's value and make spreadsheet's focus to next cell
public void onOK$formulaEditor() {
currentRange.setEditText(formulaEditor.getText());
spreadsheet.focusTo(currentCell.getRowIndex() + 1, currentCell.getColumnIndex());
}
Second, we can also use onChange and onChanging event to get current editor's value and set cell's value
public void onChanging$formulaEditor(InputEvent event) {
if (currentCell.getCellType() != Cell.CELL_TYPE_FORMULA)
currentRange.setEditText(event.getValue());
}
public void onChange$formulaEditor() {
currentRange.setEditText(formulaEditor.getText());
}
View complete source of ZUML editor.zul
View complete source of composer EditorComposer.java
Version History
Version | Date | Content |
---|---|---|
All source code listed in this book is at Github.