Toolbar
Purpose
ZK Spreadsheet supports various toolbar buttons to perform actions.
Show toolbar
Use Spreadsheet.setShowToolbar to show toolbar.
Action Handler
The Spreadsheet use a default ActionHandler to perform toolbar button's action. Developer could customize ActionHandler by and set to spreadsheet by API Spreadsheet.setActionHandler or by library property org.zkoss.zss.ui.ActionHandler.class, refer to sample zk.xml
Each spreadsheet instance use it own ActionHandler. ActionHandler can't share across different spreadsheet instance.
Each toolbar's button represent a action, the ActionHandler process action when user click it.
For example, the paste toolbarbutton and menuitem represent Action.PASTE, deveoper could override
default behavior by override ActionHandler.doPaste
New Book
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doNewBook
@Override
public void doNewBook() {
getSpreadsheet().setSrc("/WEB-INF/excel/config/blank.xlsx");
}
Refer to sample code CustomizedActionHandler.java
Save Book
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doSaveBook
@Override
public void doSaveBook() {
Spreadsheet spreadsheet = getSpreadsheet();
if (spreadsheet.getBook() != null) {
final String filePath = Executions.getCurrent().getDesktop().getWebApp().getRealPath(spreadsheet.getSrc());
Exporter exporter = Exporters.getExporter("excel");
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(new File(filePath));
exporter.export(spreadsheet.getBook(), outputStream);
try {
Messagebox.show("Saved");
} catch (InterruptedException e) {
}
} catch (FileNotFoundException e) {
try {
Messagebox.show("Save excel failed");
} catch (InterruptedException e1) {
}
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
}
}
}
}
}
Refer to Export to Excel sample code CustomizedActionHandler.java
Export PDF
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doExportPDF
@Override
public void doExportPDF(Rect selection) {
Spreadsheet spreadsheet = getSpreadsheet();
if (spreadsheet.getBook() != null && validSelection(selection)) {
ExportPDFDialog dialog = new ExportPDFDialog(selection);
//omit
}
}
Refer to Export to PDF and sample code exportPDFDialog.zulCustomizedActionHandler.java
Paste Special
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doPasteSpecial
@Override
public void doPasteSpecial(Rect selection) {
Spreadsheet spreadsheet = getSpreadsheet();
if (spreadsheet.getBook() != null && validSelection(selection)) {
PasteSpecialDialog dialog = new PasteSpecialDialog(selection);
//omit
}
}
Refer to sample code pasteSpecialDialog.zul and CustomizedActionHandler.java
Custom Sort
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doCustomSort
@Override
public void doCustomSort(Rect selection) {
Spreadsheet spreadsheet = getSpreadsheet();
if (spreadsheet.getBook() != null && validSelection(selection)) {
CustomSortDialog dialog = new CustomSortDialog(selection);
//omit
}
}
Refer to sample code customSortDialog.zul and CustomizedActionHandler.java
Hyperlink
The default ActionHandler does nothing when user click the button, developer could override ActionHandler.doHyperlink
@Override
public void doHyperlink(Rect selection) {
Spreadsheet spreadsheet = getSpreadsheet();
if (spreadsheet.getBook() != null && validSelection(selection)) {
InsertHyperlinkDialog dialog = new InsertHyperlinkDialog(selection);
//omit
}
}
I18N
Each button/menuitem map to a key, developer could browser all I18 keys by Action.getLabelKeys
Here is partial keys for toolbar
Action | I18 Key |
---|---|
Paste | zss.paste |
Paste Formula | zss.pasteFormula |
Paste Value | zss.pasteValue |
Paste All Except Border | zss.pasteAllExceptBorder |
Paste Transpose | zss.pasteTranspose |
Paste Special | zss.pasteSpecial |
Merge And Center | zss.mergeAndCenter |
Merge Across | zss.mergeAcross |
Merge Cell | zss.mergeCell |
Unmerge Cell | zss.unmergeCell |
Insert Cell | zss.insertCell |
Shift Cell Right | zss.shiftCellRight |
Shift Cell Down | zss.shiftCellDown |
Insert Sheet Row | zss.insertSheetRow |
Insert Sheet Column | zss.insertSheetColumn |
Delete Cell | zss.deleteCell |
Shift Cell Left | zss.shiftCellLeft |
Shift Cell Up | zss.shiftCellUp |
Clear | zss.clear |
Clear Context | zss.clearContent |
Clear Style | zss.clearStyle |
Clear All | zss.clearAll |
sort | zss.sort |
Sort And Filter | zss.sortAndFilter |
Sort Ascending | zss.sortAscending |
Sort Descending | zss.sortDescending |
Custom Sort | zss.customSort |
Filter | zss.filter |
Clear Filter | zss.clearFilter |
Reapply Filter | zss.reapplyFilter |
Column Chart | zss.columnChart |
Column Chart 3D | zss.columnChart3D |
Line Chart | zss.lineChart |
Line Chart 3D | zss.lineChart3D |
Pie Chart | zss.pieChart |
Bar Chart | zss.barChart |
Bar Chart 3D | zss.barChart3D |
Scatter Chart | zss.scatterChart |
Doughnut Chart | zss.doughnutChart |
Hyperlink | zss.hyperlink |
Refer to sample i3-label.properties
ZUML
Here is a sample example ZUL file
<zk>
<window vflex="1" width="100%" apply="org.zkoss.zssessentials.config.ToolbarComposer">
<button id="toggleToolbar" label="Toggle toolbar"/>
<spreadsheet showToolbar="true"
id="ss" vflex="true" width="100%"
src="/WEB-INF/excel/config/ZSS-demo_sample.xlsx" maxcolumns="40" maxrows="200"
></spreadsheet>
</window>
</zk>
Composer
The composer use Spreadsheet.setShowToolbar to show or hide toolbar.
public void onClick$toggleToolbar() {
boolean isShowToolbar = spreadsheet.isShowToolbar();
spreadsheet.setShowToolbar(!isShowToolbar);
}
See the full source code for Composer here
Version History
Version | Date | Content |
---|---|---|
2.3.0 | April, 2012 | Toolbar |
All source code listed in this book is at Github.