Package com.github.miachm.sods
Class Range
java.lang.Object
com.github.miachm.sods.Range
A range represents a subset of a Sheet.
You use ranges for write/read content in a Sheet. It references a specific subset of the Sheet.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all the content/styles of the cells in this rangevoidCopy the content of this range to another, this include values and formattingReturns the annotation/comment of the first Cell in this range.OfficeAnnotation[][]Returns the rectangular grid of the annotations for this 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 rangeintGet the starting column index of this range.Get the formula String of the first cell of the rangeString[][]Returns the formulas (A1 notation) for the cells in the range.intReturns the end column position.intReturns the end row position.Range[]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.intNumber of columns which contains this rangeintNumber of rows which contains this rangeintReturn the number of cells which contains this rangeintgetRow()Get the starting row index of this range.getSheet()Returns the sheet where this range is containedgetStyle()Returns the formating style of the top-left cell in the range.Style[][]Returns the rectangular grid of formating styles for this range.getValue()Returns the value of the top-left cell in the range.Object[][]Returns the rectangular grid of values for this range.booleanDetermines if the range is part of an existing cell's blockvoidmerge()Merges the cells in the range together into a single block.voidsetAnnotation(OfficeAnnotation annotation) Set an annotation for all the cells in this range.voidsetAnnotations(OfficeAnnotation... annotations) Set a set of anotations to the range.voidsetAnnotations(OfficeAnnotation[][] annotations) Set a set of annotations to the range.voidsetBackgroundColor(Color color) Set a cell background color to the entire rangevoidsetBackgroundColors(Color... color) Set a set of cell background colors to the range.voidsetBackgroundColors(Color[][] color) Set a set of cell background colors formatting to the range.voidsetFontBold(boolean bold) Set a font bold style to the entire rangevoidsetFontBolds(boolean... bold) Set a set of font bolds styles to the range.voidsetFontBolds(boolean[][] bold) Set a set of font bolds formatting to the range.voidsetFontColor(Color color) Set a font color to the entire rangevoidsetFontColors(Color... color) Set a set of font colors styles to the range.voidsetFontColors(Color[][] color) Set a set of font colors formatting to the range.voidsetFontItalic(boolean italic) Set a font italic style to the entire rangevoidsetFontItalics(boolean... italic) Set a set of font italics styles to the range.voidsetFontItalics(boolean[][] italic) Set a set of font italics formatting to the range.voidsetFontSize(int fontSize) Set the font size to the entire rangevoidsetFontSizes(int... fontSizes) Set a set of font sizes to the range.voidsetFontSizes(int[][] fontSizes) Set a set of font sizes to the range.voidsetFontUnderline(boolean underline) Set a font underline style to the entire rangevoidsetFontUnderlines(boolean... underline) Set a set of font underlines styles to the range.voidsetFontUnderlines(boolean[][] underline) Set a set of font underlines formatting to the range.voidsetFormula(String formula) Set a formula for every cell in the range.voidsetFormulas(String... formula) Set a set of formulas to the range.voidsetFormulas(String[][] formula) Set a set of formulas to the range.voidSet a format style for all the cells of the rangevoidSet a set of format styles to the range.voidSet a set of styles to the range.voidSet a value to the entire rangevoidSet a set of values to the range.voidSet a set of values to the range.voidsplit()Breaks apart any combined cells on the range.toString()
-
Method Details
-
clear
public void clear()Clear all the content/styles of the cells in this range -
copyTo
Copy the content of this range to another, this include values and formatting- Parameters:
dest- The destination range, it must have the same size of the orig range.- Throws:
IllegalArgumentException- if the range hasn't the same size
-
getCell
Get a specific cell of this Range using relative coords for example, (0,0) would be the first cell of this range- Parameters:
row- The X Cordcolumn- The Y Cord- Returns:
- A range which contains that specific cell
- Throws:
IndexOutOfBoundsException- if the coordinates are invalid
-
getColumn
public int getColumn()Get the starting column index of this range. For example a value of 2, indicates what this range starts at the third column of the sheet.- Returns:
- An integer with the column index
-
getFormula
Get the formula String of the first cell of the range- Returns:
- the formula text representation, it can be null
-
getFormulas
Returns the formulas (A1 notation) for the cells in the range. Entries in the 2D array are null for cells with no formula.- Returns:
- The formulas of the range
-
getLastColumn
public int getLastColumn()Returns the end column position.- Returns:
- The coordinate of the end column position in the sheet.
-
getLastRow
public int getLastRow()Returns the end row position.- Returns:
- The coordinate of the end row position in the sheet.
-
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.- Returns:
- An array with all the Ranges[]
-
getNumColumns
public int getNumColumns()Number of columns which contains this range- Returns:
- the number of columns
-
getNumRows
public int getNumRows()Number of rows which contains this range- Returns:
- the number of columns
-
getRow
public int getRow()Get the starting row index of this range. For example a value of 2, indicates what this range starts at the third row of the sheet.- Returns:
- An integer with the row index
-
getSheet
Returns the sheet where this range is contained- Returns:
- A not-null sheet object
-
getValue
Returns the value of the top-left cell in the range. The values could be String, Float, Integer, OfficeCurrency, OfficePercentage or a LocalDate Empty cells returns a null object- Returns:
- the value in this cell
- See Also:
-
getValues
Returns the rectangular grid of values for this range. The values could be String, Float, Integer, OfficeCurrency, OfficePercentage or a LocalDate Empty cells returns a null object- Returns:
- A two-dimensional array of values.
- See Also:
-
getStyle
Returns the formating style of the top-left cell in the range. It's safe to manipulate the Style object since is a copy of the original one- Returns:
- the style in this cell. It can not be null.
-
getStyles
Returns the rectangular grid of formating styles for this range. It's safe to manipulate the Styles objects since they are copies of the original ones- Returns:
- A two-dimensional array of values. It can not be null
-
getAnnotation
Returns the annotation/comment of the first Cell in this range.- Returns:
- An object which contains the comment, or null if it doesn't exist
- See Also:
-
getAnnotations
Returns the rectangular grid of the annotations for this range. It will be null if the cell doesn't have comments- Returns:
- A two-dimensional array of values. It can not be null
- See Also:
-
getNumValues
public int getNumValues()Return the number of cells which contains this range- Returns:
- The number of cells in this range
-
setValue
Set a value to the entire range- Parameters:
o- The value object, it can be Integer, Float, Date, OfficeCurrency, OfficePercentage. Differents values types will be considered as Strings and toString() will be invoked- See Also:
-
setValues
Set a set of values to the range. The values must have the same size of the entire range itselfRange range = sheet.getRange(0, 0, 2, 2); // 2x2 Range range.setValues(1, 2, 3, 4); // Set the values for the range- Parameters:
o- The values array, it must the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setValues
Set a set of values to the range. The values array must have the same size of the entire range itself- Parameters:
o- The values 2D-array, it must have the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setFontBold
public void setFontBold(boolean bold) Set a font bold style to the entire range- Parameters:
bold- Boolean which indicates if the font has bold style or not
-
setFontBolds
public void setFontBolds(boolean... bold) Set a set of font bolds styles to the range. The array must have the same size of the entire range itselfRange range = sheet.getRange(0, 0, 2, 2); // 2x2 Range range.setFontBolds(true, false, true, false); // Set the font bold formatting for the range- Parameters:
bold- The font bolds array, it must the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setFontBolds
public void setFontBolds(boolean[][] bold) Set a set of font bolds formatting to the range. The format array must have the same size of the entire range itself- Parameters:
bold- The format 2D-array, it must have the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setFontItalic
public void setFontItalic(boolean italic) Set a font italic style to the entire range- Parameters:
italic- Boolean which indicates if the font has italic style or not
-
setFontItalics
public void setFontItalics(boolean... italic) Set a set of font italics styles to the range. The array must have the same size of the entire range itselfRange range = sheet.getRange(0, 0, 2, 2); // 2x2 Range range.setFontItalics(true, false, true, false); // Set the font italic formatting for the range- Parameters:
italic- The font italics array, it must the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setFontItalics
public void setFontItalics(boolean[][] italic) Set a set of font italics formatting to the range. The format array must have the same size of the entire range itself- Parameters:
italic- The format 2D-array, it must have the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setFontUnderline
public void setFontUnderline(boolean underline) Set a font underline style to the entire range- Parameters:
underline- Boolean which indicates if the font has underline style or not
-
setFontUnderlines
public void setFontUnderlines(boolean... underline) Set a set of font underlines styles to the range. The array must have the same size of the entire range itselfRange range = sheet.getRange(0, 0, 2, 2); // 2x2 Range range.setFontUnderlines(true, false, true, false); // Set the font underline formatting for the range- Parameters:
underline- The font underline array, it must the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setFontUnderlines
public void setFontUnderlines(boolean[][] underline) Set a set of font underlines formatting to the range. The format array must have the same size of the entire range itself- Parameters:
underline- The format 2D-array, it must have the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setFontColor
Set a font color to the entire range- Parameters:
color- The color to aplicate. A null value indicates no color
-
setFontColors
Set a set of font colors styles to the range. The array must have the same size of the entire range itselfColor 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- Parameters:
color- The font colors array, it must the same size of the range itself. Null values indicates no color- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setFontColors
Set a set of font colors formatting to the range. The format array must have the same size of the entire range itself- Parameters:
color- The format 2D-array, it must have the same size of the range itself. A null value in the array indicates no color- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setBackgroundColor
Set a cell background color to the entire range- Parameters:
color- The color to aplicate. A null value indicates "no color"
-
setBackgroundColors
Set a set of cell background colors to the range. The array must have the same size of the entire range itselfColor 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- Parameters:
color- The background colors array, it must the same size of the range itself. Null values indicates no color- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setBackgroundColors
Set a set of cell background colors formatting to the range. The format array must have the same size of the entire range itself- Parameters:
color- The format 2D-array, it must have the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setFontSize
public void setFontSize(int fontSize) Set the font size to the entire range- Parameters:
fontSize- The fontsize to aplicate. A value of -1 unsets the font size- Throws:
IllegalArgumentException- if the font size is less of -1
-
setFontSizes
public void setFontSizes(int... fontSizes) Set a set of font sizes to the range. The array must have the same size of the entire range itselfRange range = sheet.getRange(0, 0, 2, 2); // 2x2 Range range.setBackgroundColors(20, 15, -1, 12); // Set the font sizes for the range- Parameters:
fontSizes- The background colors array, it must the same size of the range itself. -1 values unsets the font size- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range or a font size is less of -1
-
setFontSizes
public void setFontSizes(int[][] fontSizes) Set a set of font sizes to the range. The format array must have the same size of the entire range itself- Parameters:
fontSizes- The format 2D-array, it must have the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range or a font size is less of -1
-
setFormula
Set a formula for every cell in the range. Note that this method doesn't evaluate the formula. It just sets the formula value for when you decide to save it to a file.- Parameters:
formula- The formula string representation in the same format of a regular spreadsheet, a example would be: "A1+A2+A3"
-
setFormulas
Set a set of formulas to the range. The array must have the same size of the entire range itself. Note that this method doesn't evaluate the formulas. It jus sets the formula value for when you decide to save it to a file.- Parameters:
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"- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setFormulas
Set a set of formulas to the range. The formula array must have the same size of the entire range itself Note that this method doesn't evaluate the formulas. It jus sets the formula value for when you decide to save it to a file.- Parameters:
formula- The formula 2D-array, it must have the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
toString
-
setStyle
Set a format style for all the cells of the range- Parameters:
style- The style to apply. Cells will receive a clone of this object.- Throws:
IllegalArgumentException- if the style is null
-
setStyles
Set a set of format styles to the range. The array must have the same size of the entire range itself.- Parameters:
style- The style array, it must the same size of the range itself.- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range or a style is null
-
setStyles
Set a set of styles to the range. The array must have the same size of the entire range itself- Parameters:
style- The style 2D-array, it must have the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range or a style is null
-
setAnnotation
Set an annotation for all the cells in this range.- Parameters:
annotation- The annotation to be setted in the range- See Also:
-
setAnnotations
Set a set of anotations to the range. The array must have the same size of the entire range itself.- Parameters:
annotations- The annotations array, it must the same size of the range itself.- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
setAnnotations
Set a set of annotations to the range. The array must have the same size of the entire range itself- Parameters:
annotations- The annotations 2D-array, it must have the same size of the range itself- Throws:
IllegalArgumentException- if the number of values is not equals to the size of range
-
merge
public void merge()Merges the cells in the range together into a single block. If the range only contains a cell, no actions will be taken- Throws:
AssertionError- if a cell is already in a group. No changes will be done
-
split
public void split()Breaks apart any combined cells on the range. The full group must be inside of the range or a IllegalArgumentException would be thrown.- Throws:
IllegalArgumentException- If a group is not fully included on the range, no changes will be done
-
isPartOfMerge
public boolean isPartOfMerge()Determines if the range is part of an existing cell's block- Returns:
- True if the range overlap any merged cells
-