Package io.keikai.api
Class SheetOperationUtil
java.lang.Object
io.keikai.api.SheetOperationUtil
The utility to help UI to deal with user's sheet operation of a Range.
This utility is the default implementation for handling a spreadsheet, it is also the example for calling
Range APIs- Since:
- 3.0.0
- Author:
- dennis
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ChartaddChart(Range range, Chart.Type type, Chart.Grouping grouping, Chart.LegendPosition pos) Adds a chart to specified sheet range in pre-defined position and size.static ChartaddChart(Range range, SheetAnchor anchor, Chart.Type type, Chart.Grouping grouping, Chart.LegendPosition pos) Adds a chart at the specified locationstatic ChartaddChart(String name, Range range, Chart.Type type, Chart.Grouping grouping, Chart.LegendPosition pos) Adds a chart to specified sheet range in pre-defined position and size.static ChartaddChart(String name, Range range, SheetAnchor anchor, Chart.Type type, Chart.Grouping grouping, Chart.LegendPosition pos) Adds a chart at the specified locationstatic PictureaddPicture(Range range, byte[] binary, Picture.Format format, int widthPx, int heightPx) Add picture to the rangestatic PictureaddPicture(Range range, SheetAnchor anchor, byte[] binary, Picture.Format format) Add picture to the rangestatic PictureaddPicture(Range range, org.zkoss.image.AImage image) Add picture to the rangestatic voidAdd a new sheet to this bookstatic voidapplyAutoFilter(Range range) Re-apply autofilterstatic voidCopy the sheet with the naming pattern "ORIGINAL_SHEET_NAME (n)".static voidcreateSheet(Range range, String name) Add a new sheet as the last sheet to this bookstatic voiddeleteChart(Range range, Chart chart) Delete a chart if the specified Range has the specified chart.static voiddeletePicture(Range range, Picture picture) Delete a picturestatic voiddeleteSheet(Range range) Deletes the sheet, notice that it prevents you from deleting the last sheetstatic voiddisplaySheetGridlines(Range range, boolean enable) Enables/disables to show a sheet's gridlines.static Picture.FormatgetPictureFormat(org.zkoss.image.AImage image) Gets the picture formatstatic booleanReturns whether the range of sheet has the chart.static booleanhasPicture(Range range, Picture picture) Returns whether the range of sheet has the picturestatic voidMove a chart to specified row and column.static voidmovePicture(Range range, Picture picture, int rowIndex, int columnIndex) Move a picture to specified row and column.static voidprotectSheet(Range range, String password, boolean allowSelectingLockedCells, boolean allowSelectingUnlockedCells, boolean allowFormattingCells, boolean allowFormattingColumns, boolean allowFormattingRows, boolean allowInsertColumns, boolean allowInsertRows, boolean allowInsertingHyperlinks, boolean allowDeletingColumns, boolean allowDeletingRows, boolean allowSorting, boolean allowFiltering, boolean allowUsingPivotTables, boolean drawingObjects, boolean scenarios) static voidprotectSheet(Range range, String password, String newpasswrod) static voidrenameSheet(Range range, String newname) Rename a sheetstatic voidresetAutoFilter(Range range) Resets AutoFilterstatic voidsetSheetOrder(Range range, int pos) Sets a sheet's position order, used to move a sheetstatic SheetAnchortoChartAnchor(Range range) Create a anchor by range's row/column datastatic SheetAnchortoFilledAnchor(Sheet sheet, int row, int column, int widthPx, int heightPx) return aSheetAnchorbased on a cell and a picture width and heightstatic voidtoggleAutoFilter(Range range) Toggles AutoFilter on or offstatic booleanunprotectSheet(Range range, String password)
-
Constructor Details
-
SheetOperationUtil
public SheetOperationUtil()
-
-
Method Details
-
toggleAutoFilter
Toggles AutoFilter on or off- Parameters:
range- the range to toggle
-
resetAutoFilter
Resets AutoFilter- Parameters:
range- the range to reset
-
applyAutoFilter
Re-apply autofilter- Parameters:
range- the range to apply
-
addPicture
Add picture to the range- Parameters:
range- the range to add picture toimage- the image
-
addPicture
public static Picture addPicture(Range range, byte[] binary, Picture.Format format, int widthPx, int heightPx) Add picture to the range- Parameters:
range- the range to add picturebinary- the image binary dataformat- the image formatwidthPx- the width of image to placeheightPx- the height of image to place
-
addPicture
public static Picture addPicture(Range range, SheetAnchor anchor, byte[] binary, Picture.Format format) Add picture to the range- Parameters:
range- the range to add pictureanchor- the picture locationbinary- the image binary dataformat- the image format
-
getPictureFormat
Gets the picture format- Parameters:
image- the image- Returns:
- image format, or null if doens't support
-
movePicture
Move a picture to specified row and column.- Parameters:
range- a range represented the sheet that contains the picturepicture- the picture to moverowIndex- destination row index, 0-basedcolumnIndex- destination column index, 0-based
-
deletePicture
Delete a picture- Parameters:
range- a range that represents the sheet that contains the picturepicture- the picture to delete
-
hasPicture
Returns whether the range of sheet has the picture- Parameters:
range-picture-- Returns:
- true if the range has, otherwise false
-
addChart
public static Chart addChart(Range range, Chart.Type type, Chart.Grouping grouping, Chart.LegendPosition pos) Adds a chart to specified sheet range in pre-defined position and size.
Position: the same row as the specified range, 2 columns right to the specified range
Size: 7 rows, 7 columns- Parameters:
range- the range of source datatype- the chart typegrouping- the grouping typepos- the legend position type
-
addChart
public static Chart addChart(String name, Range range, Chart.Type type, Chart.Grouping grouping, Chart.LegendPosition pos) Adds a chart to specified sheet range in pre-defined position and size.
Position: the same row as the specified range, 2 columns right to the specified range
Size: 7 rows, 7 columns- Parameters:
name- the name of chartrange- the range of source datatype- the chart typegrouping- the grouping typepos- the legend position type- Since:
- 6.2.0
-
addChart
public static Chart addChart(Range range, SheetAnchor anchor, Chart.Type type, Chart.Grouping grouping, Chart.LegendPosition pos) Adds a chart at the specified location- Parameters:
range- the range of source dataanchor- the chart location on a sheettype- the chart typegrouping- the grouping typepos- the legend position type
-
addChart
public static Chart addChart(String name, Range range, SheetAnchor anchor, Chart.Type type, Chart.Grouping grouping, Chart.LegendPosition pos) Adds a chart at the specified location- Parameters:
name- the name of chartrange- the range of source dataanchor- the chart location on a sheettype- the chart typegrouping- the grouping typepos- the legend position type- Since:
- 6.2.0
-
toChartAnchor
Create a anchor by range's row/column data- Parameters:
range- the range for chart.- Returns:
- a new anchor
-
moveChart
Move a chart to specified row and column.- Parameters:
range- the range that represents the sheet contains the chart to move.chart- the chart to moverowIndex- destination row index, 0-based.columnIndex- destination column index, 0-based.
-
deleteChart
Delete a chart if the specified Range has the specified chart.- Parameters:
range- the range that represents the sheet contains the chart to delete.chart- the chart to delete.
-
hasChart
Returns whether the range of sheet has the chart.- Parameters:
range-chart-- Returns:
- true if the range has, otherwise false
-
protectSheet
-
protectSheet
public static void protectSheet(Range range, String password, boolean allowSelectingLockedCells, boolean allowSelectingUnlockedCells, boolean allowFormattingCells, boolean allowFormattingColumns, boolean allowFormattingRows, boolean allowInsertColumns, boolean allowInsertRows, boolean allowInsertingHyperlinks, boolean allowDeletingColumns, boolean allowDeletingRows, boolean allowSorting, boolean allowFiltering, boolean allowUsingPivotTables, boolean drawingObjects, boolean scenarios) -
unprotectSheet
-
displaySheetGridlines
Enables/disables to show a sheet's gridlines.- Parameters:
range- the sheet range to be appliedenable- true for enable
-
addSheet
Add a new sheet to this book- Parameters:
range- the range to be appliedprefix- the sheet name prefix, it will produce a new name with this prefix and a counter.
-
createSheet
Add a new sheet as the last sheet to this book- Parameters:
range- the Book to be appliedname- the sheet name, it must not be the same as another sheet name in this book, otherwise it takes no effect.
-
renameSheet
Rename a sheet- Parameters:
range- the sheet range to be appliednewname- the new name of the sheet, it must not same as another sheet name in this book
-
setSheetOrder
Sets a sheet's position order, used to move a sheet- Parameters:
range- the sheet range to be appliedpos- the sheet position
-
deleteSheet
Deletes the sheet, notice that it prevents you from deleting the last sheet- Parameters:
range- the sheet range to be applied
-
copySheet
Copy the sheet with the naming pattern "ORIGINAL_SHEET_NAME (n)".- Parameters:
range- the sheet range to be applied
-
toFilledAnchor
public static SheetAnchor toFilledAnchor(Sheet sheet, int row, int column, int widthPx, int heightPx) return aSheetAnchorbased on a cell and a picture width and height- Parameters:
sheet- target sheet where the anchor locatesrow- 0-based row indexcolumn- 0-base column indexwidthPx- a picture's width in pixelheightPx- a picture's height in pixel- Returns:
- a
SheetAnchor
-