public class CellRange extends Object implements Serializable
CellRange cr = new CellRange("Sheet1!A1:B10", workbk);Starter Inc.
cr.addCellToRange("C10");
CellHandle mycells = cr.getCells();
for(int x=0;x < mycells.length;x++)
Logger.logInfo(mycells[x].getCellAddress() + mycells[x].toString());
}
DataBoundCellRange,
XLSRecord,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
CellHandle[] |
cells |
static int |
COPY_CONTENTS
Whether to copy the cell contents.
|
static int |
COPY_FORMATS |
static int |
COPY_FORMULAS
Whether formulas should be copied.
|
boolean |
DEBUG |
protected int |
externalLink1 |
protected int |
externalLink2 |
protected WorkBook |
mybook |
protected String |
range |
static boolean |
REMOVE_MERGED_CELLS |
static boolean |
RETAIN_MERGED_CELLS |
protected String |
sheetname |
static String |
xmlResponsePost |
static String |
xmlResponsePre |
| Modifier | Constructor and Description |
|---|---|
|
CellRange(CellHandle[] newcells)
Constructor which creates a new CellRange using an array of cells as it's
constructor.
|
|
CellRange(CellHandle[] newcells,
boolean createblanks)
create a new CellRange using an array of cells as it's constructor.
|
|
CellRange(CellRangeRef source)
Initializes a
CellRange from a CellRangeRef. |
|
CellRange(CellRangeRef source,
boolean init,
boolean create)
Initializes a
CellRange from a CellRangeRef. |
|
CellRange(String r)
Constructor to Create a new CellRange from a String range
The String range must be in the format Sheet!CR:CR For Example, "Sheet1!C9:I19" NOTE: You MUST Set the WorkBookHandle explicitly on this CellRange or it will generate NullPointerException when trying to access the Cells. |
|
CellRange(String range,
WorkBook bk)
Constructor which creates a new CellRange from a String range
The String range must be in the format Sheet!CR:CR For Example, "Sheet1!C9:I19" |
|
CellRange(String range,
WorkBook bk,
boolean c)
Constructor which creates a new CellRange from a String range
The String range must be in the format Sheet!CR:CR For Example, "Sheet1!C9:I19" |
|
CellRange(String range,
WorkBook bk,
boolean createblanks,
boolean initcells)
Constructor which creates a new CellRange from a String range
The String range must be in the format Sheet!CR:CR For Example, "Sheet1!C9:I19" |
|
CellRange(WorkSheetHandle sht,
int[] coords)
Constructor to create a new CellRange from a WorkSheetHandle and a set of
range coordinates:
coords[0] = first row coords[1] = first col coords[2] = last row coords[3] = last col |
|
CellRange(WorkSheetHandle sht,
int[] coords,
boolean cb)
Constructor to create a new CellRange from a WorkSheetHandle and a set of
range coordinates:
coords[0] = first row coords[1] = first col coords[2] = last row coords[3] = last col |
protected |
CellRange(WorkSheetHandle sheet,
int row,
int col,
int width,
int height)
Protected constructor for creating result ranges.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
addCellToRange(CellHandle ch)
Increase the bounds of the CellRange by including the CellHandle.
|
Collection<CellHandle> |
calculateAffectedCellsOnSheet() |
void |
clear()
clears the contents and formats of the cells referenced by this range but
does not remove the cells from the workbook.
|
void |
clearContents()
Deprecated.
use clear()
|
void |
clearFormats() |
boolean |
contains(Cell cxx)
returns whether this CellRange contains a particular Cell
|
boolean |
contains(int[] rc)
returns whether this CellRange contains the specified Row/Col coordinates
|
CellRange |
copy(WorkSheetHandle sheet,
int row,
int col,
int what)
Copies this range to another location.
|
void |
fill(CellHandle source,
int what,
double increment)
Fills this range from the given cell.
|
org.json.JSONObject |
getBasicJSON()
Return a json object representing this cell range, entries contain only
address and values for more compact space
|
List<CellHandle> |
getCellList()
Return a list of the cells in this cell range
|
String |
getCellRangeXML()
gets the array of Cells in this Name
Thus this method is limited to use with 2D ranges.
|
String |
getCellRangeXML(boolean fragment)
gets the array of Cells in this Name
NOTE: this method variation also returns the Sheetname for the name record if
not null.
|
BiffRec[] |
getCellRecs()
get the underlying Cell Records in this range
NOTE: Cell Records are not a part of the public API and are not intended for use in client applications. |
CellHandle[] |
getCells()
get the Cells in this cell range
|
static CellHandle[] |
getCells(String range,
WorkBookHandle wbh)
returns the cells for a given range
static version |
ArrayList<CellHandle> |
getCellsByCol(String col)
Get the cells from a particular column, constrained by the boundaries of the
cellRange
|
ArrayList<CellHandle> |
getCellsByRow(int rownumber)
Get the cells from a particular rownumber, constrained by the boundaries of
the cellRange
|
int[] |
getColInts()
returns an array of column numbers referenced by this CellRange
|
ColHandle[] |
getCols()
Returns an array of Columns (ColHandles) referenced by this CellRange
|
protected Condfmt |
getConditionalFormat()
returns the conditional format object for this range, if any
|
int[] |
getCoords()
Gets the coordinates of this cell range,
|
boolean |
getCreateBlanks()
gets whether this CellRange will add blank records to the WorkBook for any
missing Cells contained within the range.
|
int[] |
getEdgePositions(CellHandle ch,
int sz)
returns edge status of the desired CellHandle within this CellRange ie: top,
left, bottom, right
returns 0 or 1 for 4 sides 1,1,1,1 is a single cell in a range 1,1,0,0 is on the top left edge of the range |
int |
getHeight()
Gets the number of rows in the range.
|
int |
getIncrementAmount()
If the cells contain an incrementing value that can be transferred into an
int, then return that value, else throw a NPE.
|
org.json.JSONObject |
getJSON()
Return a json object representing this cell range with full cell information
embedded.
|
int |
getNumberOfCols()
Get the number of columns that this CellRange encompasses
|
int |
getNumberOfRows()
Get the number of rows that this CellRange encompasses
|
String |
getR1C1Range()
Return the String cell address of this range in R1C1 format
|
String |
getRange()
Return the String representation of this range
|
int[] |
getRangeCoords()
Deprecated.
getCoords() instead, which returns zero based values for
rows. |
int[] |
getRowInts()
Returns an array of the row numbers referenced by this CellRange
|
RowHandle[] |
getRows()
Returns an array of Rows (RowHandles) referenced by this CellRange
|
WorkSheetHandle |
getSheet()
Returns the WorkSheet referenced in this CellRange.
|
static org.json.JSONArray |
getValuesAsJSON(String range,
WorkBook wbh)
return a JSON array of cell values for the given range
static version |
int |
getWidth()
Gets the number of columns in the range.
|
WorkBook |
getWorkBook() |
String |
getXML()
Return the XML representation of this CellRange object
|
void |
init()
initializes this CellRange
|
void |
initCells(boolean createBlanks)
Initializes this
CellRange's cell list if necessary. |
boolean |
intersects(CellRange cr)
returns whether this CellRange intersects with another CellRange
|
boolean |
isMerged()
returns the merged state of the CellRange
|
void |
mergeCells(boolean remove)
Merge the Cells contained in this CellRange
|
void |
removeBorder()
removes the border from all of the cells in this range
|
void |
removeCells()
removes the cells referenced by this range from the sheet.
|
void |
setAsPrintArea()
Set this CellRange to be the current Print Area
|
void |
setBorder(int width,
int linestyle,
Color colr)
sets a border around the range of cells
|
void |
setCreateBlanks(boolean b)
set whether this CellRange will add blank records to the WorkBook for any
missing Cells contained within the range.
|
void |
setFormatID(int fmtID)
Set the format ID of all cells in this CellRange
FormatID can be obtained through any CellHandle with the getFormatID() call |
void |
setInnerBorderBottom(int linestyle,
Color colr)
Sets a bottom border on all cells in the cellrange
Linestyle should be set through the FormatHandle constants
|
void |
setInnerBorderLeft(int linestyle,
Color colr)
Sets a left border on all cells in the cellrange
Linestyle should be set through the FormatHandle constants
|
void |
setInnerBorderRight(int linestyle,
Color colr)
Sets a right border on all cells in the cellrange
Linestyle should be set through the FormatHandle constants
|
void |
setInnerBorderSurround(int linestyle,
Color colr)
Sets a surround border on all cells in the cellrange
Linestyle should be set through the FormatHandle constants
|
void |
setInnerBorderTop(int linestyle,
Color colr)
Sets a top border on all cells in the cellrange
Linestyle should be set through the FormatHandle constants
|
void |
setParent(BiffRec b)
sets the parent of this Cell range
Used Internally. |
void |
setRange(String rng)
Sets the range of cells for this CellRange to a string range
|
void |
setSheet(WorkSheetHandle aSheet)
Sets the sheet reference for this CellRange.
|
void |
setURL(String url)
Set a hyperlink on all cells in this CellRange
|
void |
setWorkBook(WorkBook bk)
attach the workbook for this CellRange
|
void |
sort(int rownumber,
boolean ascending)
Resort all cells in the range according to the rownumber passed in.
|
void |
sort(int rownumber,
Comparator<CellHandle> comparator,
boolean ascending)
Re-sort all cells in this cell range according to the column.
|
void |
sort(String columnName,
boolean ascending)
Resort all cells in the range according to the column passed in.
|
void |
sort(String columnName,
Comparator comparator,
boolean ascending)
Re-sort all cells in this cell range according to the column.
|
String |
toString()
returns the String representation of this CellRange
|
void |
unMergeCells()
Un-Merge the Cells contained in this CellRange
|
boolean |
update()
update the CellRange when the underlying Cells change their location
|
public static final boolean REMOVE_MERGED_CELLS
public static final boolean RETAIN_MERGED_CELLS
public boolean DEBUG
public transient CellHandle[] cells
protected transient String range
protected transient String sheetname
protected transient WorkBook mybook
protected int externalLink1
protected int externalLink2
public static String xmlResponsePre
public static String xmlResponsePost
public static final int COPY_CONTENTS
public static final int COPY_FORMULAS
public static final int COPY_FORMATS
protected CellRange(WorkSheetHandle sheet, int row, int col, int width, int height)
public CellRange(CellRangeRef source, boolean init, boolean create)
CellRange from a CellRangeRef. The
source CellRangeRef instance must be qualified with a single
resolved worksheet.source - the CellRangeRef from which to initializeinit - whether to populate the cell arraycreate - whether to fill gaps in the range with blank cellsIllegalArgumentException - if the source range does not have a resolved sheet or has more
than one sheetpublic CellRange(CellRangeRef source)
CellRange from a CellRangeRef. The
source CellRangeRef instance must be qualified with a single
resolved worksheet.source - the CellRangeRef from which to initializeIllegalArgumentException - if the source range does not have a resolved sheet or has more
than one sheetpublic CellRange(WorkSheetHandle sht, int[] coords, boolean cb) throws Exception
WorkSheetHandle - sht - handle to the WorkSheet containing the Range's Cellsint[] - coords - the cell coordinatesboolean - cb - true if should create blank cellsExceptionpublic CellRange(WorkSheetHandle sht, int[] coords) throws Exception
WorkSheetHandle - sht - handle to the WorkSheet containing the Range's Cellsint[] - coords - the cell coordinatesExceptionpublic CellRange(String r)
String - r - range StringCellRange.setWorkBookpublic CellRange(String range, WorkBook bk, boolean createblanks, boolean initcells)
String - range - the range stringWorkBook - bkboolean - createblanks - true if blank cells should be created if necessaryboolean - initcells - true if cells should (be initialized)public CellRange(String range, WorkBook bk, boolean c)
String - range - the range stringWorkBook - bkboolean - createblanks - true if blank cells should be created (if
necessary)public CellRange(CellHandle[] newcells) throws CellNotFoundException
CellHandle[] - newcells - the array of cells from which to create the new
CellRangeCellNotFoundExceptionpublic CellRange(CellHandle[] newcells, boolean createblanks) throws CellNotFoundException
CellHandle[] - newcells - the array of cells from which to create the new
CellRangeboolean - createblanks - true if should create blank cells if necesaryCellNotFoundExceptionpublic CellRange(String range, WorkBook bk) throws CellNotFoundException
String - range - the range stringWorkBook - bkCellNotFoundExceptionprotected Condfmt getConditionalFormat()
public void clearFormats()
@Deprecated public void clearContents()
public void clear()
public void removeCells()
public void unMergeCells()
throws Exception
Exceptionpublic void setFormatID(int fmtID)
throws Exception
int - fmtID - the format ID to set the cells within the range toExceptionpublic void setURL(String url) throws Exception
String - url - the URL String to setExceptionpublic void mergeCells(boolean remove)
boolean - remove - true to delete the Cells following the first in the rangepublic int getWidth()
public int getHeight()
public int[] getRowInts()
public int[] getColInts()
public RowHandle[] getRows() throws RowNotFoundException
RowNotFoundExceptionpublic int getNumberOfRows()
public ColHandle[] getCols() throws ColumnNotFoundException
ColumnNotFoundExceptionpublic int getNumberOfCols()
public int[] getEdgePositions(CellHandle ch, int sz)
CellHandle - ch -int - sz -public boolean intersects(CellRange cr)
CellRange - cr - CellRange to testpublic boolean contains(Cell cxx)
CellHandle - ch - the Cell to checkpublic boolean contains(int[] rc)
int[] - rc - row/col coordinates to testpublic String toString()
public void setAsPrintArea()
public boolean addCellToRange(CellHandle ch)
CellHandle - ch - the Cell to add to the CellRangepublic CellHandle[] getCells()
public List<CellHandle> getCellList()
public BiffRec[] getCellRecs()
public int getIncrementAmount()
throws Exception
Exceptionpublic void setParent(BiffRec b)
b - public void sort(int rownumber,
Comparator<CellHandle> comparator,
boolean ascending)
throws RowNotFoundException
rowNumber - the 0 based (row 5 = 4) number of the row to be sorted uponcomparator - RowNotFoundExceptionColumnNotFoundExceptionpublic void sort(int rownumber,
boolean ascending)
throws RowNotFoundException
rownumber - the 0 based row numberascending - RowNotFoundExceptionColumnNotFoundExceptionpublic void sort(String columnName, Comparator comparator, boolean ascending) throws ColumnNotFoundException
columnName - comparator - RowNotFoundExceptionColumnNotFoundExceptionpublic void sort(String columnName, boolean ascending) throws ColumnNotFoundException
columnName - ascending - ColumnNotFoundExceptionRowNotFoundExceptionpublic String getXML()
public String getCellRangeXML(boolean fragment)
fragment - whether to enclose result in NameHandle tagpublic String getCellRangeXML()
fragment - whether to enclose result in NameHandle tagpublic void setWorkBook(WorkBook bk)
WorkBook - bkpublic int[] getCoords()
throws CellNotFoundException
CellNotFoundException@Deprecated public int[] getRangeCoords() throws CellNotFoundException
getCoords() instead, which returns zero based values for
rows.CellNotFoundExceptionpublic WorkSheetHandle getSheet()
public void init()
throws CellNotFoundException
CellNotFoundExceptionpublic void initCells(boolean createBlanks)
CellRange's cell list if necessary. This method
is useful if this CellRange was created with
initCells set to false and it is later necessary to
retrieve the cell list.createBlanks - whether missing cells should be created as blanks. If this is
false they will appear in the cell list as
nulls.public WorkBook getWorkBook()
public boolean getCreateBlanks()
public void setCreateBlanks(boolean b)
boolean - b - true if should create blank records for missing Cellspublic String getRange()
public String getR1C1Range()
public void setRange(String rng)
String - rng - Range stringpublic void setBorder(int width,
int linestyle,
Color colr)
int - width - line widthint - linestyle - line stylejava.awt.Color - colr - color of border linepublic boolean update()
public boolean isMerged()
public void setSheet(WorkSheetHandle aSheet)
WorkSheetHandle - aSheetpublic CellRange copy(WorkSheetHandle sheet, int row, int col, int what)
row - the topmost row of the target areacol - the leftmost column of the target areawhat - a set of flags determining what will be copiedpublic void fill(CellHandle source, int what, double increment)
source - the cell whose attributes should be copied or null to
copy from the first cell in the rangewhat - a set of flags determining what will be copiedincrement - the amount by which to increment numeric values or
NaN for no incrementpublic Collection<CellHandle> calculateAffectedCellsOnSheet()
public static org.json.JSONArray getValuesAsJSON(String range, WorkBook wbh)
String - range - a string representation of the desired range of cellsWorkBook - wbh - the source WorkBook for the cell rangepublic org.json.JSONObject getBasicJSON()
range - wbh - public org.json.JSONObject getJSON()
public ArrayList<CellHandle> getCellsByRow(int rownumber) throws RowNotFoundException
rownumber - RowNotFoundExceptionpublic ArrayList<CellHandle> getCellsByCol(String col) throws ColumnNotFoundException
rownumber - ColumnNotFoundExceptionpublic static CellHandle[] getCells(String range, WorkBookHandle wbh)
String - range - a string representation of the desired range of cellsWorkBook - wbh - the source WorkBook for the cell rangepublic void removeBorder()
public void setInnerBorderBottom(int linestyle,
Color colr)
public void setInnerBorderRight(int linestyle,
Color colr)
public void setInnerBorderLeft(int linestyle,
Color colr)
public void setInnerBorderTop(int linestyle,
Color colr)
public void setInnerBorderSurround(int linestyle,
Color colr)
Copyright © 2002–2019 Starter Inc.. All rights reserved.