Delete Range"
From Documentation
m (Created page with '{{ZKSpreadsheetEssentialsPageHeader}} __TOC__ ZK Spreadsheet can use Range.delete to delete row or column. ==Scenario== User right click to open a menu and delete row or colum…') |
m (correct highlight (via JWB)) |
||
(15 intermediate revisions by 3 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 | + | ===Purpose=== |
− | + | ZK Spreadsheet can use <javadoc directory="zss" method="delete(java.lang.Integer)">org.zkoss.zss.model.Range</javadoc> to delete range, rows or columns. | |
− | |||
− | |||
− | ===ZUML | + | ===ZUML=== |
− | <source lang="xml" | + | <source lang="xml" highlight="4,10"> |
<zk> | <zk> | ||
<div height="100%" width="100%" apply="demo.DeleteRangeComposer"> | <div height="100%" width="100%" apply="demo.DeleteRangeComposer"> | ||
Line 28: | Line 31: | ||
</source> | </source> | ||
− | ===Open | + | ===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" | + | <source lang="java" highlight="7,8,9,10"> |
int rowIndex; | int rowIndex; | ||
int colIndex; | int colIndex; | ||
− | + | Worksheet currentSheet; | |
Spreadsheet spreadsheet; | Spreadsheet spreadsheet; | ||
Menupopup cellMenupopup; | Menupopup cellMenupopup; | ||
Line 44: | Line 48: | ||
</source> | </source> | ||
− | ===Shift | + | [[File:ZKSsEss_Spreadsheet_DeleteRange_Menu.png]] |
− | <source lang="java" | + | |
+ | ====Shift Cells Left==== | ||
+ | <source lang="java" highlight="3"> | ||
public void onClick$shiftCellLeft() { | public void onClick$shiftCellLeft() { | ||
Range rng = Ranges.range(currentSheet, rowIndex, colIndex); | Range rng = Ranges.range(currentSheet, rowIndex, colIndex); | ||
Line 52: | Line 58: | ||
</source> | </source> | ||
− | ===Shift | + | [[File:ZKSsEss_Spreadsheet_DeleteRange_ShiftLeft.png]] |
− | <source lang="java" | + | |
+ | ====Shift Cells Up==== | ||
+ | <source lang="java" highlight="3"> | ||
public void onClick$shiftCellUp() { | public void onClick$shiftCellUp() { | ||
final Range rng = Ranges.range(currentSheet, rowIndex, colIndex); | final Range rng = Ranges.range(currentSheet, rowIndex, colIndex); | ||
Line 59: | Line 67: | ||
} | } | ||
</source> | </source> | ||
+ | |||
+ | [[File:ZKSsEss_Spreadsheet_DeleteRange_ShiftUp.png]] | ||
+ | |||
+ | ====Delete Entire Row==== | ||
+ | <source lang="java" highlight="5"> | ||
+ | public void onClick$deleteEntireRow() { | ||
+ | Row row = currentSheet.getRow(rowIndex); | ||
+ | int lCol = row.getFirstCellNum(); | ||
+ | int rCol = row.getLastCellNum(); | ||
+ | Ranges.range(currentSheet, rowIndex, lCol, rowIndex, rCol).delete(Range.SHIFT_UP); | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | [[File:ZKSsEss_Spreadsheet_DeleteRange_Row.png]] | ||
+ | |||
+ | ====Delete Entire Column==== | ||
+ | <source lang="java" highlight="4"> | ||
+ | public void onClick$deleteEntireColumn() { | ||
+ | int tRow = currentSheet.getFirstRowNum(); | ||
+ | int bRow = currentSheet.getPhysicalNumberOfRows(); | ||
+ | Ranges.range(currentSheet, tRow, colIndex, bRow, colIndex).delete(Range.SHIFT_LEFT); | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | [[File:ZKSsEss_Spreadsheet_DeleteRange_Column.png]] | ||
=Version History= | =Version History= |
Latest revision as of 12:55, 19 January 2022
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 can use Range.delete(Integer) to delete range, rows or columns.
ZUML
<zk>
<div height="100%" width="100%" apply="demo.DeleteRangeComposer">
<div height="3px"></div>
<menupopup id="cellMenupopup">
<menuitem id="shiftCellLeft" label="Shift cells left"></menuitem>
<menuitem id="shiftCellUp" label="Shift cells up"/>
<menuitem id="deleteEntireRow" label="Entire row" />
<menuitem id="deleteEntireColumn" 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());
}
Shift Cells Left
public void onClick$shiftCellLeft() {
Range rng = Ranges.range(currentSheet, rowIndex, colIndex);
rng.delete(Range.SHIFT_LEFT);
}
Shift Cells Up
public void onClick$shiftCellUp() {
final Range rng = Ranges.range(currentSheet, rowIndex, colIndex);
rng.delete(Range.SHIFT_UP);
}
Delete Entire Row
public void onClick$deleteEntireRow() {
Row row = currentSheet.getRow(rowIndex);
int lCol = row.getFirstCellNum();
int rCol = row.getLastCellNum();
Ranges.range(currentSheet, rowIndex, lCol, rowIndex, rCol).delete(Range.SHIFT_UP);
}
Delete Entire Column
public void onClick$deleteEntireColumn() {
int tRow = currentSheet.getFirstRowNum();
int bRow = currentSheet.getPhysicalNumberOfRows();
Ranges.range(currentSheet, tRow, colIndex, bRow, colIndex).delete(Range.SHIFT_LEFT);
}
Version History
Version | Date | Content |
---|---|---|
All source code listed in this book is at Github.