Merge Cells or Split Merged Cells
From Documentation
This article is out of date, please refer to http://books.zkoss.org/wiki/ZK_Spreadsheet_Essentials for more up to date information.
Purpose
ZK Spreadsheet support merge cells and split merged cells.
Merge cells
Merge cell can cross rows, also known as vertical merge.
ZUML
<zk>
<div height="100%" width="100%" apply="org.zkoss.zssessentials.config.MergeCellComposer">
<div>
<button id="mergeCells" label="Merge Cells" mold="trendy"></button>
<button id="splitMergedCells" label="Split Merged Cells" mold="trendy"></button>
</div>
<spreadsheet id="spreadsheet" src="/WEB-INF/excel/config/merge.xlsx"
maxrows="200"
maxcolumns="40"
width="100%"
height="450px"></spreadsheet>
</div>
</zk>
Composer
Range to merge or split
Use CellSelectionEvent to get current range.
Spreadsheet spreadsheet;
int topRow;
int bottomRow;
int leftCol;
int rightCol;
public void onCellSelection$spreadsheet(CellSelectionEvent event) {
topRow = event.getTop();
bottomRow = event.getBottom();
leftCol = event.getLeft();
rightCol = event.getRight();
}
Merge Cells
Use Range.merge(Boolean)to merge cells. The boolean argument indicates whether to merge cells for each individual rows. true
to merge cells for each row while
false
indicates merge cells as a whole.
public void onClick$mergeCells() {
Ranges.range(spreadsheet.getSelectedSheet(),
topRow,
leftCol,
bottomRow,
rightCol).merge(false);
}
Split Merged Cells
public void onClick$splitMergedCells() {
Ranges.range(spreadsheet.getSelectedSheet(),
topRow,
leftCol,
bottomRow,
rightCol).unMerge();
}
View the complete source of ZUML mergeCells.zul
View the complete source of composer MergeCellComposer.java
Version History
Version
Date
Content
2.1.0
May, 2011
support vertical merge
All source code listed in this book is at Github.