Package io.keikai.api
Class CellOperationUtil
- java.lang.Object
-
- io.keikai.api.CellOperationUtil
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CellOperationUtil.CellStyleApplier
Interface for help apply cell stylestatic interface
CellOperationUtil.CellStyleApplierEx
Interface for help apply whole row,column style
-
Constructor Summary
Constructors Constructor Description CellOperationUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
applyAlignment(Range range, CellStyle.Alignment alignment)
Apply alignment to cells in the rangestatic void
applyBackColor(Range range, String htmlColor)
Apply back-color to cells in the rangestatic void
applyBorder(Range range, Range.ApplyBorderType applyType, CellStyle.BorderType borderType, String htmlColor)
Apply border to cells in the rangestatic void
applyCellStyle(Range range, CellOperationUtil.CellStyleApplier applyer)
Apply style according to the cell style applierstatic void
applyDataFormat(Range range, String format)
Apply data-format to cells in the rangestatic void
applyFillColor(Range range, String htmlColor)
Apply fill-color to cells in the rangestatic void
applyFontBoldweight(Range range, Font.Boldweight boldweight)
Apply font bold-weight to cells in the rangestatic void
applyFontColor(Range range, String htmlColor)
Apply font color to cells in the rangestatic void
applyFontHeightPoints(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 void
applyFontItalic(Range range, boolean italic)
Apply font italic to cells in the rangestatic void
applyFontName(Range range, String fontName)
Apply font to cells in the rangestatic void
applyFontStrikeout(Range range, boolean strikeout)
Apply font strike-out to cells in the rangestatic void
applyFontTypeOffset(Range range, Font.TypeOffset offset)
Apply font typeOffset to cells in the rangestatic void
applyFontUnderline(Range range, Font.Underline underline)
Apply font underline to cells in the rangestatic void
applyHyperlink(Range range, Hyperlink.HyperlinkType type, String address, String label)
static void
applyIndentionOffset(Range range, int offset)
Apply indention to cells in the rangestatic void
applyLocked(Range range, boolean locked)
Apply the locked status only to cells in the rangestatic void
applyRotation(Range range, int rotation)
Apply alignment to cells in the rangestatic void
applyVerticalAlignment(Range range, CellStyle.VerticalAlignment alignment)
Apply vertical-alignment to cells in the rangestatic void
applyWrapText(Range range, boolean wraptext)
Apply text-warp to cells in the rangestatic void
autoFill(Range src, Range dest, Range.AutoFillType type)
Fills data from source range to destination range automatically upon auto fill typestatic void
clearAll(Range range)
Clear allstatic void
clearContents(Range range)
Clear contentsstatic void
clearStyles(Range range)
Clear stylestatic Range
cut(Range src, Range dest)
Cuts data and style from src to destinationstatic void
delete(Range range, Range.DeleteShift shift)
Delete cells of the range.static void
deleteColumn(Range range)
Delete columns to the range.static void
deleteRow(Range range)
Delete rows of the range.static void
fitFontHeightPoints(Range range)
Detect the highest words in each row.static CellOperationUtil.CellStyleApplier
getAligmentApplier(CellStyle.Alignment alignment)
static int
getAutoFitHeight(Sheet sheet, int row, int col)
Calculate the autoFit cell height according its data size.static CellOperationUtil.CellStyleApplier
getBackColorApplier(Color color)
static CellOperationUtil.CellStyleApplier
getDataFormatApplier(String format)
static CellOperationUtil.CellStyleApplier
getFillColorApplier(Color color)
static CellOperationUtil.CellStyleApplier
getFontBoldweightApplier(Font.Boldweight boldweight)
static CellOperationUtil.CellStyleApplier
getFontColorApplier(Color color)
static CellOperationUtil.CellStyleApplier
getFontHeightPointsApplier(int fontHeightPoints)
static CellOperationUtil.CellStyleApplier
getFontItalicApplier(boolean italic)
static CellOperationUtil.CellStyleApplier
getFontNameApplier(String fontName)
static CellOperationUtil.CellStyleApplier
getFontStrikeoutApplier(boolean strikeout)
static CellOperationUtil.CellStyleApplier
getFontTypeOffsetApplier(Font.TypeOffset offset)
static CellOperationUtil.CellStyleApplier
getFontUnderlineApplier(Font.Underline underline)
static CellOperationUtil.CellStyleApplier
getIndentionApplier(int offset)
static CellOperationUtil.CellStyleApplier
getRichTextFontBoldweightApplier(Font.Boldweight boldweight)
static CellOperationUtil.CellStyleApplier
getRichTextFontColorApplier(Color color)
static CellOperationUtil.CellStyleApplier
getRichTextFontHeightPointsApplier(int heightPoints)
static CellOperationUtil.CellStyleApplier
getRichTextFontItalicApplier(boolean italic)
static CellOperationUtil.CellStyleApplier
getRichTextFontNameApplier(String fontName)
static CellOperationUtil.CellStyleApplier
getRichTextFontStrikeoutApplier(boolean strikeout)
static CellOperationUtil.CellStyleApplier
getRichTextFontTypeOffsetApplier(Font.TypeOffset offset)
static CellOperationUtil.CellStyleApplier
getRichTextFontUnderlineApplier(Font.Underline underline)
static CellOperationUtil.CellStyleApplier
getRotationApplier(short rotation)
static CellOperationUtil.CellStyleApplier
getVerticalAligmentApplier(CellStyle.VerticalAlignment alignment)
static CellOperationUtil.CellStyleApplier
getWrapTextApplier(boolean wraptext)
static void
hide(Range range)
Hide the range.static void
insert(Range range, Range.InsertShift shift, Range.InsertCopyOrigin copyOrigin)
Insert cells to the range.static void
insertColumn(Range range)
Insert columns to the range.static void
insertRow(Range range)
Insert rows to the range.static void
merge(Range range, boolean across)
merge the rangestatic Range
paste(Range src, Range dest)
Paste data and style from src to destinationstatic Range
pasteAllExceptBorder(Range src, Range dest)
Paste all (except border) from src to destinationstatic Range
pasteFormula(Range src, Range dest)
Paste formula only from src to destinationstatic Range
pasteSpecial(Range src, Range dest, Range.PasteType pasteType, Range.PasteOperation pasteOperation, boolean skipBlank, boolean transpose)
Paste according the argument from src to destinationstatic Range
pasteTranspose(Range src, Range dest)
Paste and transpose from src to destinationstatic Range
pasteValue(Range src, Range dest)
Paste value only from src to destinationstatic void
setColumnWidth(Range range, int widthPx)
Sets the column widthstatic void
setRowHeight(Range range, int heightPx)
Sets the row height and make it as custom modifiedstatic void
setRowHeight(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 void
shift(Range range, int rowOffset, int colOffset)
Shifts/moves cells with a offset row and columnstatic void
sort(Range range, boolean desc)
Sort rangestatic 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 rangestatic void
toggleMergeCenter(Range range)
Toggle merge/unmerge of the range, if merging it will also set alignment to centerstatic void
unhide(Range range)
Unhide the range.static void
unmerge(Range range)
Unmerge the range
-
-
-
Method Detail
-
cut
public static Range cut(Range src, Range dest)
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
public static Range paste(Range src, Range dest)
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
public static Range pasteFormula(Range src, Range dest)
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
public static Range pasteValue(Range src, Range dest)
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
public static Range pasteAllExceptBorder(Range src, Range dest)
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
public static Range pasteTranspose(Range src, Range dest)
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
public static CellOperationUtil.CellStyleApplier getFontNameApplier(String fontName)
-
applyFontName
public static void applyFontName(Range range, String fontName)
Apply font to cells in the range- Parameters:
range
- range to be appliedfontName
- the font name
-
getRichTextFontNameApplier
public static CellOperationUtil.CellStyleApplier getRichTextFontNameApplier(String fontName)
-
applyFontHeightPoints
public static void applyFontHeightPoints(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 height- Parameters:
range
- range to be appliedfontHeightPoints
- the font height in point
-
fitFontHeightPoints
public static void fitFontHeightPoints(Range range)
Detect the highest words in each row. It will change row height if needed.- Parameters:
range
- range to be detected
-
getFontHeightPointsApplier
public static CellOperationUtil.CellStyleApplier getFontHeightPointsApplier(int fontHeightPoints)
-
getRichTextFontHeightPointsApplier
public static CellOperationUtil.CellStyleApplier getRichTextFontHeightPointsApplier(int heightPoints)
-
getFontBoldweightApplier
public static CellOperationUtil.CellStyleApplier getFontBoldweightApplier(Font.Boldweight boldweight)
-
applyFontBoldweight
public static void applyFontBoldweight(Range range, Font.Boldweight boldweight)
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
public static CellOperationUtil.CellStyleApplier getFontItalicApplier(boolean italic)
-
applyFontItalic
public static void applyFontItalic(Range range, boolean italic)
Apply font italic to cells in the range- Parameters:
range
- the range to be applieditalic
- the font italic
-
getRichTextFontItalicApplier
public static CellOperationUtil.CellStyleApplier getRichTextFontItalicApplier(boolean italic)
-
getFontStrikeoutApplier
public static CellOperationUtil.CellStyleApplier getFontStrikeoutApplier(boolean strikeout)
-
applyFontStrikeout
public static void applyFontStrikeout(Range range, boolean strikeout)
Apply font strike-out to cells in the range- Parameters:
range
- the range to be appliedstrikeout
- font strike-out
-
getRichTextFontStrikeoutApplier
public static CellOperationUtil.CellStyleApplier getRichTextFontStrikeoutApplier(boolean strikeout)
-
getFontUnderlineApplier
public static CellOperationUtil.CellStyleApplier getFontUnderlineApplier(Font.Underline underline)
-
applyFontUnderline
public static void applyFontUnderline(Range range, Font.Underline underline)
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
public static CellOperationUtil.CellStyleApplier getFontColorApplier(Color color)
-
applyFontColor
public static void applyFontColor(Range range, String htmlColor)
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
public static CellOperationUtil.CellStyleApplier getRichTextFontColorApplier(Color color)
-
getBackColorApplier
public static CellOperationUtil.CellStyleApplier getBackColorApplier(Color color)
-
getFillColorApplier
public static CellOperationUtil.CellStyleApplier getFillColorApplier(Color color)
-
applyBackColor
public static void applyBackColor(Range range, String htmlColor)
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
public static void applyFillColor(Range range, String htmlColor)
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
public static CellOperationUtil.CellStyleApplier getDataFormatApplier(String format)
-
applyDataFormat
public static void applyDataFormat(Range range, String format)
Apply data-format to cells in the range- Parameters:
range
- the range to be appliedformat
- the data format
-
getAligmentApplier
public static CellOperationUtil.CellStyleApplier getAligmentApplier(CellStyle.Alignment alignment)
-
applyAlignment
public static void applyAlignment(Range range, CellStyle.Alignment alignment)
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
public static void applyVerticalAlignment(Range range, CellStyle.VerticalAlignment alignment)
Apply vertical-alignment to cells in the range- Parameters:
range
- the range to be appliedalignment
- vertical alignment
-
applyCellStyle
public static void applyCellStyle(Range range, CellOperationUtil.CellStyleApplier applyer)
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
public static void toggleMergeCenter(Range range)
Toggle merge/unmerge of the range, if merging it will also set alignment to center- Parameters:
range
- the range to be applied
-
merge
public static void merge(Range range, boolean across)
merge the range- Parameters:
range
- the range to be mergeacross
- true if merge horizontally
-
unmerge
public static void unmerge(Range range)
Unmerge the range- Parameters:
range
- the range to be unmerge
-
getWrapTextApplier
public static CellOperationUtil.CellStyleApplier getWrapTextApplier(boolean wraptext)
-
applyWrapText
public static void applyWrapText(Range range, boolean wraptext)
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
public static void clearContents(Range range)
Clear contents- Parameters:
range
- the range to be cleared.
-
clearStyles
public static void clearStyles(Range range)
Clear style- Parameters:
range
- the range to be cleared
-
clearAll
public static void clearAll(Range range)
Clear all- Parameters:
range
- the range to be cleared
-
insert
public static void insert(Range range, Range.InsertShift shift, Range.InsertCopyOrigin copyOrigin)
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
public static void insertRow(Range range)
Insert rows to the range.- Parameters:
range
- the range to insert new rows
-
insertColumn
public static void insertColumn(Range range)
Insert columns to the range.- Parameters:
range
- the range to insert new rows
-
delete
public static void delete(Range range, Range.DeleteShift shift)
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
public static void deleteRow(Range range)
Delete rows of the range.- Parameters:
range
- the range to delete rows
-
deleteColumn
public static void deleteColumn(Range range)
Delete columns to the range.- Parameters:
range
- the range to delete columns
-
sort
public static void sort(Range range, boolean desc)
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
public static void hide(Range range)
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
public static void unhide(Range range)
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
public static void shift(Range range, int rowOffset, int colOffset)
Shifts/moves cells with a offset row and column- Parameters:
range
- the range to shiftrowOffset
- the row offsetcolOffset
- the column offset
-
autoFill
public static void autoFill(Range src, Range dest, Range.AutoFillType type)
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
public static void setRowHeight(Range range, int heightPx)
Sets the row height and make it as custom modified- Parameters:
range
-heightPx
-
-
setRowHeight
public static void setRowHeight(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.- Parameters:
range
-heightPx
-isCustom
-- Since:
- 3.0.1
-
setColumnWidth
public static void setColumnWidth(Range range, int widthPx)
Sets the column width- Parameters:
range
-widthPx
-
-
getFontTypeOffsetApplier
public static CellOperationUtil.CellStyleApplier getFontTypeOffsetApplier(Font.TypeOffset offset)
-
applyFontTypeOffset
public static void applyFontTypeOffset(Range range, Font.TypeOffset offset)
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
public static CellOperationUtil.CellStyleApplier getRotationApplier(short rotation)
-
applyRotation
public static void applyRotation(Range range, int rotation)
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
public static CellOperationUtil.CellStyleApplier getIndentionApplier(int offset)
-
applyIndentionOffset
public static void applyIndentionOffset(Range range, int offset)
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
public static int getAutoFitHeight(Sheet sheet, int row, int col)
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, theFontMetrics
calculates 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
public static void applyLocked(Range range, boolean locked)
Apply the locked status only to cells in the range- Parameters:
range
- the range to be appliedlocked
- true to lock- Since:
- 6.0.0
-
-