Get or Set Value, Formula, or Formatted Text"
From Documentation
m (Created page with '{{ZKSpreadsheetEssentialsPageHeader}} __TOC__ {{ZKSpreadsheetEssentialsPageFooter}}') |
m |
||
Line 2: | Line 2: | ||
__TOC__ | __TOC__ | ||
+ | |||
+ | ZK Spreadsheet can use Range.setEditText(text) to set cell's text as input by user. | ||
+ | |||
+ | ==Purpose== | ||
+ | Implement a formula editor to allow user input text, formula etc. | ||
+ | For this function, we can use a Combobox to show the current cell, and use Textbox as a editor | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <combobox id="focusCombobox" mold="rounded" style="text-align:center;"></combobox> | ||
+ | <textbox id="formulaEditor" cols="100"/> | ||
+ | <spreadsheet id="spreadsheet" src="/demo_sample.xls" | ||
+ | maxrows="200" | ||
+ | maxcolumns="40" | ||
+ | width="100%" | ||
+ | height="450px"></spreadsheet> | ||
+ | </source> | ||
+ | |||
+ | ==onCellFocused== | ||
+ | ===Cell position=== | ||
+ | First, we need to get the current cell's position. We can get row, column index from CellEvent, then use Spreadsheet.getRowtitle() and Spreadsheet.getColumntitle() to get current cell's title. | ||
+ | |||
+ | <source lang="java" > | ||
+ | public void onCellFocused$spreadsheet(CellEvent event) { | ||
+ | int row = event.getRow(); | ||
+ | int col = event.getColumn(); | ||
+ | focusCombobox.setText(spreadsheet.getRowtitle(row) + spreadsheet.getColumntitle(col)); | ||
+ | ... | ||
+ | </source> | ||
+ | |||
+ | ===Cell value=== | ||
+ | After we get cell's position, we can get cell's value from Range.getEditText() | ||
+ | |||
+ | <source lang="java" > | ||
+ | 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()); | ||
+ | } | ||
+ | </source> | ||
{{ZKSpreadsheetEssentialsPageFooter}} | {{ZKSpreadsheetEssentialsPageFooter}} |
Revision as of 02:33, 18 November 2010
ZK Spreadsheet can use Range.setEditText(text) to set cell's text as input by user.
Purpose
Implement a formula editor to allow user input text, formula etc. For this function, we can use a Combobox to show the current cell, and use Textbox as a editor
<combobox id="focusCombobox" mold="rounded" style="text-align:center;"></combobox>
<textbox id="formulaEditor" cols="100"/>
<spreadsheet id="spreadsheet" src="/demo_sample.xls"
maxrows="200"
maxcolumns="40"
width="100%"
height="450px"></spreadsheet>
onCellFocused
Cell position
First, we need to get the current cell's position. We can get row, column index from CellEvent, then use Spreadsheet.getRowtitle() and Spreadsheet.getColumntitle() 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());
}
All source code listed in this book is at Github.