Package io.keikai.api
Class CellOperationUtil
java.lang.Object
io.keikai.api.CellOperationUtil
The utility to help UI to deal with user's cell operation of a
Range.
This utility is the default implementation for handling user operations for cells, it is also the example for calling Range APIs- Since:
- 3.0.0
- Author:
- dennis
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for help apply cell stylestatic interfaceInterface for help apply whole row,column style -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplyAlignment(Range range, CellStyle.Alignment alignment) Apply alignment to cells in the rangestatic voidapplyBackColor(Range range, String htmlColor) Apply back-color to cells in the rangestatic voidapplyBorder(Range range, Range.ApplyBorderType applyType, CellStyle.BorderType borderType, String htmlColor) Apply border to cells in the rangestatic voidapplyCellStyle(Range range, CellOperationUtil.CellStyleApplier applyer) Apply style according to the cell style applierstatic voidapplyDataFormat(Range range, String format) Apply data-format to cells in the rangestatic voidapplyFillColor(Range range, String htmlColor) Apply fill-color to cells in the rangestatic voidapplyFontBoldweight(Range range, Font.Boldweight boldweight) Apply font bold-weight to cells in the rangestatic voidapplyFontColor(Range range, String htmlColor) Apply font color to cells in the rangestatic voidapplyFontHeightPoints(Range range, int fontHeightPoints) Apply font height to cells in the range, it will also enlarge the row height if row height is smaller than font heightstatic voidapplyFontItalic(Range range, boolean italic) Apply font italic to cells in the rangestatic voidapplyFontName(Range range, String fontName) Apply font to cells in the rangestatic voidapplyFontStrikeout(Range range, boolean strikeout) Apply font strike-out to cells in the rangestatic voidapplyFontTypeOffset(Range range, Font.TypeOffset offset) Apply font typeOffset to cells in the rangestatic voidapplyFontUnderline(Range range, Font.Underline underline) Apply font underline to cells in the rangestatic voidapplyHyperlink(Range range, Hyperlink.HyperlinkType type, String address, String label) static voidapplyIndentionOffset(Range range, int offset) Apply indention to cells in the rangestatic voidapplyLocked(Range range, boolean locked) Apply the locked status only to cells in the rangestatic voidapplyRotation(Range range, int rotation) Apply alignment to cells in the rangestatic voidapplyVerticalAlignment(Range range, CellStyle.VerticalAlignment alignment) Apply vertical-alignment to cells in the rangestatic voidapplyWrapText(Range range, boolean wraptext) Apply text-warp to cells in the rangestatic voidautoFill(Range src, Range dest, Range.AutoFillType type) Fills data from source range to destination range automatically upon auto fill typestatic voidClear allstatic voidclearContents(Range range) Clear contentsstatic voidclearStyles(Range range) Clear stylestatic RangeCuts data and style from src to destinationstatic voiddelete(Range range, Range.DeleteShift shift) Delete cells of the range.static voiddeleteColumn(Range range) Delete columns to the range.static voidDelete rows of the range.static voidfitFontHeightPoints(Range range) Detect the highest words in each row.getAligmentApplier(CellStyle.Alignment alignment) static intgetAutoFitHeight(Sheet sheet, int row, int col) Calculate the autoFit cell height according its data size.getBackColorApplier(Color color) getDataFormatApplier(String format) getFillColorApplier(Color color) getFontBoldweightApplier(Font.Boldweight boldweight) getFontColorApplier(Color color) getFontHeightPointsApplier(int fontHeightPoints) getFontItalicApplier(boolean italic) getFontNameApplier(String fontName) getFontStrikeoutApplier(boolean strikeout) getFontUnderlineApplier(Font.Underline underline) getIndentionApplier(int offset) getRichTextFontBoldweightApplier(Font.Boldweight boldweight) getRichTextFontColorApplier(Color color) getRichTextFontHeightPointsApplier(int heightPoints) getRichTextFontItalicApplier(boolean italic) getRichTextFontNameApplier(String fontName) getRichTextFontStrikeoutApplier(boolean strikeout) getRichTextFontUnderlineApplier(Font.Underline underline) getRotationApplier(short rotation) getWrapTextApplier(boolean wraptext) static voidHide the range.static voidinsert(Range range, Range.InsertShift shift, Range.InsertCopyOrigin copyOrigin) Insert cells to the range.static voidinsertColumn(Range range) Insert columns to the range.static voidInsert rows to the range.static voidmerge the rangestatic RangePaste data and style from src to destinationstatic RangepasteAllExceptBorder(Range src, Range dest) Paste all (except border) from src to destinationstatic RangepasteFormula(Range src, Range dest) Paste formula only from src to destinationstatic RangepasteSpecial(Range src, Range dest, Range.PasteType pasteType, Range.PasteOperation pasteOperation, boolean skipBlank, boolean transpose) Paste according the argument from src to destinationstatic RangepasteTranspose(Range src, Range dest) Paste and transpose from src to destinationstatic RangepasteValue(Range src, Range dest) Paste value only from src to destinationstatic voidsetColumnWidth(Range range, int widthPx) Sets the column width.static voidsetRowHeight(Range range, int heightPx) Sets the row height and make it as custom modifiedstatic voidsetRowHeight(Range range, int heightPx, boolean isCustom) Sets the row height and provide a custom flag, a custom flag to indicate this height was set by user or system.static voidShifts/moves cells with a offset row and columnstatic voidSort rangestatic voidsort(Range range, Range index1, boolean desc1, Range.SortDataOption dataOption1, Range index2, boolean desc2, Range.SortDataOption dataOption2, Range index3, boolean desc3, Range.SortDataOption dataOption3, boolean header, boolean matchCase, boolean sortByRows) Sort rangestatic voidtoggleMergeCenter(Range range) Toggle merge/unmerge of the range, if merging it will also set alignment to centerstatic voidUnhide the range.static voidUnmerge the range
-
Constructor Details
-
CellOperationUtil
public CellOperationUtil()
-
-
Method Details
-
cut
Cuts data and style from src to destination- Parameters:
src- source rangedest- destination range- Returns:
- a Range contains the final pasted range. paste to a protected sheet will always cause paste return null.
-
paste
Paste data and style from src to destination- Parameters:
src- source rangedest- destination range- Returns:
- a Range contains the final pasted range. paste to a protected sheet will always cause paste return null.
-
pasteFormula
Paste formula only from src to destination- Parameters:
src- source rangedest- destination range- Returns:
- a Range contains the final pasted range. paste to a protected sheet will always cause paste return null.
-
pasteValue
Paste value only from src to destination- Parameters:
src- source rangedest- destination range- Returns:
- a Range contains the final pasted range. paste to a protected sheet will always cause paste return null.
-
pasteAllExceptBorder
Paste all (except border) from src to destination- Parameters:
src- source rangedest- destination range- Returns:
- a Range contains the final pasted range. paste to a protected sheet will always cause paste return null.
-
pasteTranspose
Paste and transpose from src to destination- Parameters:
src- source rangedest- destination range- Returns:
- a Range contains the final pasted range. paste to a protected sheet will always cause paste return null.
-
pasteSpecial
public static Range pasteSpecial(Range src, Range dest, Range.PasteType pasteType, Range.PasteOperation pasteOperation, boolean skipBlank, boolean transpose) Paste according the argument from src to destination- Parameters:
src- source rangedest- destination rangepasteType- paste typepasteOperation- paste operationskipBlank- skip blanktranspose- transpose- Returns:
- a Range contains the final pasted range. paste to a protected sheet will always cause paste return null.
-
getFontNameApplier
-
applyFontName
Apply font to cells in the range- Parameters:
range- range to be appliedfontName- the font name
-
getRichTextFontNameApplier
-
applyFontHeightPoints
Apply font height to cells in the range, it will also enlarge the row height if row height is smaller than font height- Parameters:
range- range to be appliedfontHeightPoints- the font height in point
-
fitFontHeightPoints
Detect the highest words in each row. It will change row height if needed.- Parameters:
range- range to be detected
-
getFontHeightPointsApplier
-
getRichTextFontHeightPointsApplier
public static CellOperationUtil.CellStyleApplier getRichTextFontHeightPointsApplier(int heightPoints) -
getFontBoldweightApplier
public static CellOperationUtil.CellStyleApplier getFontBoldweightApplier(Font.Boldweight boldweight) -
applyFontBoldweight
Apply font bold-weight to cells in the range- Parameters:
range- the range to be appliedboldweight- the font bold-weight
-
getRichTextFontBoldweightApplier
public static CellOperationUtil.CellStyleApplier getRichTextFontBoldweightApplier(Font.Boldweight boldweight) -
getFontItalicApplier
-
applyFontItalic
Apply font italic to cells in the range- Parameters:
range- the range to be applieditalic- the font italic
-
getRichTextFontItalicApplier
-
getFontStrikeoutApplier
-
applyFontStrikeout
Apply font strike-out to cells in the range- Parameters:
range- the range to be appliedstrikeout- font strike-out
-
getRichTextFontStrikeoutApplier
-
getFontUnderlineApplier
-
applyFontUnderline
Apply font underline to cells in the range- Parameters:
range- the range to be appliedunderline- font underline
-
getRichTextFontUnderlineApplier
public static CellOperationUtil.CellStyleApplier getRichTextFontUnderlineApplier(Font.Underline underline) -
getFontColorApplier
-
applyFontColor
Apply font color to cells in the range- Parameters:
range- the range to be applied.htmlColor- the color by html color syntax(#rgb-hex-code, e.x #FF00FF)
-
getRichTextFontColorApplier
-
getBackColorApplier
-
getFillColorApplier
-
applyBackColor
Apply back-color to cells in the range- Parameters:
range- the range to be appliedhtmlColor- the color by html color syntax(#rgb-hex-code, e.x #FF00FF)
-
applyFillColor
Apply fill-color to cells in the range- Parameters:
range- the range to be appliedhtmlColor- the color by html color syntax(#rgb-hex-code, e.x #FF00FF)
-
getDataFormatApplier
-
applyDataFormat
Apply data-format to cells in the range- Parameters:
range- the range to be appliedformat- the data format
-
getAligmentApplier
-
applyAlignment
Apply alignment to cells in the range- Parameters:
range- the range to be appliedalignment- the alignement
-
getVerticalAligmentApplier
public static CellOperationUtil.CellStyleApplier getVerticalAligmentApplier(CellStyle.VerticalAlignment alignment) -
applyVerticalAlignment
Apply vertical-alignment to cells in the range- Parameters:
range- the range to be appliedalignment- vertical alignment
-
applyCellStyle
Apply style according to the cell style applier- Parameters:
range- the range to be appliedapplyer-
-
applyBorder
public static void applyBorder(Range range, Range.ApplyBorderType applyType, CellStyle.BorderType borderType, String htmlColor) Apply border to cells in the range- Parameters:
range- the range to be appliedapplyType- the apply typeborderType- the border typehtmlColor- the color of border(#rgb-hex-code, e.x #FF00FF)
-
toggleMergeCenter
Toggle merge/unmerge of the range, if merging it will also set alignment to center- Parameters:
range- the range to be applied
-
merge
merge the range- Parameters:
range- the range to be mergeacross- true if merge horizontally
-
unmerge
Unmerge the range- Parameters:
range- the range to be unmerge
-
getWrapTextApplier
-
applyWrapText
Apply text-warp to cells in the range- Parameters:
range- the range to be appliedwraptext- wrap text or not
-
applyHyperlink
public static void applyHyperlink(Range range, Hyperlink.HyperlinkType type, String address, String label) -
clearContents
Clear contents- Parameters:
range- the range to be cleared.
-
clearStyles
Clear style- Parameters:
range- the range to be cleared
-
clearAll
Clear all- Parameters:
range- the range to be cleared
-
insert
Insert cells to the range. To insert a row, you have to callRange.toRowRange()first, to insert a column, you have to callRange.toColumnRange()first.- Parameters:
range- the range to insert new cellsshift- the shift direction of original cellscopyOrigin- copy the format from nearby cells when inserting new cells
-
insertRow
Insert rows to the range.- Parameters:
range- the range to insert new rows
-
insertColumn
Insert columns to the range.- Parameters:
range- the range to insert new rows
-
delete
Delete cells of the range. To delete a row, you have to callRange.toRowRange()first, to delete a column, you have to callRange.toColumnRange()first.- Parameters:
range- the range to deleteshift- the shift direction when deleting.
-
deleteRow
Delete rows of the range.- Parameters:
range- the range to delete rows
-
deleteColumn
Delete columns to the range.- Parameters:
range- the range to delete columns
-
sort
Sort range- Parameters:
range- the range to sortdesc- true for descent, false for ascent
-
sort
public static void sort(Range range, Range index1, boolean desc1, Range.SortDataOption dataOption1, Range index2, boolean desc2, Range.SortDataOption dataOption2, Range index3, boolean desc3, Range.SortDataOption dataOption3, boolean header, boolean matchCase, boolean sortByRows) Sort range- Parameters:
range- the range to sortdesc1- true for descent, false for ascent
-
hide
Hide the range. To hide a row, you have to callRange.toRowRange()first, to hide a column, you have to callRange.toColumnRange()- Parameters:
range- the range to hide
-
unhide
Unhide the range. To unhide a row, you have to callRange.toRowRange()first, to unhide a column, you have to callRange.toColumnRange()- Parameters:
range- the range to un-hide
-
shift
Shifts/moves cells with a offset row and column- Parameters:
range- the range to shiftrowOffset- the row offsetcolOffset- the column offset
-
autoFill
Fills data from source range to destination range automatically upon auto fill type- Parameters:
src- the source rangedest- the destination rangetype- the fill type, currently only support AutoFillType.DEFAULT, AutoFillType.COPY, AutoFillType.FORMAT, AutoFillType.VALUES
-
setRowHeight
Sets the row height and make it as custom modified- Parameters:
range-heightPx-
-
setRowHeight
Sets the row height and provide a custom flag, a custom flag to indicate this height was set by user or system.- Parameters:
range-heightPx-isCustom-- Since:
- 3.0.1
-
setColumnWidth
Sets the column width.Visibility effect:
- If
widthPxis 0, it hides the columns implicitly. - If
widthPxis a positive value, it unhides the columns automatically. - This operation affects entire columns even if the range only contains some cells.
- The column width will be marked as custom (manually set) and disables "best fit".
- It may trigger re-refresh of cell contents (e.g., changing displayed number precision).
- Parameters:
range- the target rangewidthPx- the column width in pixels. A value of 0 hides the columns, while a positive value unhides them and sets their width.
- If
-
getFontTypeOffsetApplier
-
applyFontTypeOffset
Apply font typeOffset to cells in the range- Parameters:
range- the range to be appliedoffset- font type offset (super, sub)
-
getRichTextFontTypeOffsetApplier
public static CellOperationUtil.CellStyleApplier getRichTextFontTypeOffsetApplier(Font.TypeOffset offset) -
getRotationApplier
-
applyRotation
Apply alignment to cells in the range- Parameters:
range- the range to be appliedrotation- the rotation degree(255 means vertical text)- Since:
- 3.8.0
-
getIndentionApplier
-
applyIndentionOffset
Apply indention to cells in the range- Parameters:
range- the range to be appliedoffset- the relative value to indent. Value greater than 0 means increasing indent. On the other hand, value less than 0 means decreasing indent.- Since:
- 3.8.0
-
getAutoFitHeight
Calculate the autoFit cell height according its data size. No resize when the whole cell has no content.
Note: be aware of that in different JDK vendor, version, or OS, theFontMetricscalculates a different width value of the same text, so the result on UI may look different when the server is running on these differences which are mentioned early. Not recommended using this function to update the cell height. Please useSpreadsheet.autoFitRowHeight(int, int).- Parameters:
sheet-row- index of rowcol- index of column- Returns:
- height (px)
- Since:
- 5.9.0
-
applyLocked
Apply the locked status only to cells in the range- Parameters:
range- the range to be appliedlocked- true to lock- Since:
- 6.0.0
-