public class Range extends Object
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear all the content/styles of the cells in this range
|
void |
copyTo(Range dest)
Copy the content of this range to another,
this include values and formatting
|
OfficeAnnotation |
getAnnotation()
Returns the annotation/comment of the first Cell in this range.
|
OfficeAnnotation[][] |
getAnnotations()
Returns the rectangular grid of the annotations for this range.
|
Range |
getCell(int row,
int column)
Get a specific cell of this Range using relative coords
for example, (0,0) would be the first cell of this range
|
int |
getColumn()
Get the starting column index of this range.
|
String |
getFormula()
Get the formula String of the first cell of the range
|
String[][] |
getFormulas()
Returns the formulas (A1 notation) for the cells in the range.
|
int |
getLastColumn()
Returns the end column position.
|
int |
getLastRow()
Returns the end row position.
|
Range[] |
getMergedCells()
Returns an array of Range objects representing merged cells that either
are fully within the current range, or contain at least one cell in the current range.
|
int |
getNumColumns()
Number of columns which contains this range
|
int |
getNumRows()
Number of rows which contains this range
|
int |
getNumValues()
Return the number of cells which contains this range
|
int |
getRow()
Get the starting row index of this range.
|
Sheet |
getSheet()
Returns the sheet where this range is contained
|
Style |
getStyle()
Returns the formating style of the top-left cell in the range.
|
Style[][] |
getStyles()
Returns the rectangular grid of formating styles for this range.
|
Object |
getValue()
Returns the value of the top-left cell in the range.
|
Object[][] |
getValues()
Returns the rectangular grid of values for this range.
|
boolean |
isPartOfMerge()
Determines if the range is part of an existing cell's block
|
void |
merge()
Merges the cells in the range together into a single block.
|
void |
setAnnotation(OfficeAnnotation annotation)
Set an annotation for all the cells in this range.
|
void |
setAnnotations(OfficeAnnotation... annotations)
Set a set of anotations to the range.
|
void |
setAnnotations(OfficeAnnotation[][] annotations)
Set a set of annotations to the range.
|
void |
setBackgroundColor(Color color)
Set a cell background color to the entire range
|
void |
setBackgroundColors(Color... color)
Set a set of cell background colors to the range.
|
void |
setBackgroundColors(Color[][] color)
Set a set of cell background colors formatting to the range.
|
void |
setFontBold(boolean bold)
Set a font bold style to the entire range
|
void |
setFontBolds(boolean... bold)
Set a set of font bolds styles to the range.
|
void |
setFontBolds(boolean[][] bold)
Set a set of font bolds formatting to the range.
|
void |
setFontColor(Color color)
Set a font color to the entire range
|
void |
setFontColors(Color... color)
Set a set of font colors styles to the range.
|
void |
setFontColors(Color[][] color)
Set a set of font colors formatting to the range.
|
void |
setFontItalic(boolean italic)
Set a font italic style to the entire range
|
void |
setFontItalics(boolean... italic)
Set a set of font italics styles to the range.
|
void |
setFontItalics(boolean[][] italic)
Set a set of font italics formatting to the range.
|
void |
setFontLineThrough(boolean lineThrough)
Set a font lineThrough style to the entire range
|
void |
setFontLineThroughs(boolean... lineThrough)
Set a set of font lineThroughs styles to the range.
|
void |
setFontLineThroughs(boolean[][] lineThrough)
Set a set of font lineThroughs formatting to the range.
|
void |
setFontSize(int fontSize)
Set the font size to the entire range
|
void |
setFontSizes(int... fontSizes)
Set a set of font sizes to the range.
|
void |
setFontSizes(int[][] fontSizes)
Set a set of font sizes to the range.
|
void |
setFontUnderline(boolean underline)
Set a font underline style to the entire range
|
void |
setFontUnderlines(boolean... underline)
Set a set of font underlines styles to the range.
|
void |
setFontUnderlines(boolean[][] underline)
Set a set of font underlines formatting to the range.
|
void |
setFormula(String formula)
Set a formula for every cell in the range.
|
void |
setFormulas(String... formula)
Set a set of formulas to the range.
|
void |
setFormulas(String[][] formula)
Set a set of formulas to the range.
|
void |
setStyle(Style style)
Set a format style for all the cells of the range
|
void |
setStyles(Style... style)
Set a set of format styles to the range.
|
void |
setStyles(Style[][] style)
Set a set of styles to the range.
|
void |
setValue(Object o)
Set a value to the entire range
|
void |
setValues(Object... o)
Set a set of values to the range.
|
void |
setValues(Object[][] o)
Set a set of values to the range.
|
void |
split()
Breaks apart any combined cells on the range.
|
String |
toString() |
public void clear()
public void copyTo(Range dest)
dest - The destination range, it must have the same size of the orig range.IllegalArgumentException - if the range hasn't the same sizepublic Range getCell(int row, int column)
row - The X Cordcolumn - The Y CordIndexOutOfBoundsException - if the coordinates are invalidpublic int getColumn()
public String getFormula()
public String[][] getFormulas()
public int getLastColumn()
public int getLastRow()
public Range[] getMergedCells()
public int getNumColumns()
public int getNumRows()
public int getRow()
public Sheet getSheet()
public Object getValue()
OfficeCurrency,
OfficePercentagepublic Object[][] getValues()
OfficeCurrency,
OfficePercentagepublic Style getStyle()
public Style[][] getStyles()
public OfficeAnnotation getAnnotation()
OfficeAnnotationpublic OfficeAnnotation[][] getAnnotations()
OfficeAnnotationpublic int getNumValues()
public void setValue(Object o)
o - The value object, it can be Integer, Float, Date, OfficeCurrency, OfficePercentage. Differents values types
will be considered as Strings and toString() will be invokedOfficeCurrency,
OfficePercentagepublic void setValues(Object... o)
Range range = sheet.getRange(0, 0, 2, 2); // 2x2 Range
range.setValues(1, 2, 3, 4); // Set the values for the range
o - The values array, it must the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setValues(Object[][] o)
o - The values 2D-array, it must have the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFontBold(boolean bold)
bold - Boolean which indicates if the font has bold style or notpublic void setFontBolds(boolean... bold)
Range range = sheet.getRange(0, 0, 2, 2); // 2x2 Range
range.setFontBolds(true, false, true, false); // Set the font bold formatting for the range
bold - The font bolds array, it must the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFontBolds(boolean[][] bold)
bold - The format 2D-array, it must have the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFontItalic(boolean italic)
italic - Boolean which indicates if the font has italic style or notpublic void setFontItalics(boolean... italic)
Range range = sheet.getRange(0, 0, 2, 2); // 2x2 Range
range.setFontItalics(true, false, true, false); // Set the font italic formatting for the range
italic - The font italics array, it must the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFontItalics(boolean[][] italic)
italic - The format 2D-array, it must have the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFontUnderline(boolean underline)
underline - Boolean which indicates if the font has underline style or notpublic void setFontUnderlines(boolean... underline)
Range range = sheet.getRange(0, 0, 2, 2); // 2x2 Range
range.setFontUnderlines(true, false, true, false); // Set the font underline formatting for the range
underline - The font underline array, it must the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFontUnderlines(boolean[][] underline)
underline - The format 2D-array, it must have the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFontLineThrough(boolean lineThrough)
lineThrough - Boolean which indicates if the font has lineThrough style or notpublic void setFontLineThroughs(boolean... lineThrough)
Range range = sheet.getRange(0, 0, 2, 2); // 2x2 Range
range.setFontLineThroughs(true, false, true, false); // Set the font lineThrough formatting for the range
lineThrough - The font lineThrough array, it must the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFontLineThroughs(boolean[][] lineThrough)
lineThrough - The format 2D-array, it must have the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFontColor(Color color)
color - The color to aplicate. A null value indicates no colorpublic void setFontColors(Color... color)
Color red = new Color(255, 0, 0);
Color green = new Color(0, 255, 0);
Color blue = new Color(0, 0, 255);
Range range = sheet.getRange(0, 0, 2, 2); // 2x2 Range
range.setFontColors(red, green, blue, null); // Set the font colors for the range
color - The font colors array, it must the same size of the range itself. Null values indicates no colorIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFontColors(Color[][] color)
color - The format 2D-array, it must have the same size of the range itself. A null value in the array indicates no colorIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setBackgroundColor(Color color)
color - The color to aplicate. A null value indicates "no color"public void setBackgroundColors(Color... color)
Color red = new Color(255, 0, 0);
Color green = new Color(0, 255, 0);
Color blue = new Color(0, 0, 255);
Range range = sheet.getRange(0, 0, 2, 2); // 2x2 Range
range.setBackgroundColors(red, green, blue, null); // Set the background colors for the range
color - The background colors array, it must the same size of the range itself. Null values indicates no colorIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setBackgroundColors(Color[][] color)
color - The format 2D-array, it must have the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFontSize(int fontSize)
fontSize - The fontsize to aplicate. A value of -1 unsets the font sizeIllegalArgumentException - if the font size is less of -1public void setFontSizes(int... fontSizes)
Range range = sheet.getRange(0, 0, 2, 2); // 2x2 Range
range.setBackgroundColors(20, 15, -1, 12); // Set the font sizes for the range
fontSizes - The background colors array, it must the same size of the range itself. -1 values unsets the font sizeIllegalArgumentException - if the number of values is not equals to the size of range or a font size is less of -1public void setFontSizes(int[][] fontSizes)
fontSizes - The format 2D-array, it must have the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of range or a font size is less of -1public void setFormula(String formula)
formula - The formula string representation in the same format of a regular spreadsheet, a example would be: "A1+A2+A3"public void setFormulas(String... formula)
formula - The formulas array, it must the same size of the range itself. The format of each formula
should be same used in a regular spreadsheet, for example: "A1+A2+A3"IllegalArgumentException - if the number of values is not equals to the size of rangepublic void setFormulas(String[][] formula)
formula - The formula 2D-array, it must have the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void setStyle(Style style)
style - The style to apply. Cells will receive a clone of this object.IllegalArgumentException - if the style is nullpublic void setStyles(Style... style)
style - The style array, it must the same size of the range itself.IllegalArgumentException - if the number of values is not equals to the size of range or a style is nullpublic void setStyles(Style[][] style)
style - The style 2D-array, it must have the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of range or a style is nullpublic void setAnnotation(OfficeAnnotation annotation)
annotation - The annotation to be setted in the rangeOfficeAnnotationpublic void setAnnotations(OfficeAnnotation... annotations)
annotations - The annotations array, it must the same size of the range itself.IllegalArgumentException - if the number of values is not equals to the size of rangepublic void setAnnotations(OfficeAnnotation[][] annotations)
annotations - The annotations 2D-array, it must have the same size of the range itselfIllegalArgumentException - if the number of values is not equals to the size of rangepublic void merge()
AssertionError - if a cell is already in a group. No changes will be donepublic void split()
IllegalArgumentException - If a group is not fully included on the range, no changes will be donepublic boolean isPartOfMerge()
Copyright © 2026. All rights reserved.