public class Row
extends java.lang.Object
implements java.lang.Iterable
Example
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
Style style = workbook.createStyle();
//Setting the background color to Blue
style.setBackgroundColor(Color.getBlue());
//Setting the foreground color to Red
style.setForegroundColor(Color.getRed());
//setting Background Pattern
style.setPattern(BackgroundType.DIAGONAL_STRIPE);
//New Style Flag
StyleFlag styleFlag = new StyleFlag();
//Set All Styles
styleFlag.setAll(true);
//Get first row
Row row = worksheet.getCells().getRows().get(0);
//Apply Style to first row
row.applyStyle(style, styleFlag);
//Saving the Excel file
workbook.save("book1.xls");
| Modifier and Type | Method and Description |
|---|---|
void |
applyStyle(Style style,
StyleFlag flag)
Applies formats for a whole row.
|
void |
copySettings(Row source,
boolean checkStyle)
Copy settings of row, such as style, height, visibility, ...etc.
|
boolean |
equals(java.lang.Object obj)
Checks whether this object refers to the same row with another.
|
boolean |
equals(Row row)
Checks whether this object refers to the same row with another row object.
|
Cell |
get(int column)
Gets the cell.
|
Cell |
getCellByIndex(int index)
Get the cell by specific index in the cells collection of this row.
|
Cell |
getCellOrNull(int column)
Gets the cell or null in the specific index.
|
Cell |
getFirstCell()
Gets the first cell object in the row.
|
Cell |
getFirstDataCell()
Gets the first non-blank cell in the row.
|
byte |
getGroupLevel()
Gets the group level of the row.
|
double |
getHeight()
Gets the row height in unit of Points.
|
int |
getIndex()
Gets the index of this row.
|
Cell |
getLastCell()
Gets the last cell object in the row.
|
Cell |
getLastDataCell()
Gets the last non-blank cell in the row.
|
Style |
getStyle()
Gets the style of this row.
|
boolean |
hasCustomStyle()
Indicates whether this row has custom style settings(different from the default one inherited from workbook).
|
boolean |
isBlank()
Indicates whether the row contains any data
|
boolean |
isCollapsed()
whether the row is collapsed
|
boolean |
isHeightMatched()
Indicates whether the row height matches current default font setting of the workbook.
|
boolean |
isHidden()
Indicates whether the row is hidden.
|
java.util.Iterator |
iterator()
Gets the cells enumerator
|
java.util.Iterator |
iterator(boolean reversed,
boolean sync)
Gets an enumerator that iterates cells through this row.
|
void |
setCollapsed(boolean value)
whether the row is collapsed
|
void |
setGroupLevel(byte value)
Gets the group level of the row.
|
void |
setHeight(double value)
Sets the row height in unit of Points.
|
void |
setHeightMatched(boolean value)
Indicates whether the row height matches current default font setting of the workbook.
|
void |
setHidden(boolean value)
Indicates whether the row is hidden.
|
void |
setStyle(Style style)
Sets the style of this row.
|
public Cell getCellByIndex(int index)
Remarks
To traverse all cells in sequence without modification, usingiterator() will give better performance than using this method to get cell one by one.index - The index(position) of the cell in the cells collection of this row.public boolean isBlank()
public Cell get(int column)
column - The column indexpublic java.util.Iterator iterator()
Example
Workbook workbook = new Workbook("template.xlsx");
Cells cells = workbook.getWorksheets().get(0).getCells();
Iterator en = cells.getRows().get(1).iterator();
while (en.hasNext())
{
Cell cell = (Cell)en.next();
System.out.println(cell.getName() + ": " + cell.getValue());
}
iterator in interface java.lang.Iterablepublic java.util.Iterator iterator(boolean reversed,
boolean sync)
Remarks
If the row will be modified(by operations that may cause new Cell be instantiated or existing Cell be removed) during the traversal with the enumerator, synchronized enumerator should be used instead of normal enumerator so that the traversal can continue from the position just after the one has been traversed by the last MoveNext(). However, together with the advantage that no element be skipped or traversed repeatedly, the disadvantage for synchronized enumerator is that the performance will be degraded a bit when comparing with normal enumerator.reversed - whether enumerate cells in reversed ordersync - whether the returned enumerator should check the modification of cells in this row
and keep synchronized with it.public Cell getCellOrNull(int column)
column - The column indexpublic boolean isCollapsed()
public void setCollapsed(boolean value)
public double getHeight()
public void setHeight(double value)
public boolean isHidden()
public void setHidden(boolean value)
public int getIndex()
public byte getGroupLevel()
public void setGroupLevel(byte value)
public boolean isHeightMatched()
Remarks
When this property is true, if the content in this row changes, generally the row height needs to be re-calculated(such as byWorksheet.autoFitRows())
to get the same result with what is shown in ms excel when you opening the workbook in it.public void setHeightMatched(boolean value)
Remarks
When this property is true, if the content in this row changes, generally the row height needs to be re-calculated(such as byWorksheet.autoFitRows())
to get the same result with what is shown in ms excel when you opening the workbook in it.public Style getStyle()
Remarks
Modifying the returned style object directly takes no effect for this row or any cells in this row. You have to callColumn.applyStyle(Style,StyleFlag) or Column.setStyle(Style) method
to apply the change to this row.public void setStyle(Style style)
Remarks
This method only sets the given style as the default style for this row, without changing the style settings for existing cells in this row. To update style settings of existing cells to the specified style at the same time, please useColumn.applyStyle(Style,StyleFlag)style - the style to be used as the default style for cells in this row.public boolean hasCustomStyle()
public void copySettings(Row source, boolean checkStyle)
source - the source row whose settings will be copied to this onecheckStyle - whether check and gather style.
Only takes effect and be needed when two row objects belong to different workbook and the styles of two workbooks are different.public Cell getFirstCell()
public Cell getFirstDataCell()
public Cell getLastCell()
public Cell getLastDataCell()
public void applyStyle(Style style, StyleFlag flag)
style - The style object which will be applied.flag - Flags which indicates applied formatting properties.public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - another objectpublic boolean equals(Row row)
row - another row objectSee Also:
Aspose.Cells Documentation - the home page for the Aspose.Cells Product Documentation.
Aspose.Cells Support Forum - our preferred method of support.
We guarantee a prompt response to any inquiry!
© Aspose Pty Ltd 2003-2025. All Rights Reserved.