Encapsulates the object that represents a range of cells within a spreadsheet.
Example:
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get the first Worksheet Cells.
Cells cells = workbook.getWorksheets().get(0).getCells();
// Create a range (A1:D3).
Range range = cells.createRange("A1", "D3");
// Set value to the range.
range.setValue("Hello");
//Save the Excel file
workbook.save("book1.xlsm");
Returns a Range object that represents the current region.
The current region is a range bounded by any combination of blank rows and blank columns.
getHyperlinks
public com.aspose.cells.Hyperlink[] getHyperlinks()
Gets all hyperlink in the range.
getRowCount
public int getRowCount()
Gets the count of rows in the range.
getColumnCount
public int getColumnCount()
Gets the count of columns in the range.
getCellCount
public int getCellCount()
Gets all cell count in the range.
NOTE: This property is now obsolete.
Instead, please use RowCount and ColumnCount to get total cells count.
This property will be removed 12 months later since February 2021.
Aspose apologizes for any inconvenience you may have experienced.
getName/setName
public java.lang.String getName() / public void setName(java.lang.String value)
Gets or sets the name of the range.
Named range is supported. For example,
range.Name = "Sheet1!MyRange";
getRefersTo
public java.lang.String getRefersTo()
Gets the range's refers to.
getAddress
public java.lang.String getAddress()
Gets address of the range.
getLeft
public double getLeft()
Gets the distance, in points, from the left edge of column A to the left edge of the range.
getTop
public double getTop()
Gets the distance, in points, from the top edge of row 1 to the top edge of the range.
getWidth
public double getWidth()
Gets the width of a range in points.
getHeight
public double getHeight()
Gets the width of a range in points.
getFirstRow
public int getFirstRow()
Gets the index of the first row of the range.
getFirstColumn
public int getFirstColumn()
Gets the index of the first column of the range.
getValue/setValue
public java.lang.Object getValue() / public void setValue(java.lang.Object value)
Gets and sets the value of the range.
If the range contains multiple cells, return a two-dimension System.Array object.
If applies object array to the range, it should be a two-dimension System.Array object.
getColumnWidth/setColumnWidth
public double getColumnWidth() / public void setColumnWidth(double value)
Sets or gets the column width of this range
getRowHeight/setRowHeight
public double getRowHeight() / public void setRowHeight(double value)
public void autoFill(Range target)
throws java.lang.Exception
Automaticall fill the target range.
Parameters:
target - the target range.
Example:
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get the first Worksheet Cells.
Cells cells = workbook.getWorksheets().get(0).getCells();
cells.get("A1").putValue(1);
cells.get("A2").putValue(2);
Range source = cells.createRange("A1:A2");
Range target = cells.createRange("A3:A10");
//fill 3,4,5....10 to the range A3:A10
source.autoFill(target);
//Save the Excel file
workbook.save("book1.xlsm");
autoFill
public void autoFill(Range target, int autoFillType)
throws java.lang.Exception
Automaticall fill the target range.
Parameters:
target - The targed range.
autoFillType - A AutoFillType value. The auto fill type.
iterator
public java.util.Iterator iterator()
Gets the enumerator for cells in this Range.
When traversing elements by the returned Enumerator, the cells collection
should not be modified(such as operations that will cause new Cell/Row be instantiated or existing Cell/Row be deleted).
Otherwise the enumerator may not be able to traverse all cells correctly(some elements may be traversed repeatedly or skipped).
Returns:
The cells enumerator
Example:
Workbook workbook = new Workbook("template.xlsx");
Cells cells = workbook.getWorksheets().get(0).getCells();
Iterator en = cells.createRange("B2:C3").iterator();
while (en.hasNext())
{
Cell cell = (Cell)en.next();
System.out.println(cell.getName() + ": " + cell.getValue());
}
Returns a Range object that represents the rectangular intersection of two ranges.
If the two ranges are not intersected, returns null.
Parameters:
range - The intersecting range.
Returns:
Returns a Range object
Example:
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get the first Worksheet Cells.
Cells cells = workbook.getWorksheets().get(0).getCells();
Range range1 = cells.createRange("A1:A5");
Range range2 = cells.createRange("A3:A10");
//Get intersected range of the two ranges.
Range intersectRange = range1.intersect(range2);
//Save the Excel file
workbook.save("book1.xlsm");
Applies formats for a whole range.
Each cell in this range will contains a Style object.
So this is a memory-consuming method. Please use it carefully.
Parameters:
style - The style object which will be applied.
flag - Flags which indicates applied formatting properties.
public void setOutlineBorders(int[] borderStyles, com.aspose.cells.Color[] borderColors)
Sets out line borders around a range of cells.
Both the length of borderStyles and borderStyles must be 4.
The order of borderStyles and borderStyles must be top,bottom,left,right
Parameters:
borderStyles - Border styles.
borderColors - Border colors.
setOutlineBorder
public void setOutlineBorder(int borderEdge, int borderStyle, com.aspose.cells.Color borderColor)
public void copy(Range range, PasteOptions options)
throws java.lang.Exception
Copying the range with paste special options.
Parameters:
range - The source range.
options - The paste special options.
copy
public void copy(Range range)
throws java.lang.Exception
Copies data (including formulas), formatting, drawing objects etc. from a source range.
Parameters:
range - Source Range object.
Example:
//Instantiating a Workbook object
Workbook workbook = new Workbook();
// Get the first Worksheet Cells.
Cells cells = workbook.getWorksheets().get(0).getCells();
Range range1 = cells.createRange("A1:A5");
Range range2 = cells.createRange("A6:A10");
//Copy the range.
range1.copy(range2);
//Save the Excel file
workbook.save("book1.xlsm");
getCellOrNull
public CellgetCellOrNull(int rowOffset, int columnOffset)