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

public final Class PropertyTemplate

extends Object
Class Inheritance
Imports
java.util.HashMap, .HashSet, .Map, .Set, org.apache.poi.hssf.usermodel.HSSFWorkbook, org.apache.poi.ss.SpreadsheetVersion, org.apache.poi.ss.usermodel.BorderExtent, .BorderStyle, .Cell, .IndexedColors, .Row, .Sheet, .Workbook

A PropertyTemplate is a template that can be applied to any sheet in a project. It contains all the border type and color attributes needed to draw all the borders for a single sheet. That template can be applied to any sheet in any workbook. This class requires the full spreadsheet to be in memory, so org.apache.poi.xssf.streaming.SXSSFWorkbook Spreadsheets are not supported. The same PropertyTemplate can, however, be applied to both HSSFWorkbook and org.apache.poi.xssf.usermodel.XSSFWorkbook objects if necessary. Portions of the border that fall outside the max range of the Workbook sheet are ignored.

This would replace RegionUtil.

Field Summary

Modifier and TypeField and Description
private final Map<CellAddress, Map<String, Object>>
_propertyTemplate

This is a list of cell properties for one shot application to a range of cells at a later time.

Constructor Summary

AccessConstructor and Description
public
PropertyTemplate()

Create a PropertyTemplate object

public
PropertyTemplate(PropertyTemplate
a PropertyTemplate object
template
)

Create a PropertyTemplate object from another PropertyTemplate

Method Summary

Modifier and TypeMethod and Description
private void
addProperty(int row, int col, String property, short value)

Adds a property to this PropertyTemplate for a given cell

private void
addProperty(int row, int col, String property, Object value)

Adds a property to this PropertyTemplate for a given cell

public void
applyBorders(Sheet
- Sheet on which to apply borders
sheet
)

Applies the drawn borders to a Sheet.

private static Map<String, Object>
public void
drawBorderColors(CellRangeAddress
- CellRangeAddress range of cells on which colors are set.
range
,
short
- Color index from IndexedColors used to draw the borders.
color
,
BorderExtent
- BorderExtent of the borders for which colors are set.
extent
)

Sets the color for a group of cell borders for a cell range.

public void
drawBorders(CellRangeAddress
- CellRangeAddress range of cells on which borders are drawn.
range
,
BorderStyle
- Type of border to draw. BorderStyle.
borderType
,
BorderExtent
- BorderExtent of the borders to be applied.
extent
)

Draws a group of cell borders for a cell range.

public void
drawBorders(CellRangeAddress
- CellRangeAddress range of cells on which borders are drawn.
range
,
BorderStyle
- Type of border to draw. BorderStyle.
borderType
,
short
- Color index from IndexedColors used to draw the borders.
color
,
BorderExtent
- BorderExtent of the borders to be applied.
extent
)

Draws a group of cell borders for a cell range.

private void
drawBottomBorder(CellRangeAddress
- CellRangeAddress range of cells on which borders are drawn.
range
,
BorderStyle
- Type of border to draw. BorderStyle.
borderType
)

Draws the bottom border for a range of cells

private void
drawBottomBorderColor(CellRangeAddress
- CellRangeAddress range of cells on which colors are set.
range
,
short
- Color index from IndexedColors used to draw the borders.
color
)

Sets the color of the bottom border for a range of cells.

private void
drawHorizontalBorderColors(CellRangeAddress
- CellRangeAddress range of cells on which colors are set.
range
,
short
- Color index from IndexedColors used to draw the borders.
color
,
BorderExtent
- BorderExtent of the borders for which colors are set. Valid Values are:
  • BorderExtent.ALL
  • BorderExtent.INSIDE
extent
)

Sets the color of the horizontal borders for a range of cells.

private void
drawHorizontalBorders(CellRangeAddress
- CellRangeAddress range of cells on which borders are drawn.
range
,
BorderStyle
- Type of border to draw. BorderStyle.
borderType
,
BorderExtent
- BorderExtent of the borders to be applied. Valid Values are:
  • BorderExtent.ALL
  • BorderExtent.INSIDE
extent
)

Draws the horizontal borders for a range of cells.

private void
drawLeftBorder(CellRangeAddress
- CellRangeAddress range of cells on which borders are drawn.
range
,
BorderStyle
- Type of border to draw. BorderStyle.
borderType
)

Draws the left border for a range of cells

private void
drawLeftBorderColor(CellRangeAddress
- CellRangeAddress range of cells on which colors are set.
range
,
short
- Color index from IndexedColors used to draw the borders.
color
)

Sets the color of the left border for a range of cells.

private void
drawOutsideBorderColors(CellRangeAddress
- CellRangeAddress range of cells on which colors are set.
range
,
short
- Color index from IndexedColors used to draw the borders.
color
,
BorderExtent
- BorderExtent of the borders for which colors are set. Valid Values are:
  • BorderExtent.ALL
  • BorderExtent.HORIZONTAL
  • BorderExtent.VERTICAL
extent
)

Sets the color of the outside borders for a range of cells.

private void
drawOutsideBorders(CellRangeAddress
- CellRangeAddress range of cells on which borders are drawn.
range
,
BorderStyle
- Type of border to draw. BorderStyle.
borderType
,
BorderExtent
- BorderExtent of the borders to be applied. Valid Values are:
  • BorderExtent.ALL
  • BorderExtent.HORIZONTAL
  • BorderExtent.VERTICAL
extent
)

Draws the outside borders for a range of cells.

private void
drawRightBorder(CellRangeAddress
- CellRangeAddress range of cells on which borders are drawn.
range
,
BorderStyle
- Type of border to draw. BorderStyle.
borderType
)

Draws the right border for a range of cells

private void
drawRightBorderColor(CellRangeAddress
- CellRangeAddress range of cells on which colors are set.
range
,
short
- Color index from IndexedColors used to draw the borders.
color
)

Sets the color of the right border for a range of cells.

private void
drawTopBorder(CellRangeAddress
- CellRangeAddress range of cells on which borders are drawn.
range
,
BorderStyle
- Type of border to draw. BorderStyle.
borderType
)

Draws the top border for a range of cells

private void
drawTopBorderColor(CellRangeAddress
- CellRangeAddress range of cells on which colors are set.
range
,
short
- Color index from IndexedColors used to draw the borders.
color
)

Sets the color of the top border for a range of cells.

private void
drawVerticalBorderColors(CellRangeAddress
- CellRangeAddress range of cells on which colors are set.
range
,
short
- Color index from IndexedColors used to draw the borders.
color
,
BorderExtent
- BorderExtent of the borders for which colors are set. Valid Values are:
  • BorderExtent.ALL
  • BorderExtent.INSIDE
extent
)

Sets the color of the vertical borders for a range of cells.

private void
drawVerticalBorders(CellRangeAddress
- CellRangeAddress range of cells on which borders are drawn.
range
,
BorderStyle
- Type of border to draw. BorderStyle.
borderType
,
BorderExtent
- BorderExtent of the borders to be applied. Valid Values are:
  • BorderExtent.ALL
  • BorderExtent.INSIDE
extent
)

Draws the vertical borders for a range of cells.

public BorderStyle
getBorderStyle(CellAddress cell, String property)

Retrieves the border style for a given cell

public BorderStyle
getBorderStyle(int row, int col, String property)

Retrieves the border style for a given cell

public int
getNumBorderColors(CellAddress cell)

Retrieves the number of border colors assigned to a cell

public int
getNumBorderColors(int row, int col)

Retrieves the number of border colors assigned to a cell

public int
getNumBorders(CellAddress cell)

Retrieves the number of borders assigned to a cell

public int
getNumBorders(int row, int col)

Retrieves the number of borders assigned to a cell

private static short

Returns:

short value, or 0 if not a short
getShort
(Object
Potentially short value to convert
value
)

Converts a Short object to a short value or 0 if the object is not a Short

private Map<CellAddress, Map<String, Object>>
public short
getTemplateProperty(CellAddress cell, String property)

Retrieves the border style for a given cell

public short
getTemplateProperty(int row, int col, String property)

Retrieves the border style for a given cell

private void
removeBorderColors(CellRangeAddress
- CellRangeAddress range of cells to remove borders.
range
)

Removes all border properties from this PropertyTemplate for the specified range.

private void
removeBorders(CellRangeAddress
- CellRangeAddress range of cells to remove borders.
range
)

Removes all border properties from this PropertyTemplate for the specified range.

private void
removeProperties(int row, int col, Set<String> properties)

Removes a set of properties from this PropertyTemplate for a given cell

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_propertyTemplateback to summary
private final Map<CellAddress, Map<String, Object>> _propertyTemplate

This is a list of cell properties for one shot application to a range of cells at a later time.

Constructor Detail

PropertyTemplateback to summary
public PropertyTemplate()

Create a PropertyTemplate object

PropertyTemplateback to summary
public PropertyTemplate(PropertyTemplate template)

Create a PropertyTemplate object from another PropertyTemplate

Parameters
template:PropertyTemplate

a PropertyTemplate object

Method Detail

addPropertyback to summary
private void addProperty(int row, int col, String property, short value)

Adds a property to this PropertyTemplate for a given cell

addPropertyback to summary
private void addProperty(int row, int col, String property, Object value)

Adds a property to this PropertyTemplate for a given cell

applyBordersback to summary
public void applyBorders(Sheet sheet)

Applies the drawn borders to a Sheet. The borders that are applied are the ones that have been drawn by the drawBorders and drawBorderColors methods.

Parameters
sheet:Sheet

- Sheet on which to apply borders

cloneCellPropertiesback to summary
private static Map<String, Object> cloneCellProperties(Map<String, Object> properties)
drawBorderColorsback to summary
public void drawBorderColors(CellRangeAddress range, short color, BorderExtent extent)

Sets the color for a group of cell borders for a cell range. The borders are not applied to the cells at this time, just the template is drawn. If the borders do not exist, a BORDER_THIN border is used. To apply the drawn borders to a sheet, use applyBorders.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which colors are set.

color:short

- Color index from IndexedColors used to draw the borders.

extent:BorderExtent

- BorderExtent of the borders for which colors are set.

drawBordersback to summary
public void drawBorders(CellRangeAddress range, BorderStyle borderType, BorderExtent extent)

Draws a group of cell borders for a cell range. The borders are not applied to the cells at this time, just the template is drawn. To apply the drawn borders to a sheet, use applyBorders.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which borders are drawn.

borderType:BorderStyle

- Type of border to draw. BorderStyle.

extent:BorderExtent

- BorderExtent of the borders to be applied.

drawBordersback to summary
public void drawBorders(CellRangeAddress range, BorderStyle borderType, short color, BorderExtent extent)

Draws a group of cell borders for a cell range. The borders are not applied to the cells at this time, just the template is drawn. To apply the drawn borders to a sheet, use applyBorders.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which borders are drawn.

borderType:BorderStyle

- Type of border to draw. BorderStyle.

color:short

- Color index from IndexedColors used to draw the borders.

extent:BorderExtent

- BorderExtent of the borders to be applied.

drawBottomBorderback to summary
private void drawBottomBorder(CellRangeAddress range, BorderStyle borderType)

Draws the bottom border for a range of cells

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which borders are drawn.

borderType:BorderStyle

- Type of border to draw. BorderStyle.

drawBottomBorderColorback to summary
private void drawBottomBorderColor(CellRangeAddress range, short color)

Sets the color of the bottom border for a range of cells.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which colors are set.

color:short

- Color index from IndexedColors used to draw the borders.

drawHorizontalBorderColorsback to summary
private void drawHorizontalBorderColors(CellRangeAddress range, short color, BorderExtent extent)

Sets the color of the horizontal borders for a range of cells.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which colors are set.

color:short

- Color index from IndexedColors used to draw the borders.

extent:BorderExtent

- BorderExtent of the borders for which colors are set. Valid Values are:

  • BorderExtent.ALL
  • BorderExtent.INSIDE
drawHorizontalBordersback to summary
private void drawHorizontalBorders(CellRangeAddress range, BorderStyle borderType, BorderExtent extent)

Draws the horizontal borders for a range of cells.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which borders are drawn.

borderType:BorderStyle

- Type of border to draw. BorderStyle.

extent:BorderExtent

- BorderExtent of the borders to be applied. Valid Values are:

  • BorderExtent.ALL
  • BorderExtent.INSIDE
drawLeftBorderback to summary
private void drawLeftBorder(CellRangeAddress range, BorderStyle borderType)

Draws the left border for a range of cells

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which borders are drawn.

borderType:BorderStyle

- Type of border to draw. BorderStyle.

drawLeftBorderColorback to summary
private void drawLeftBorderColor(CellRangeAddress range, short color)

Sets the color of the left border for a range of cells.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which colors are set.

color:short

- Color index from IndexedColors used to draw the borders.

drawOutsideBorderColorsback to summary
private void drawOutsideBorderColors(CellRangeAddress range, short color, BorderExtent extent)

Sets the color of the outside borders for a range of cells.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which colors are set.

color:short

- Color index from IndexedColors used to draw the borders.

extent:BorderExtent

- BorderExtent of the borders for which colors are set. Valid Values are:

  • BorderExtent.ALL
  • BorderExtent.HORIZONTAL
  • BorderExtent.VERTICAL
drawOutsideBordersback to summary
private void drawOutsideBorders(CellRangeAddress range, BorderStyle borderType, BorderExtent extent)

Draws the outside borders for a range of cells.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which borders are drawn.

borderType:BorderStyle

- Type of border to draw. BorderStyle.

extent:BorderExtent

- BorderExtent of the borders to be applied. Valid Values are:

  • BorderExtent.ALL
  • BorderExtent.HORIZONTAL
  • BorderExtent.VERTICAL
drawRightBorderback to summary
private void drawRightBorder(CellRangeAddress range, BorderStyle borderType)

Draws the right border for a range of cells

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which borders are drawn.

borderType:BorderStyle

- Type of border to draw. BorderStyle.

drawRightBorderColorback to summary
private void drawRightBorderColor(CellRangeAddress range, short color)

Sets the color of the right border for a range of cells. If the border is not drawn, it defaults to BORDER_THIN

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which colors are set.

color:short

- Color index from IndexedColors used to draw the borders.

drawTopBorderback to summary
private void drawTopBorder(CellRangeAddress range, BorderStyle borderType)

Draws the top border for a range of cells

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which borders are drawn.

borderType:BorderStyle

- Type of border to draw. BorderStyle.

drawTopBorderColorback to summary
private void drawTopBorderColor(CellRangeAddress range, short color)

Sets the color of the top border for a range of cells.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which colors are set.

color:short

- Color index from IndexedColors used to draw the borders.

drawVerticalBorderColorsback to summary
private void drawVerticalBorderColors(CellRangeAddress range, short color, BorderExtent extent)

Sets the color of the vertical borders for a range of cells.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which colors are set.

color:short

- Color index from IndexedColors used to draw the borders.

extent:BorderExtent

- BorderExtent of the borders for which colors are set. Valid Values are:

  • BorderExtent.ALL
  • BorderExtent.INSIDE
drawVerticalBordersback to summary
private void drawVerticalBorders(CellRangeAddress range, BorderStyle borderType, BorderExtent extent)

Draws the vertical borders for a range of cells.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells on which borders are drawn.

borderType:BorderStyle

- Type of border to draw. BorderStyle.

extent:BorderExtent

- BorderExtent of the borders to be applied. Valid Values are:

  • BorderExtent.ALL
  • BorderExtent.INSIDE
getBorderStyleback to summary
public BorderStyle getBorderStyle(CellAddress cell, String property)

Retrieves the border style for a given cell

getBorderStyleback to summary
public BorderStyle getBorderStyle(int row, int col, String property)

Retrieves the border style for a given cell

getNumBorderColorsback to summary
public int getNumBorderColors(CellAddress cell)

Retrieves the number of border colors assigned to a cell

getNumBorderColorsback to summary
public int getNumBorderColors(int row, int col)

Retrieves the number of border colors assigned to a cell

getNumBordersback to summary
public int getNumBorders(CellAddress cell)

Retrieves the number of borders assigned to a cell

getNumBordersback to summary
public int getNumBorders(int row, int col)

Retrieves the number of borders assigned to a cell

getShortback to summary
private static short getShort(Object value)

Converts a Short object to a short value or 0 if the object is not a Short

Parameters
value:Object

Potentially short value to convert

Returns:short

short value, or 0 if not a short

getTemplateback to summary
private Map<CellAddress, Map<String, Object>> getTemplate()
getTemplatePropertyback to summary
public short getTemplateProperty(CellAddress cell, String property)

Retrieves the border style for a given cell

getTemplatePropertyback to summary
public short getTemplateProperty(int row, int col, String property)

Retrieves the border style for a given cell

removeBorderColorsback to summary
private void removeBorderColors(CellRangeAddress range)

Removes all border properties from this PropertyTemplate for the specified range.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells to remove borders.

removeBordersback to summary
private void removeBorders(CellRangeAddress range)

Removes all border properties from this PropertyTemplate for the specified range.

Parameters
range:CellRangeAddress

- CellRangeAddress range of cells to remove borders.

removePropertiesback to summary
private void removeProperties(int row, int col, Set<String> properties)

Removes a set of properties from this PropertyTemplate for a given cell