org.jfree.workbook
Class Worksheet

java.lang.Object
  |
  +--org.jfree.workbook.Worksheet

public class Worksheet
extends java.lang.Object

Represents one worksheet within a workbook.


Field Summary
protected  Cells cells
          The cells in the worksheet.
protected  ColumnAttributesManager columnAttributesManager
          Column attributes (width, margins, hidden etc).
protected  boolean columnHeaderVisible
          A flag indicating whether or not the column header is visible.
protected  java.util.List comments
          Comments for cells in the worksheet.
static double DEFAULT_COLUMN_WIDTH
          The default width for columns.
static double DEFAULT_ROW_HEIGHT
          The default height for rows.
protected  boolean displayFormulae
          Display formulae rather than calculated values (true/false).
protected  boolean gridVisible
          A flag indicating whether or not the grid is visible.
protected  boolean hideZeros
          Hide zeros (true/false).
static int MAX_COLUMNS
          The maximum number of columns in a worksheet.
static int MAX_ROWS
          The maximum number of rows in a worksheet.
protected  int maxColumn
          The index of the right-most column used in the worksheet.
protected  int maxRow
          The index of the bottom-most row used in the worksheet.
protected  java.lang.String name
          The name of the worksheet.
protected  NamesManager namesManager
          Manager for names defined in the worksheet.
protected  PrintInformation printInfo
          Print setup.
protected  RowAttributesManager rowAttributesManager
          Row attributes (height, margins, hidden etc).
protected  boolean rowHeaderVisible
          A flag indicating whether or not the row header is visible.
protected  Selections selections
          Ranges that are selected.
protected  Solver solver
          Settings for the solver utility.
protected  Styles styles
          Styles that apply to ranges within the worksheet.
protected  double zoom
          The current zoom factor (in the range 0.05 to 5.00, that is 5% to 500%).
 
Constructor Summary
Worksheet(java.lang.String name)
          Standard constructor: creates a named empty worksheet.
 
Method Summary
 void addCell(Cell cell)
          Sets the value at the specified cell.
 void addName(java.lang.String name, java.lang.String value)
          Adds a name to the worksheet.
 void addStyleRegion(StyleRegion styleRegion)
          Adds the specified style region.
 void applyBackgroundColor(Color color, int row, int column)
          Applies the background color to the specified cell.
 void applyBackgroundColor(Color color, int startRow, int startColumn, int endRow, int endColumn)
          Applies the background color to the specified region.
 void applyBorder(Border border, int row, int column)
          Applies the foreground color to the specified cell.
 void applyBorder(Border border, int startRow, int startColumn, int endRow, int endColumn)
          Applies the border to the specified region.
 void applyFont(FontStyle font, int row, int column)
          Applies the font to the specified cell.
 void applyFont(FontStyle font, int startRow, int startColumn, int endRow, int endColumn)
          Applies the font to the specified region.
 void applyForegroundColor(Color color, int row, int column)
          Applies the foreground color to the specified cell.
 void applyForegroundColor(Color color, int startRow, int startColumn, int endRow, int endColumn)
          Applies the foreground color to the specified region.
 void applyHorizontalAlignment(int align, int row, int column)
          Applies a horizontal alignment setting to a cell.
 void applyHorizontalAlignment(int align, int startRow, int startColumn, int endRow, int endColumn)
          Applies a horizontal alignment setting to a range of cells.
 void applyOutline(int row, int column)
          Applies a thin outline border to a cell.
 void applyOutline(int borderStyle, int row, int column)
          Applies a border to a cell.
 void applyOutline(int startRow, int startColumn, int endRow, int endColumn)
          Applies a thin outline border to a range of cells.
 void applyOutline(int lineStyle, int startRow, int startColumn, int endRow, int endColumn)
          Applies a border around a range of cells.
 void applyPatternColor(Color color, int row, int column)
          Applies the pattern color to the specified cell.
 void applyPatternColor(Color color, int startRow, int startColumn, int endRow, int endColumn)
          Applies the pattern color to the specified region.
 void applyVerticalAlignment(int align, int row, int column)
          Applies a vertical alignment setting to a cell.
 void applyVerticalAlignment(int align, int startRow, int startColumn, int endRow, int endColumn)
          Applies a vertical alignment setting to a range of cells.
 void applyWrapText(boolean wrapText, int row, int column)
          Applies the "wrap-text" setting to the specified cell.
 void applyWrapText(boolean wrapText, int startRow, int startColumn, int endRow, int endColumn)
          Applies the "wrap-text" setting to the specified region.
static java.lang.String cellReference(int row, int column)
          Returns a cell reference using letters for the column (e.g.
 Cells getCells()
          Returns the cells for the worksheet.
 ColumnAttributesManager getColumnAttributesManager()
          Returns a reference to the object managing the column attributes.
 java.util.List getComments()
          Returns the comments for the worksheet.
 boolean getDisplayFormulae()
          Returns true if formulae rather than values are being displayed in the worksheet.
 boolean getHideZeros()
          Returns a flag indicating whether or not zero values are displayed.
 int getMaxColumn()
          Returns the index of the rightmost column in the sheet.
 int getMaxRow()
          Returns the index of the bottommost row in the sheet.
 java.lang.String getName()
          Returns the name of the worksheet.
 NamesManager getNamesManager()
          Returns a reference to the names manager.
 PrintInformation getPrintInformation()
          Returns the print information for the sheet.
 RowAttributesManager getRowAttributesManager()
          Returns a reference to the object managing the row attributes.
 Selections getSelections()
          Returns the selections for the sheet.
 Solver getSolver()
          Returns the solver for the worksheet.
 Styles getStyles()
          Returns the styles information for the sheet.
 double getZoom()
          Returns the zoom factor.
 boolean isColumnHeaderVisible()
          Returns a flag indicating whether or not the column header is visible.
 boolean isGridVisible()
          Returns a flag indicating whether or not the grid is visible.
 boolean isRowHeaderVisible()
          Returns a flag indicating whether or not the row header is visible.
 void putComment(int row, int column, java.lang.String comment)
          Puts a comment in a cell, overwriting any existing cell comments.
 void putDate(int row, int column, SerialDate date)
          Puts a date in a cell, overwriting any existing cell contents.
 void putFormula(int row, int column, java.lang.String formula)
          Puts a formula in a cell, overwriting any existing cell contents.
 void putLabel(int row, int column, java.lang.String label)
          Puts a label in a cell, overwriting any existing cell contents.
 void putValue(int row, int column, double value)
          Puts a value in a cell, overwriting any existing cell contents.
 void setColumnWidth(int column, double width)
          Sets the width of one column.
 void setColumnWidth(int startColumn, int endColumn, double width)
          Sets the width of a range of columns.
 void setName(java.lang.String name)
          Sets the name of the worksheet.
 void setRowHeight(int row, double height)
          Sets the height of one row.
 void setRowHeight(int startRow, int endRow, double height)
          Sets the height of a range of rows.
 void setStyle(Style style, int startRow, int startColumn, int endRow, int endColumn)
          Set the style for the specified range of the worksheet.
 void setZoom(double percent)
          Sets the zoom factor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_COLUMNS

public static final int MAX_COLUMNS
The maximum number of columns in a worksheet.

See Also:
Constant Field Values

MAX_ROWS

public static final int MAX_ROWS
The maximum number of rows in a worksheet.

See Also:
Constant Field Values

DEFAULT_COLUMN_WIDTH

public static final double DEFAULT_COLUMN_WIDTH
The default width for columns.

See Also:
Constant Field Values

DEFAULT_ROW_HEIGHT

public static final double DEFAULT_ROW_HEIGHT
The default height for rows.

See Also:
Constant Field Values

name

protected java.lang.String name
The name of the worksheet.


displayFormulae

protected boolean displayFormulae
Display formulae rather than calculated values (true/false).


hideZeros

protected boolean hideZeros
Hide zeros (true/false).


gridVisible

protected boolean gridVisible
A flag indicating whether or not the grid is visible.


columnHeaderVisible

protected boolean columnHeaderVisible
A flag indicating whether or not the column header is visible.


rowHeaderVisible

protected boolean rowHeaderVisible
A flag indicating whether or not the row header is visible.


maxColumn

protected int maxColumn
The index of the right-most column used in the worksheet.


maxRow

protected int maxRow
The index of the bottom-most row used in the worksheet.


zoom

protected double zoom
The current zoom factor (in the range 0.05 to 5.00, that is 5% to 500%).


namesManager

protected NamesManager namesManager
Manager for names defined in the worksheet.


printInfo

protected PrintInformation printInfo
Print setup.


styles

protected Styles styles
Styles that apply to ranges within the worksheet.


columnAttributesManager

protected ColumnAttributesManager columnAttributesManager
Column attributes (width, margins, hidden etc).


rowAttributesManager

protected RowAttributesManager rowAttributesManager
Row attributes (height, margins, hidden etc).


selections

protected Selections selections
Ranges that are selected.


cells

protected Cells cells
The cells in the worksheet.


comments

protected java.util.List comments
Comments for cells in the worksheet.


solver

protected Solver solver
Settings for the solver utility.

Constructor Detail

Worksheet

public Worksheet(java.lang.String name)
Standard constructor: creates a named empty worksheet.

Parameters:
name - the name of the worksheet.
Method Detail

getName

public java.lang.String getName()
Returns the name of the worksheet.

Returns:
The name of the worksheet.

setName

public void setName(java.lang.String name)
Sets the name of the worksheet.

Parameters:
name - the name.

getMaxColumn

public int getMaxColumn()
Returns the index of the rightmost column in the sheet.

Returns:
The maximum column index.

getMaxRow

public int getMaxRow()
Returns the index of the bottommost row in the sheet.

Returns:
The maximum row index.

getZoom

public double getZoom()
Returns the zoom factor.

Returns:
The zoom factor.

setZoom

public void setZoom(double percent)
Sets the zoom factor.

Parameters:
percent - the new zoom factor (should be in the range 0.05 to 5.00).

getDisplayFormulae

public boolean getDisplayFormulae()
Returns true if formulae rather than values are being displayed in the worksheet.

Returns:
True if formulae rather than values are being displayed in the worksheet.

getHideZeros

public boolean getHideZeros()
Returns a flag indicating whether or not zero values are displayed.

Returns:
A boolean.

isGridVisible

public boolean isGridVisible()
Returns a flag indicating whether or not the grid is visible.

Returns:
A boolean.

isColumnHeaderVisible

public boolean isColumnHeaderVisible()
Returns a flag indicating whether or not the column header is visible.

Returns:
A boolean.

isRowHeaderVisible

public boolean isRowHeaderVisible()
Returns a flag indicating whether or not the row header is visible.

Returns:
A boolean.

getNamesManager

public NamesManager getNamesManager()
Returns a reference to the names manager.

Returns:
A reference to the names manager.

getPrintInformation

public PrintInformation getPrintInformation()
Returns the print information for the sheet.

Returns:
Print information.

getStyles

public Styles getStyles()
Returns the styles information for the sheet.

Returns:
Styles information.

getSelections

public Selections getSelections()
Returns the selections for the sheet.

Returns:
The selections.

getCells

public Cells getCells()
Returns the cells for the worksheet.

Returns:
The cells.

getSolver

public Solver getSolver()
Returns the solver for the worksheet.

Returns:
The solver.

getComments

public java.util.List getComments()
Returns the comments for the worksheet.

Returns:
The comments.

getColumnAttributesManager

public ColumnAttributesManager getColumnAttributesManager()
Returns a reference to the object managing the column attributes.

Returns:
The column attributes manager.

getRowAttributesManager

public RowAttributesManager getRowAttributesManager()
Returns a reference to the object managing the row attributes.

Returns:
The row attributes manager.

setRowHeight

public void setRowHeight(int row,
                         double height)
Sets the height of one row.

Parameters:
row - the row (0 <= startRow < Worksheets.MAX_ROWS).
height - the new height.

setRowHeight

public void setRowHeight(int startRow,
                         int endRow,
                         double height)
Sets the height of a range of rows.

Parameters:
startRow - the row (0 <= startRow < Worksheets.MAX_ROWS).
endRow - the row (startRow <= endRow < Worksheets.MAX_ROWS).
height - the new height (height >= 0.0).

setColumnWidth

public void setColumnWidth(int column,
                           double width)
Sets the width of one column.

Parameters:
column - the column (0 to Worksheets.MAX_COLUMNS-1).
width - the new width.

setColumnWidth

public void setColumnWidth(int startColumn,
                           int endColumn,
                           double width)
Sets the width of a range of columns.

Parameters:
startColumn - the start column (0 <= startColumn < Worksheets.MAX_COLUMNS).
endColumn - the end column (startColumn <= endColumn < Worksheets.MAX_COLUMNS).
width - the new width.

addCell

public void addCell(Cell cell)
Sets the value at the specified cell.

Parameters:
cell - the new cell.

addName

public void addName(java.lang.String name,
                    java.lang.String value)
Adds a name to the worksheet. For now, there is no validation performed here, so be careful what you add.

Parameters:
name - the new name.
value - the value that the name resolves to.

addStyleRegion

public void addStyleRegion(StyleRegion styleRegion)
Adds the specified style region.

Note: this method will not adjust row sizes for the particular style that is being applied. Not sure what is the best way to achieve this...

Parameters:
styleRegion - the style region being added.

setStyle

public void setStyle(Style style,
                     int startRow,
                     int startColumn,
                     int endRow,
                     int endColumn)
Set the style for the specified range of the worksheet.

Note: this method will not adjust row sizes for the particular style that is being applied. Not sure what is the best way to achieve this...

Parameters:
style - the style to be applied.
startRow - the start row for the style region.
startColumn - the start column for the style region.
endRow - the end row for the style region.
endColumn - the end column for the style region.

putDate

public void putDate(int row,
                    int column,
                    SerialDate date)
Puts a date in a cell, overwriting any existing cell contents.

Parameters:
row - the row (0 <= row < Worksheet.MAX_ROWS).
column - the column (0 <= column < Worksheet.MAX_COLUMNS).
date - the date.

putFormula

public void putFormula(int row,
                       int column,
                       java.lang.String formula)
Puts a formula in a cell, overwriting any existing cell contents.

Parameters:
formula - the formula (not validated).
column - the column (0 <= column < Worksheet.MAX_COLUMNS).
row - the row (0 <= row < Worksheet.MAX_ROWS).

putLabel

public void putLabel(int row,
                     int column,
                     java.lang.String label)
Puts a label in a cell, overwriting any existing cell contents.

Parameters:
label - the label.
column - the column (0 <= column < Worksheet.MAX_COLUMNS).
row - the row (0 <= row < Worksheet.MAX_ROWS).

putValue

public void putValue(int row,
                     int column,
                     double value)
Puts a value in a cell, overwriting any existing cell contents.

Parameters:
value - the value.
column - the column (0 <= column < Worksheet.MAX_COLUMNS).
row - the row (0 <= row < Worksheet.MAX_ROWS).

putComment

public void putComment(int row,
                       int column,
                       java.lang.String comment)
Puts a comment in a cell, overwriting any existing cell comments.

Parameters:
row - the row (0 <= row < Worksheet.MAX_ROWS).
column - the column (0 <= column < Worksheet.MAX_COLUMNS).
comment - the comment.

applyFont

public void applyFont(FontStyle font,
                      int row,
                      int column)
Applies the font to the specified cell.

This may involve restructuring the style regions.

Parameters:
font - the font.
row - the row (0 <= row < Worksheet.MAX_ROWS).
column - the column (0 <= column < Worksheet.MAX_COLUMNS).

applyFont

public void applyFont(FontStyle font,
                      int startRow,
                      int startColumn,
                      int endRow,
                      int endColumn)
Applies the font to the specified region.

This may involve restructuring the style regions.

Parameters:
font - the font.
startRow - the start row (0 <= startRow < Worksheet.MAX_ROWS).
startColumn - the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
endRow - the end row (0 <= endRow < Worksheet.MAX_ROWS).
endColumn - the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).

applyHorizontalAlignment

public void applyHorizontalAlignment(int align,
                                     int row,
                                     int column)
Applies a horizontal alignment setting to a cell.

This may involve restructuring the style regions.

Parameters:
align - the new alignment.
row - the row (0 <= row < Worksheet.MAX_ROWS).
column - the column (0 <= column < Worksheet.MAX_COLUMNS).

applyHorizontalAlignment

public void applyHorizontalAlignment(int align,
                                     int startRow,
                                     int startColumn,
                                     int endRow,
                                     int endColumn)
Applies a horizontal alignment setting to a range of cells.

This may involve restructuring the style regions.

Parameters:
align - the new alignment.
startRow - the start row (0 <= startRow < Worksheet.MAX_ROWS).
startColumn - the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
endRow - the end row (0 <= endRow < Worksheet.MAX_ROWS).
endColumn - the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).

applyVerticalAlignment

public void applyVerticalAlignment(int align,
                                   int row,
                                   int column)
Applies a vertical alignment setting to a cell.

This may involve restructuring the style regions.

Parameters:
align - the new alignment.
row - the row (0 <= row < Worksheet.MAX_ROWS).
column - the column (0 <= column < Worksheet.MAX_COLUMNS).

applyVerticalAlignment

public void applyVerticalAlignment(int align,
                                   int startRow,
                                   int startColumn,
                                   int endRow,
                                   int endColumn)
Applies a vertical alignment setting to a range of cells.

This may involve restructuring the style regions.

Parameters:
align - the new alignment.
startColumn - the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
startRow - the start row (0 <= startRow < Worksheet.MAX_ROWS).
endColumn - the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).
endRow - the end row (0 <= endRow < Worksheet.MAX_ROWS).

applyWrapText

public void applyWrapText(boolean wrapText,
                          int row,
                          int column)
Applies the "wrap-text" setting to the specified cell.

This may involve restructuring the style regions.

Parameters:
wrapText - the new value of the wrap-text flag.
row - the row (0 <= row < Worksheet.MAX_ROWS).
column - the column (0 <= column < Worksheet.MAX_COLUMNS).

applyWrapText

public void applyWrapText(boolean wrapText,
                          int startRow,
                          int startColumn,
                          int endRow,
                          int endColumn)
Applies the "wrap-text" setting to the specified region.

This may involve restructuring the style regions.

Parameters:
wrapText - the new value of the wrap-text flag.
startColumn - the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
startRow - the start row (0 <= startRow < Worksheet.MAX_ROWS).
endColumn - the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).
endRow - the end row (0 <= endRow < Worksheet.MAX_ROWS).

applyBorder

public void applyBorder(Border border,
                        int row,
                        int column)
Applies the foreground color to the specified cell.

This may involve restructuring the style regions.

Parameters:
border - the border.
row - the row (0 <= row < Worksheet.MAX_ROWS).
column - the column (0 <= column < Worksheet.MAX_COLUMNS).

applyBorder

public void applyBorder(Border border,
                        int startRow,
                        int startColumn,
                        int endRow,
                        int endColumn)
Applies the border to the specified region.

This may involve restructuring the style regions.

Parameters:
border - the border.
startRow - the start row (0 <= startRow < Worksheet.MAX_ROWS).
startColumn - the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
endRow - the end row (0 <= endRow < Worksheet.MAX_ROWS).
endColumn - the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).

applyOutline

public void applyOutline(int row,
                         int column)
Applies a thin outline border to a cell.

Parameters:
row - the row (0 <= row < Worksheet.MAX_ROWS).
column - the column (0 <= column < Worksheet.MAX_COLUMNS).

applyOutline

public void applyOutline(int startRow,
                         int startColumn,
                         int endRow,
                         int endColumn)
Applies a thin outline border to a range of cells.

Parameters:
startRow - the start row (0 <= startRow < Worksheet.MAX_ROWS).
startColumn - the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
endRow - the end row (0 <= endRow < Worksheet.MAX_ROWS).
endColumn - the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).

applyOutline

public void applyOutline(int borderStyle,
                         int row,
                         int column)
Applies a border to a cell.

Parameters:
borderStyle - the border style.
row - the row.
column - the column.

applyOutline

public void applyOutline(int lineStyle,
                         int startRow,
                         int startColumn,
                         int endRow,
                         int endColumn)
Applies a border around a range of cells.

Parameters:
lineStyle - the style of line for the border.
startRow - the start row (0 <= startRow < Worksheet.MAX_ROWS).
startColumn - the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
endRow - the end row (0 <= endRow < Worksheet.MAX_ROWS).
endColumn - the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).

applyForegroundColor

public void applyForegroundColor(Color color,
                                 int row,
                                 int column)
Applies the foreground color to the specified cell.

This may involve restructuring the style regions.

Parameters:
color - the color.
row - the row (0 <= row < Worksheet.MAX_ROWS).
column - the column (0 <= column < Worksheet.MAX_COLUMNS).

applyForegroundColor

public void applyForegroundColor(Color color,
                                 int startRow,
                                 int startColumn,
                                 int endRow,
                                 int endColumn)
Applies the foreground color to the specified region.

This may involve restructuring the style regions.

Parameters:
color - the color.
startRow - the start row (0 <= startRow < Worksheet.MAX_ROWS).
startColumn - the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
endRow - the end row (0 <= endRow < Worksheet.MAX_ROWS).
endColumn - the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).

applyBackgroundColor

public void applyBackgroundColor(Color color,
                                 int row,
                                 int column)
Applies the background color to the specified cell.

This may involve restructuring the style regions.

Parameters:
color - the color.
row - the row (0 <= row < Worksheet.MAX_ROWS).
column - the column (0 <= column < Worksheet.MAX_COLUMNS).

applyBackgroundColor

public void applyBackgroundColor(Color color,
                                 int startRow,
                                 int startColumn,
                                 int endRow,
                                 int endColumn)
Applies the background color to the specified region.

This may involve restructuring the style regions.

Parameters:
color - the color.
startRow - the start row (0 <= startRow < Worksheet.MAX_ROWS).
startColumn - the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
endRow - the end row (0 <= endRow < Worksheet.MAX_ROWS).
endColumn - the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).

applyPatternColor

public void applyPatternColor(Color color,
                              int row,
                              int column)
Applies the pattern color to the specified cell.

This may involve restructuring the style regions.

Parameters:
color - the color.
column - the column (0 <= column < Worksheet.MAX_COLUMNS).
row - the row (0 <= row < Worksheet.MAX_ROWS).

applyPatternColor

public void applyPatternColor(Color color,
                              int startRow,
                              int startColumn,
                              int endRow,
                              int endColumn)
Applies the pattern color to the specified region.

This may involve restructuring the style regions.

Parameters:
color - the color.
startRow - the start row (0 <= startRow < Worksheet.MAX_ROWS).
startColumn - the start column (0 <= startColumn < Worksheet.MAX_COLUMNS).
endRow - the end row (0 <= endRow < Worksheet.MAX_ROWS).
endColumn - the end column (0 <= endColumn < Worksheet.MAX_COLUMNS).

cellReference

public static java.lang.String cellReference(int row,
                                             int column)
Returns a cell reference using letters for the column (e.g. D4) and the row number.

Note that internally we use zero based indices for the column and row numbers. But externally the user expects the first row to be number 1 (not 0).

Parameters:
row - the cell's row (0 <= row < Worksheet.MAX_ROWS).
column - the cell's column (0 <= column < Worksheet.MAX_COLUMNS).
Returns:
A cell reference.