Insert Range"

From Documentation
m (Created page with '{{ZKSpreadsheetEssentialsPageHeader}} __TOC__ ZK Spreadsheet can use Range.insert to inser row or column. ==Scenario== User right click to open a menu and inert row or column.…')
 
m (correct highlight (via JWB))
 
(14 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{ZKSpreadsheetEssentialsPageHeader}}
 
{{ZKSpreadsheetEssentialsPageHeader}}
 +
 +
 +
{{Deprecated|url=http://books.zkoss.org/wiki/ZK_Spreadsheet_Essentials}}
 +
 +
  
 
__TOC__
 
__TOC__
  
ZK Spreadsheet can use Range.insert to inser row or column.
+
===Purpose===
 +
ZK Spreadsheet uses <javadoc directory="zss" method="insert (java.lang.Integer, java.lang.Integer)">org.zkoss.zss.model.Range</javadoc> to insert cell, row or column.
  
==Scenario==
+
===ZUML===
User right click to open a menu and inert row or column.
+
<source lang="xml" highlight="4,10">
 
 
===ZUML Example===
 
<source lang="xml" high="3,4">
 
 
<zk>
 
<zk>
 
<div height="100%" width="100%" apply="demo.InsertRangeComposer">
 
<div height="100%" width="100%" apply="demo.InsertRangeComposer">
Line 28: Line 31:
 
</source>
 
</source>
  
===Open menu===
+
===Composer===
 +
====Open menu====
 
We can use onCellRightClick to get the current mouse position and open popup.
 
We can use onCellRightClick to get the current mouse position and open popup.
<source lang="java" high="7,8,910">
+
<source lang="java" highlight="7,8,9,10">
 
int rowIndex;
 
int rowIndex;
 
int colIndex;
 
int colIndex;
Sheet currentSheet;
+
Worksheet currentSheet;
 
Spreadsheet spreadsheet;
 
Spreadsheet spreadsheet;
 
Menupopup cellMenupopup;
 
Menupopup cellMenupopup;
Line 44: Line 48:
 
</source>
 
</source>
  
===Shift cells right===
+
[[File:ZKSsEss_Spreadsheet_InsertRange_Menu.png]]
<source lang="java" high="3">
+
 
 +
====Shift cells right====
 +
<source lang="java" highlight="4">
 
Menuitem shiftCellRight;
 
Menuitem shiftCellRight;
 
public void onClick$shiftCellRight() {
 
public void onClick$shiftCellRight() {
Line 53: Line 59:
 
</source>
 
</source>
  
===Shift cells down===
+
[[File:ZKSsEss_Spreadsheet_InsertRange_ShiftRight.png]]
<source lang="java" high="3">
+
 
 +
====Shift cells down====
 +
<source lang="java" highlight="3">
 
public void onClick$shiftCellDown() {
 
public void onClick$shiftCellDown() {
 
final Range rng = Ranges.range(currentSheet, rowIndex, colIndex);
 
final Range rng = Ranges.range(currentSheet, rowIndex, colIndex);
Line 61: Line 69:
 
</source>
 
</source>
  
===Insert entire row===
+
[[File:ZKSsEss_Spreadsheet_InsertRange_ShiftDown.png]]
<source lang="java" high="7">
+
 
 +
====Insert entire row====
 +
<source lang="java" highlight="7">
 
public void onClick$insertEntireRow() {
 
public void onClick$insertEntireRow() {
 
Row row = currentSheet.getRow(rowIndex);
 
Row row = currentSheet.getRow(rowIndex);
 
int lCol = row.getFirstCellNum();
 
int lCol = row.getFirstCellNum();
 
int rCol  = row.getLastCellNum();
 
int rCol  = row.getLastCellNum();
for(int colIdx = lCol; colIdx < rCol; colIdx++) {
+
Ranges.range(currentSheet, rowIndex, lCol, rowIndex, rCol).insert(Range.SHIFT_DOWN, Range.FORMAT_LEFTABOVE);
final Range rng = Ranges.range(currentSheet, rowIndex, colIdx);
 
rng.insert(Range.SHIFT_DOWN, Range.FORMAT_LEFTABOVE);
 
}
 
 
}
 
}
 
</source>
 
</source>
  
===Insert entire column===
+
[[File:ZKSsEss_Spreadsheet_InsertRange_Row.png]]
<source lang="java" high="6">
+
 
 +
====Insert entire column====
 +
<source lang="java" highlight="6">
 
public void onClick$insertEntireColumn() {
 
public void onClick$insertEntireColumn() {
 
int tRow = currentSheet.getFirstRowNum();
 
int tRow = currentSheet.getFirstRowNum();
 
int bRow = currentSheet.getPhysicalNumberOfRows();
 
int bRow = currentSheet.getPhysicalNumberOfRows();
for (int rowIdx = tRow; rowIdx < bRow; rowIdx++) {
+
Ranges.range(currentSheet, tRow, colIndex, bRow, colIndex).insert(Range.SHIFT_RIGHT, Range.FORMAT_RIGHTBELOW);
final Range rng = Ranges.range(currentSheet, rowIdx, colIndex);
 
rng.insert(Range.SHIFT_RIGHT, Range.FORMAT_RIGHTBELOW);
 
}
 
 
}
 
}
 
</source>
 
</source>
 +
 +
[[File:ZKSsEss_Spreadsheet_InsertRange_Column.png]]
 +
 +
View the complete source of ZUML [https://code.google.com/p/zkbooks/source/browse/trunk/zssessentials/examples/WebContent/config/insertRange.zul insertRange.zul]
 +
 +
View the complete source of composer [https://code.google.com/p/zkbooks/source/browse/trunk/zssessentials/examples/src/org/zkoss/zssessentials/config/InsertRangeComposer.java InsertRangeComposer.java]
  
 
=Version History=
 
=Version History=

Latest revision as of 12:55, 19 January 2022



Stop.png 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 uses Range.insert (Integer, Integer) to insert cell, row or column.

ZUML

<zk>
<div height="100%" width="100%" apply="demo.InsertRangeComposer">
	<div height="3px"></div>
	<menupopup id="cellMenupopup">
		<menuitem id="shiftCellRight" label="Shift cells right"></menuitem>
		<menuitem id="shiftCellDown" label="Shift cells down"/>
		<menuitem id="insertEntireRow" label="Entire row" />
		<menuitem id="insertEntireColumn" label="Entire column" />
	</menupopup>
	<spreadsheet id="spreadsheet" src="/demo_sample.xls"	
			maxrows="200" 
			maxcolumns="40"
			width="100%"
			height="450px"></spreadsheet>
</div>
</zk>

Composer

Open menu

We can use onCellRightClick to get the current mouse position and open popup.

int rowIndex;
int colIndex;
Worksheet currentSheet;
Spreadsheet spreadsheet;
Menupopup cellMenupopup;
public void onCellRightClick$spreadsheet(CellMouseEvent event) {
	rowIndex = event.getRow();
	colIndex = event.getColumn();
	currentSheet = event.getSheet();
	cellMenupopup.open(event.getPageX(), event.getPageY());
}

ZKSsEss Spreadsheet InsertRange Menu.png

Shift cells right

Menuitem shiftCellRight;
public void onClick$shiftCellRight() {
	Range rng = Ranges.range(currentSheet, rowIndex, colIndex);
	rng.insert(Range.SHIFT_RIGHT, Range.FORMAT_RIGHTBELOW);
}

ZKSsEss Spreadsheet InsertRange ShiftRight.png

Shift cells down

public void onClick$shiftCellDown() {
	final Range rng = Ranges.range(currentSheet, rowIndex, colIndex);
	rng.insert(Range.SHIFT_DOWN, Range.FORMAT_LEFTABOVE);
}

ZKSsEss Spreadsheet InsertRange ShiftDown.png

Insert entire row

public void onClick$insertEntireRow() {
	Row row = currentSheet.getRow(rowIndex);
	int lCol = row.getFirstCellNum();
	int rCol  = row.getLastCellNum();
	Ranges.range(currentSheet, rowIndex, lCol, rowIndex, rCol).insert(Range.SHIFT_DOWN, Range.FORMAT_LEFTABOVE);
}

ZKSsEss Spreadsheet InsertRange Row.png

Insert entire column

public void onClick$insertEntireColumn() {
	int tRow = currentSheet.getFirstRowNum();
	int bRow = currentSheet.getPhysicalNumberOfRows();
	Ranges.range(currentSheet, tRow, colIndex, bRow, colIndex).insert(Range.SHIFT_RIGHT, Range.FORMAT_RIGHTBELOW);
}

ZKSsEss Spreadsheet InsertRange Column.png

View the complete source of ZUML insertRange.zul

View the complete source of composer InsertRangeComposer.java

Version History

Last Update : 2022/01/19


Version Date Content
     


All source code listed in this book is at Github.


Last Update : 2022/01/19

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