Row

Inheritance: java.lang.Object

All Implemented Interfaces: java.lang.Iterable

public class Row implements Iterable

Represents a single row in a worksheet.

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");

Methods

MethodDescription
applyStyle(Style style, StyleFlag flag)Applies formats for a whole row.
copySettings(Row source, boolean checkStyle)Copy settings of row, such as style, height, visibility, …etc.
equals(Row row)Checks whether this object refers to the same row with another row object.
equals(Object obj)Checks whether this object refers to the same row with another.
get(int column)Gets the cell.
getCellByIndex(int index)Get the cell by specific index in the cells collection of this row.
getCellOrNull(int column)Gets the cell or null in the specific index.
getClass()
getFirstCell()Gets the first cell object in the row.
getFirstDataCell()Gets the first non-blank cell in the row.
getGroupLevel()Gets the group level of the row.
getHeight()Gets the row height in unit of Points.
getIndex()Gets the index of this row.
getLastCell()Gets the last cell object in the row.
getLastDataCell()Gets the last non-blank cell in the row.
getStyle()Gets the style of this row.
hasCustomStyle()Indicates whether this row has custom style settings(different from the default one inherited from workbook).
hashCode()
isBlank()Indicates whether the row contains any data
isCollapsed()whether the row is collapsed
isHeightMatched()Indicates whether the row height matches current default font setting of the workbook.
isHidden()Indicates whether the row is hidden.
iterator()Gets the cells enumerator
iterator(boolean reversed, boolean sync)Gets an enumerator that iterates cells through this row.
notify()
notifyAll()
setCollapsed(boolean value)whether the row is collapsed
setGroupLevel(byte value)Gets the group level of the row.
setHeight(double value)Sets the row height in unit of Points.
setHeightMatched(boolean value)Indicates whether the row height matches current default font setting of the workbook.
setHidden(boolean value)Indicates whether the row is hidden.
setStyle(Style style)Sets the style of this row.
toString()
wait()
wait(long arg0)
wait(long arg0, int arg1)

applyStyle(Style style, StyleFlag flag)

public void applyStyle(Style style, StyleFlag flag)

Applies formats for a whole row.

Parameters:

ParameterTypeDescription
styleStyleThe style object which will be applied.
flagStyleFlagFlags which indicates applied formatting properties.

copySettings(Row source, boolean checkStyle)

public void copySettings(Row source, boolean checkStyle)

Copy settings of row, such as style, height, visibility, …etc.

Parameters:

ParameterTypeDescription
sourceRowthe source row whose settings will be copied to this one
checkStylebooleanwhether 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.

equals(Row row)

public boolean equals(Row row)

Checks whether this object refers to the same row with another row object.

Parameters:

ParameterTypeDescription
rowRowanother row object

Returns: boolean - true if two row objects refers to the same row.

equals(Object obj)

public boolean equals(Object obj)

Checks whether this object refers to the same row with another.

Parameters:

ParameterTypeDescription
objjava.lang.Objectanother object

Returns: boolean - true if two objects refers to the same row.

get(int column)

public Cell get(int column)

Gets the cell.

Parameters:

ParameterTypeDescription
columnintThe column index

Returns: Cell -

getCellByIndex(int index)

public Cell getCellByIndex(int index)

Get the cell by specific index in the cells collection of this row.

Remarks

To traverse all cells in sequence without modification, using iterator() will give better performance than using this method to get cell one by one.

Parameters:

ParameterTypeDescription
indexintThe index(position) of the cell in the cells collection of this row.

Returns: Cell - The Cell object at given position.

getCellOrNull(int column)

public Cell getCellOrNull(int column)

Gets the cell or null in the specific index.

Parameters:

ParameterTypeDescription
columnintThe column index

Returns: Cell - Returns the cell object if the cell exists. Or returns null if the cell object does not exist.

getClass()

public final native Class<?> getClass()

Returns: java.lang.Class

getFirstCell()

public Cell getFirstCell()

Gets the first cell object in the row.

Returns: Cell

getFirstDataCell()

public Cell getFirstDataCell()

Gets the first non-blank cell in the row.

Returns: Cell

getGroupLevel()

public byte getGroupLevel()

Gets the group level of the row.

Returns: byte

getHeight()

public double getHeight()

Gets the row height in unit of Points.

Returns: double

getIndex()

public int getIndex()

Gets the index of this row.

Returns: int

getLastCell()

public Cell getLastCell()

Gets the last cell object in the row.

Returns: Cell

getLastDataCell()

public Cell getLastDataCell()

Gets the last non-blank cell in the row.

Returns: Cell

getStyle()

public Style getStyle()

Gets the style of this row.

Remarks

Modifying the returned style object directly takes no effect for this row or any cells in this row. You have to call Column.applyStyle(Style,StyleFlag) or Column.setStyle(Style) method to apply the change to this row.

Row’s style is the style which will be inherited by cells in this row(those cells that have no custom style settings, such as existing cells that have not been set style explicitly, or those that have not been instantiated)

Returns: Style

hasCustomStyle()

public boolean hasCustomStyle()

Indicates whether this row has custom style settings(different from the default one inherited from workbook).

Returns: boolean

hashCode()

public native int hashCode()

Returns: int

isBlank()

public boolean isBlank()

Indicates whether the row contains any data

Returns: boolean

isCollapsed()

public boolean isCollapsed()

whether the row is collapsed

Returns: boolean

isHeightMatched()

public boolean isHeightMatched()

Indicates whether the row height matches current default font setting of the workbook. True of this property also denotes the row height is “automatic” without custom height value set by user.

Remarks

When this property is true, if the content in this row changes, generally the row height needs to be re-calculated(such as by Worksheet.autoFitRows()) to get the same result with what is shown in ms excel when you opening the workbook in it.

Returns: boolean

isHidden()

public boolean isHidden()

Indicates whether the row is hidden.

Returns: boolean

iterator()

public Iterator iterator()

Gets the cells enumerator

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());
         	}

Returns: java.util.Iterator - The cells enumerator

iterator(boolean reversed, boolean sync)

public Iterator iterator(boolean reversed, boolean sync)

Gets an enumerator that iterates cells through this row.

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.

Parameters:

ParameterTypeDescription
reversedbooleanwhether enumerate cells in reversed order
syncbooleanwhether the returned enumerator should check the modification of cells in this row and keep synchronized with it.

Returns: java.util.Iterator - The cell enumerator

notify()

public final native void notify()

notifyAll()

public final native void notifyAll()

setCollapsed(boolean value)

public void setCollapsed(boolean value)

whether the row is collapsed

Parameters:

ParameterTypeDescription
valueboolean

setGroupLevel(byte value)

public void setGroupLevel(byte value)

Gets the group level of the row.

Parameters:

ParameterTypeDescription
valuebyte

setHeight(double value)

public void setHeight(double value)

Sets the row height in unit of Points.

Parameters:

ParameterTypeDescription
valuedouble

setHeightMatched(boolean value)

public void setHeightMatched(boolean value)

Indicates whether the row height matches current default font setting of the workbook. True of this property also denotes the row height is “automatic” without custom height value set by user.

Remarks

When this property is true, if the content in this row changes, generally the row height needs to be re-calculated(such as by Worksheet.autoFitRows()) to get the same result with what is shown in ms excel when you opening the workbook in it.

Parameters:

ParameterTypeDescription
valueboolean

setHidden(boolean value)

public void setHidden(boolean value)

Indicates whether the row is hidden.

Parameters:

ParameterTypeDescription
valueboolean

setStyle(Style style)

public void setStyle(Style style)

Sets the style of this row.

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 use Column.applyStyle(Style,StyleFlag)

Parameters:

ParameterTypeDescription
styleStylethe style to be used as the default style for cells in this row.

toString()

public String toString()

Returns: java.lang.String

wait()

public final void wait()

wait(long arg0)

public final native void wait(long arg0)

Parameters:

ParameterTypeDescription
arg0long

wait(long arg0, int arg1)

public final void wait(long arg0, int arg1)

Parameters:

ParameterTypeDescription
arg0long
arg1int