Shift Cells"
From Documentation
m (correct highlight (via JWB)) |
|||
Line 3: | Line 3: | ||
− | Shift a range of cells can be performed by calling < | + | Shift a range of cells can be performed by calling <code>shift()</code> wit row and column offset: |
<source lang='java'> | <source lang='java'> | ||
range.shift(rowOffset, columnOffset) | range.shift(rowOffset, columnOffset) | ||
Line 9: | Line 9: | ||
You can also use | You can also use | ||
− | < | + | <code>CellOperationUtil.shift()</code> which checks protection for you. The first Range object is your source range to be shifted. The second argument is row offset. If it's positive, source range will be shifted down, otherwise it will be shifted up. The third argument is column offset. If it's positive, source range will be shifted right, otherwise it will be shifted left. |
Assume that we have selected a selected range of cells: | Assume that we have selected a selected range of cells: |
Latest revision as of 12:53, 19 January 2022
Shift a range of cells can be performed by calling shift()
wit row and column offset:
range.shift(rowOffset, columnOffset)
You can also use
CellOperationUtil.shift()
which checks protection for you. The first Range object is your source range to be shifted. The second argument is row offset. If it's positive, source range will be shifted down, otherwise it will be shifted up. The third argument is column offset. If it's positive, source range will be shifted right, otherwise it will be shifted left.
Assume that we have selected a selected range of cells:
We want to move the selected cells 3 columns to the right, we can write the below code to shift it:
Range range = Ranges.range(spreadsheet.getSelectedSheet(), "F6:F10");
//move 3 columns to the right
CellOperationUtil.shift(range, 0, 3);
The result will be like:
All source code listed in this book is at Github.