Merge Cells or Split Merged Cells

From Documentation




Purpose

ZK Spreadsheet support merge cells and split merged cells.

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 complete source of ZUML mergeCells.zul

View complete source of composer MergeCellComposer.java

Version History

Last Update : 2011/05/24


Version Date Content
     


All source code listed in this book is at Github.


Last Update : 2011/05/24

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.