Top Description Fields Constructors Methods
org.apache.poi.ss.util

public Class SheetBuilder

extends Object
Class Inheritance
Imports
java.util.Calendar, .Date, org.apache.poi.ss.usermodel.Sheet, .Workbook, .Row, .Cell

Class SheetBuilder provides an easy way of building workbook sheets from 2D array of Objects. It can be used in test cases to improve code readability or in Swing applications with tables.

Field Summary

Modifier and TypeField and Description
private final Object[][]
private String
private boolean
private final Workbook

Constructor Summary

AccessConstructor and Description
public
SheetBuilder(Workbook workbook, Object[][] cells)

Method Summary

Modifier and TypeMethod and Description
public Sheet

Returns:

newly created sheet
build
()

Builds sheet from parent workbook and 2D array with cell values.

public boolean

Returns:

true if null objects should be treated as empty cells and false otherwise
getCreateEmptyCells
()

Returns true if null array elements should be treated as empty cells.

private String
private boolean
private void
setCellValue(Cell
cell to change
cell
,
Object
value to set
value
)

Sets the cell value using object type information.

public SheetBuilder

Returns:

this
setCreateEmptyCells
(boolean
true if null array elements should be treated as empty cells
shouldCreateEmptyCells
)

Specifies if null array elements should be treated as empty cells.

public SheetBuilder

Returns:

this
setSheetName
(String
sheet name to use
sheetName
)

Specifies name of the sheet to build.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cellsback to summary
private final Object[][] cells
sheetNameback to summary
private String sheetName
shouldCreateEmptyCellsback to summary
private boolean shouldCreateEmptyCells
workbookback to summary
private final Workbook workbook

Constructor Detail

SheetBuilderback to summary
public SheetBuilder(Workbook workbook, Object[][] cells)

Method Detail

buildback to summary
public Sheet build()

Builds sheet from parent workbook and 2D array with cell values. Creates rows anyway (even if row contains only null cells), creates cells if either corresponding array value is not null or createEmptyCells property is true. The conversion is performed in the following way:

  • Numbers become numeric cells.
  • java.util.Date or java.util.Calendar instances become date cells.
  • String with leading '=' char become formulas (leading '=' will be truncated).
  • Other objects become strings via Object.toString() method call.
Returns:Sheet

newly created sheet

getCreateEmptyCellsback to summary
public boolean getCreateEmptyCells()

Returns true if null array elements should be treated as empty cells.

Returns:boolean

true if null objects should be treated as empty cells and false otherwise

getFormulaback to summary
private String getFormula(Object obj)
isFormulaDefinitionback to summary
private boolean isFormulaDefinition(Object obj)
setCellValueback to summary
private void setCellValue(Cell cell, Object value)

Sets the cell value using object type information.

Parameters
cell:Cell

cell to change

value:Object

value to set

setCreateEmptyCellsback to summary
public SheetBuilder setCreateEmptyCells(boolean shouldCreateEmptyCells)

Specifies if null array elements should be treated as empty cells.

Parameters
shouldCreateEmptyCells:boolean

true if null array elements should be treated as empty cells

Returns:SheetBuilder

this

setSheetNameback to summary
public SheetBuilder setSheetName(String sheetName)

Specifies name of the sheet to build. If not specified, default name (provided by workbook) will be used instead.

Parameters
sheetName:String

sheet name to use

Returns:SheetBuilder

this