Package io.keikai.api

Class CellOperationUtil


  • public class CellOperationUtil
    extends Object
    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
    • Constructor Detail

      • CellOperationUtil

        public CellOperationUtil()
    • Method Detail

      • cut

        public static Range cut​(Range src,
                                Range dest)
        Cuts data and style from src to destination
        Parameters:
        src - source range
        dest - 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 range
        dest - 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 range
        dest - 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 range
        dest - 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 range
        dest - 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 range
        dest - 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 range
        dest - destination range
        pasteType - paste type
        pasteOperation - paste operation
        skipBlank - skip blank
        transpose - transpose
        Returns:
        a Range contains the final pasted range. paste to a protected sheet will always cause paste return null.
      • applyFontName

        public static void applyFontName​(Range range,
                                         String fontName)
        Apply font to cells in the range
        Parameters:
        range - range to be applied
        fontName - the font name
      • 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 applied
        fontHeightPoints - 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
      • 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 applied
        boldweight - the font bold-weight
      • applyFontItalic

        public static void applyFontItalic​(Range range,
                                           boolean italic)
        Apply font italic to cells in the range
        Parameters:
        range - the range to be applied
        italic - the font italic
      • applyFontStrikeout

        public static void applyFontStrikeout​(Range range,
                                              boolean strikeout)
        Apply font strike-out to cells in the range
        Parameters:
        range - the range to be applied
        strikeout - font strike-out
      • applyFontUnderline

        public static void applyFontUnderline​(Range range,
                                              Font.Underline underline)
        Apply font underline to cells in the range
        Parameters:
        range - the range to be applied
        underline - font underline
      • 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)
      • applyBackColor

        public static void applyBackColor​(Range range,
                                          String htmlColor)
        Apply back-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)
      • applyFillColor

        public static void applyFillColor​(Range range,
                                          String htmlColor)
        Apply fill-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)
      • applyDataFormat

        public static void applyDataFormat​(Range range,
                                           String format)
        Apply data-format to cells in the range
        Parameters:
        range - the range to be applied
        format - the data format
      • applyAlignment

        public static void applyAlignment​(Range range,
                                          CellStyle.Alignment alignment)
        Apply alignment to cells in the range
        Parameters:
        range - the range to be applied
        alignment - the alignement
      • applyVerticalAlignment

        public static void applyVerticalAlignment​(Range range,
                                                  CellStyle.VerticalAlignment alignment)
        Apply vertical-alignment to cells in the range
        Parameters:
        range - the range to be applied
        alignment - 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 applied
        applyer -
      • 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 applied
        applyType - the apply type
        borderType - the border type
        htmlColor - 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 merge
        across - true if merge horizontally
      • unmerge

        public static void unmerge​(Range range)
        Unmerge the range
        Parameters:
        range - the range to be unmerge
      • applyWrapText

        public static void applyWrapText​(Range range,
                                         boolean wraptext)
        Apply text-warp to cells in the range
        Parameters:
        range - the range to be applied
        wraptext - wrap text or not
      • 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 call Range.toRowRange() first, to insert a column, you have to call Range.toColumnRange() first.
        Parameters:
        range - the range to insert new cells
        shift - the shift direction of original cells
        copyOrigin - 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 call Range.toRowRange() first, to delete a column, you have to call Range.toColumnRange() first.
        Parameters:
        range - the range to delete
        shift - 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 sort
        desc - true for descent, false for ascent
      • unhide

        public static void unhide​(Range range)
        Unhide the range. To unhide a row, you have to call Range.toRowRange() first, to unhide a column, you have to call Range.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 shift
        rowOffset - the row offset
        colOffset - 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 range
        dest - the destination range
        type - 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 -
      • applyFontTypeOffset

        public static void applyFontTypeOffset​(Range range,
                                               Font.TypeOffset offset)
        Apply font typeOffset to cells in the range
        Parameters:
        range - the range to be applied
        offset - font type offset (super, sub)
      • applyRotation

        public static void applyRotation​(Range range,
                                         int rotation)
        Apply alignment to cells in the range
        Parameters:
        range - the range to be applied
        rotation - the rotation degree(255 means vertical text)
        Since:
        3.8.0
      • applyIndentionOffset

        public static void applyIndentionOffset​(Range range,
                                                int offset)
        Apply indention to cells in the range
        Parameters:
        range - the range to be applied
        offset - 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, the FontMetrics 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 use Spreadsheet.autoFitRowHeight(int, int).
        Parameters:
        sheet -
        row - index of row
        col - 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 applied
        locked - true to lock
        Since:
        6.0.0