jxl.write.biff
Class WritableSheetImpl

java.lang.Object
  |
  +--jxl.write.biff.WritableSheetImpl
All Implemented Interfaces:
Sheet, WritableSheet

class WritableSheetImpl
extends java.lang.Object
implements WritableSheet

A writable sheet. This class contains implementation of all the writable sheet methods which may be invoke by the API


Inner Class Summary
private static class WritableSheetImpl.ColumnInfoComparator
          The comparator for column info record
 
Field Summary
private  java.util.TreeSet columnFormats
          The list of non-default column formats
private  FormattingRecords formatRecords
          A handle to workbook format records
private  java.util.ArrayList hyperlinks
          The list of hyperlinks
private  java.util.ArrayList mergedCells
          The list of merged ranged
private  java.lang.String name
          The name of this sheet
private  int numColumns
          The number of columns.
private  int numRows
          A number of rows.
private static int numRowsPerSheet
          The maximum number of rows excel allows in a worksheet
private  File outputFile
          A handle to the output file which the binary data is written to
private  java.util.ArrayList rowBreaks
          Array of row page breaks
private static int rowGrowSize
          The amount by which to grow the rows array
private  RowRecord[] rows
          The rows within this sheet
private  SheetSettings settings
          The settings for this sheet
private  SharedStrings sharedStrings
          A handle to the shared strings used by this workbook
private  SheetWriter sheetWriter
          The sheet writer engine
private  WritableWorkbookImpl workbook
          The workbook
private  WorkbookSettings workbookSettings
          The settings for the workbook
 
Constructor Summary
WritableSheetImpl(java.lang.String n, File of, FormattingRecords fr, SharedStrings ss, WorkbookSettings ws, WritableWorkbookImpl ww)
          Constructor
 
Method Summary
 void addCell(WritableCell cell)
          Adds the cell to this sheet.
 void addHyperlink(WritableHyperlink h)
          Adds the specified hyperlink
 void addRowPageBreak(int row)
          Forces a page break at the specified row
(package private)  void checkMergedBorders()
          Check all the merged cells for borders.
(package private)  void copy(Sheet s)
          Copies the specified sheet, row by row and cell by cell
(package private)  void copy(WritableSheet s)
          Copies the specified sheet, row by row and cell by cell
private  void copyCells(Sheet s)
          Copies the cell contents from the specified sheet into this one
 Cell findCell(java.lang.String contents)
          Gets the cell whose contents match the string passed in.
 LabelCell findLabelCell(java.lang.String contents)
          Gets the cell whose contents match the string passed in.
 Cell getCell(int column, int row)
          Returns the cell specified at this row and at this column
private  Chart[] getCharts()
          Accessor for the charts.
 Cell[] getColumn(int col)
          Gets all the cells on the specified column
(package private)  ColumnInfoRecord getColumnInfo(int c)
          Gets the column info record for the specified column
 int getColumns()
          Returns the number of columns in this sheet
(package private)  FooterRecord getFooter()
          Gets the footer.
(package private)  HeaderRecord getHeader()
          Gets the header.
 Hyperlink[] getHyperlinks()
          Gets the hyperlinks on this sheet
 Range[] getMergedCells()
          Gets the cells which have been merged on this sheet
 java.lang.String getName()
          Gets the name of this sheet
 Cell[] getRow(int row)
          Gets all the cells on the specified row
(package private)  RowRecord getRowInfo(int r)
          Gets the row record for the specified row
private  RowRecord getRowRecord(int row)
          Gets the row record at the specified row number, growing the array as needs dictate
 int getRows()
          Returns the number of rows in this sheet
 SheetSettings getSettings()
          Gets the settings for this sheet
(package private)  WritableWorkbookImpl getWorkbook()
          Accessor for the workbook
(package private)  WorkbookSettings getWorkbookSettings()
          Gets the workbook settings
private  WorkspaceInformationRecord getWorkspaceOptions()
          Accessor for the workspace options
 WritableCell getWritableCell(int column, int row)
          Returns the cell specified at this row and at this column
 WritableHyperlink[] getWritableHyperlinks()
          Gets the writable hyperlinks on this sheet
 void insertColumn(int col)
          Inserts a blank column into this spreadsheet.
 void insertRow(int row)
          Inserts a blank row into this spreadsheet.
 boolean isHidden()
          Deprecated. in favour of the getSettings() method
 boolean isProtected()
          Deprecated. in favour of getSettings() api
 Range mergeCells(int col1, int row1, int col2, int row2)
          Merges the specified cells.
(package private)  void rationalize(IndexMapping xfMapping, IndexMapping fontMapping, IndexMapping formatMapping)
          Rationalizes the sheets xf index mapping
 void removeColumn(int col)
          Removes a column from this spreadsheet.
 void removeHyperlink(WritableHyperlink h)
          Removes the specified hyperlink.
 void removeHyperlink(WritableHyperlink h, boolean preserveLabel)
          Removes the specified hyperlink.
 void removeRow(int row)
          Removes a row from this spreadsheet.
 void setColumnView(int col, int width)
          Sets the width (in characters) for a particular column in this sheet
 void setColumnView(int col, int width, CellFormat format)
          Sets the width (in characters) and format options for a particular column in this sheet
 void setFooter(java.lang.String l, java.lang.String c, java.lang.String r)
          Sets the footer for this page
 void setHeader(java.lang.String l, java.lang.String c, java.lang.String r)
          Sets the header for this page
 void setHidden(boolean h)
          Deprecated. use the settings bean instead
 void setName(java.lang.String n)
          Sets the name of this worksheet
 void setPageSetup(PageOrientation p)
          Deprecated. use the SheetSettings bean
 void setPageSetup(PageOrientation p, double hm, double fm)
          Deprecated. use the SheetSettings bean
 void setPageSetup(PageOrientation p, PaperSize ps, double hm, double fm)
          Deprecated. use the SheetSettings bean
 void setProtected(boolean prot)
          Deprecated. use the settings bean instead
 void setRowView(int row, boolean collapsed)
          Sets the height of the specified row, as well as its collapse status
 void setRowView(int row, int height)
          Sets the height of the specified row, as well as its collapse status
 void setRowView(int row, int height, boolean collapsed)
          Sets the height of the specified row, as well as its collapse status
 void setSelected()
          Deprecated. use the settings bean
 void unmergeCells(Range r)
          Unmerges the specified cells.
 void write()
          Writes out this sheet.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

name

private java.lang.String name
The name of this sheet

outputFile

private File outputFile
A handle to the output file which the binary data is written to

rows

private RowRecord[] rows
The rows within this sheet

formatRecords

private FormattingRecords formatRecords
A handle to workbook format records

sharedStrings

private SharedStrings sharedStrings
A handle to the shared strings used by this workbook

columnFormats

private java.util.TreeSet columnFormats
The list of non-default column formats

hyperlinks

private java.util.ArrayList hyperlinks
The list of hyperlinks

mergedCells

private java.util.ArrayList mergedCells
The list of merged ranged

numRows

private int numRows
A number of rows. This is a count of the maximum row number + 1

numColumns

private int numColumns
The number of columns. This is a count of the maximum column number + 1

rowBreaks

private java.util.ArrayList rowBreaks
Array of row page breaks

settings

private SheetSettings settings
The settings for this sheet

sheetWriter

private SheetWriter sheetWriter
The sheet writer engine

workbookSettings

private WorkbookSettings workbookSettings
The settings for the workbook

workbook

private WritableWorkbookImpl workbook
The workbook

rowGrowSize

private static final int rowGrowSize
The amount by which to grow the rows array

numRowsPerSheet

private static final int numRowsPerSheet
The maximum number of rows excel allows in a worksheet
Constructor Detail

WritableSheetImpl

public WritableSheetImpl(java.lang.String n,
                         File of,
                         FormattingRecords fr,
                         SharedStrings ss,
                         WorkbookSettings ws,
                         WritableWorkbookImpl ww)
Constructor
Parameters:
fr - the formatting records used by the workbook
of - the output file to write the binary data
f - the fonts used by the workbook
n - the name of this sheet
ss - the shared strings used by the workbook
ws - the workbook settings
Method Detail

getCell

public Cell getCell(int column,
                    int row)
Returns the cell specified at this row and at this column
Specified by:
getCell in interface Sheet
Parameters:
column - the column number
row - the row number
Returns:
the cell at the specified co-ordinates

getWritableCell

public WritableCell getWritableCell(int column,
                                    int row)
Returns the cell specified at this row and at this column
Specified by:
getWritableCell in interface WritableSheet
Parameters:
column - the column number
row - the row number
Returns:
the cell at the specified co-ordinates

getRows

public int getRows()
Returns the number of rows in this sheet
Specified by:
getRows in interface Sheet
Returns:
the number of rows in this sheet

getColumns

public int getColumns()
Returns the number of columns in this sheet
Specified by:
getColumns in interface Sheet
Returns:
the number of columns in this sheet

findCell

public Cell findCell(java.lang.String contents)
Gets the cell whose contents match the string passed in. If no match is found, then null is returned. The search is performed on a row by row basis, so the lower the row number, the more efficiently the algorithm will perform
Specified by:
findCell in interface Sheet
Parameters:
contents - the string to match
Returns:
the Cell whose contents match the parameter, null if not found

findLabelCell

public LabelCell findLabelCell(java.lang.String contents)
Gets the cell whose contents match the string passed in. If no match is found, then null is returned. The search is performed on a row by row basis, so the lower the row number, the more efficiently the algorithm will perform. This method differs from the findCell methods in that only cells with labels are queried - all numerical cells are ignored. This should therefore improve performance.
Specified by:
findLabelCell in interface Sheet
Parameters:
contents - the string to match
Returns:
the Cell whose contents match the paramter, null if not found

getRow

public Cell[] getRow(int row)
Gets all the cells on the specified row
Specified by:
getRow in interface Sheet
Parameters:
row - the rows whose cells are to be returned
Returns:
the cells on the given row

getColumn

public Cell[] getColumn(int col)
Gets all the cells on the specified column
Specified by:
getColumn in interface Sheet
Parameters:
col - the column whose cells are to be returned
Returns:
the cells on the specified column

getName

public java.lang.String getName()
Gets the name of this sheet
Specified by:
getName in interface Sheet
Returns:
the name of the sheet

insertRow

public void insertRow(int row)
Inserts a blank row into this spreadsheet. If the row is out of range of the rows in the sheet, then no action is taken
Specified by:
insertRow in interface WritableSheet
Parameters:
row - the row to insert

insertColumn

public void insertColumn(int col)
Inserts a blank column into this spreadsheet. If the column is out of range of the columns in the sheet, then no action is taken
Specified by:
insertColumn in interface WritableSheet
Parameters:
col - the column to insert

removeColumn

public void removeColumn(int col)
Removes a column from this spreadsheet. If the column is out of range of the columns in the sheet, then no action is taken
Specified by:
removeColumn in interface WritableSheet
Parameters:
col - the column to remove

removeRow

public void removeRow(int row)
Removes a row from this spreadsheet. If the row is out of range of the columns in the sheet, then no action is taken
Specified by:
removeRow in interface WritableSheet
Parameters:
row - the row to remove

addCell

public void addCell(WritableCell cell)
             throws WriteException,
                    RowsExceededException
Adds the cell to this sheet. If the cell has already been added to this sheet or another sheet, a WriteException is thrown. If the position to be occupied by this cell is already taken, the incumbent cell is replaced. The cell is then marked as referenced, and its formatting information registered with the list of formatting records updated if necessary The RowsExceededException may be caught if client code wishes to explicitly trap the case where too many rows have been written to the current sheet. If this behaviour is not desired, it is sufficient simply to handle the WriteException, since this is a base class of RowsExceededException
Specified by:
addCell in interface WritableSheet
Parameters:
cell - the cell to add
Throws:
WriteException -  
RowsExceededException -  

getRowRecord

private RowRecord getRowRecord(int row)
                        throws RowsExceededException
Gets the row record at the specified row number, growing the array as needs dictate
Parameters:
row - the row number we are interested in
Returns:
the row record at the specified row
Throws:
RowsExceededException -  

getRowInfo

RowRecord getRowInfo(int r)
Gets the row record for the specified row
Parameters:
r - the row
Returns:
the row record

getColumnInfo

ColumnInfoRecord getColumnInfo(int c)
Gets the column info record for the specified column
Parameters:
c - the column
Returns:
the column record

setName

public void setName(java.lang.String n)
Sets the name of this worksheet
Specified by:
setName in interface WritableSheet
Parameters:
n - the name of this sheet

setHidden

public void setHidden(boolean h)
Deprecated. use the settings bean instead

Sets the hidden status of this sheet
Specified by:
setHidden in interface WritableSheet
Parameters:
h - the hiden flag

setProtected

public void setProtected(boolean prot)
Deprecated. use the settings bean instead

Indicates whether or not this sheet is protected
Specified by:
setProtected in interface WritableSheet
Parameters:
prot - protected flag

setSelected

public void setSelected()
Deprecated. use the settings bean

Sets this sheet as selected

isHidden

public boolean isHidden()
Deprecated. in favour of the getSettings() method

Retrieves the hidden status of this sheet
Specified by:
isHidden in interface Sheet
Returns:
TRUE if hidden, FALSE otherwise

setColumnView

public void setColumnView(int col,
                          int width)
Sets the width (in characters) for a particular column in this sheet
Specified by:
setColumnView in interface WritableSheet
Parameters:
col - the column whose width to set
width - the width of the column in characters

setColumnView

public void setColumnView(int col,
                          int width,
                          CellFormat format)
Sets the width (in characters) and format options for a particular column in this sheet
Specified by:
setColumnView in interface WritableSheet
Parameters:
col - the column to set
width - the width in characters
format - the formt details for the column

setRowView

public void setRowView(int row,
                       int height)
                throws RowsExceededException
Sets the height of the specified row, as well as its collapse status
Specified by:
setRowView in interface WritableSheet
Parameters:
row - the row to be formatted
height - the row height in points
Throws:
RowsExceededException -  

setRowView

public void setRowView(int row,
                       boolean collapsed)
                throws RowsExceededException
Sets the height of the specified row, as well as its collapse status
Specified by:
setRowView in interface WritableSheet
Parameters:
row - the row to be formatted
collapsed - indicates whether the row is collapsed
Throws:
RowsExceededException -  

setRowView

public void setRowView(int row,
                       int height,
                       boolean collapsed)
                throws RowsExceededException
Sets the height of the specified row, as well as its collapse status
Specified by:
setRowView in interface WritableSheet
Parameters:
row - the row to be formatted
height - the row height in points
collapsed - indicates whether the row is collapsed
zeroHeight - indicates that the row has zero height
Throws:
RowsExceededException -  

write

public void write()
           throws java.io.IOException
Writes out this sheet. This functionality is delegated off to the SheetWriter class in order to reduce the bloated nature of this source file
Throws:
java.io.IOException -  

copyCells

private void copyCells(Sheet s)
Copies the cell contents from the specified sheet into this one
Parameters:
s - the sheet to copy

copy

void copy(Sheet s)
Copies the specified sheet, row by row and cell by cell
Parameters:
s - the sheet to copy

copy

void copy(WritableSheet s)
Copies the specified sheet, row by row and cell by cell
Parameters:
s - the sheet to copy

getHeader

final HeaderRecord getHeader()
Gets the header. Called when copying sheets
Returns:
the page header

getFooter

final FooterRecord getFooter()
Gets the footer. Called when copying sheets
Returns:
the page footer

isProtected

public boolean isProtected()
Deprecated. in favour of getSettings() api

Determines whether the sheet is protected
Specified by:
isProtected in interface Sheet
Returns:
whether or not the sheet is protected

getHyperlinks

public Hyperlink[] getHyperlinks()
Gets the hyperlinks on this sheet
Specified by:
getHyperlinks in interface Sheet
Returns:
an array of hyperlinks

getMergedCells

public Range[] getMergedCells()
Gets the cells which have been merged on this sheet
Specified by:
getMergedCells in interface Sheet
Returns:
an array of range objects

getWritableHyperlinks

public WritableHyperlink[] getWritableHyperlinks()
Gets the writable hyperlinks on this sheet
Specified by:
getWritableHyperlinks in interface WritableSheet
Returns:
an array of hyperlinks

removeHyperlink

public void removeHyperlink(WritableHyperlink h)
Removes the specified hyperlink. Note that if you merely set the cell contents to be an Empty cell, then the cells containing the hyperlink will still be active. The contents of the cell which activate the hyperlink are removed. The hyperlink passed in must be a hyperlink retrieved using the getHyperlinks method
Specified by:
removeHyperlink in interface WritableSheet
Parameters:
h - the hyperlink to remove.
preserveLabel - if TRUE preserves the label contents, if FALSE removes them

removeHyperlink

public void removeHyperlink(WritableHyperlink h,
                            boolean preserveLabel)
Removes the specified hyperlink. Note that if you merely set the cell contents to be an Empty cell, then the cells containing the hyperlink will still be active. If the preserveLabel field is set, the cell contents of the hyperlink are preserved, although the hyperlink is deactivated. If this value is FALSE, the cell contents are removed The hyperlink passed in must be a hyperlink retrieved using the getHyperlinks method
Specified by:
removeHyperlink in interface WritableSheet
Parameters:
h - the hyperlink to remove.
preserveLabel - if TRUE preserves the label contents, if FALSE removes them

addHyperlink

public void addHyperlink(WritableHyperlink h)
                  throws WriteException,
                         RowsExceededException
Adds the specified hyperlink
Specified by:
addHyperlink in interface WritableSheet
Parameters:
the - hyperlink
Throws:
WriteException -  
RowsExceededException -  

mergeCells

public Range mergeCells(int col1,
                        int row1,
                        int col2,
                        int row2)
                 throws WriteException,
                        RowsExceededException
Merges the specified cells. Any clashes or intersections between merged cells are resolved when the spreadsheet is written out
Specified by:
mergeCells in interface WritableSheet
Parameters:
col1 - the column number of the top left cell
row1 - the row number of the top left cell
col2 - the column number of the bottom right cell
row2 - the row number of the bottom right cell
Returns:
the Range object representing the merged cells
Throws:
jxl.write..WriteException -  
RowsExceededException -  

unmergeCells

public void unmergeCells(Range r)
Unmerges the specified cells. The Range passed in should be one that has been previously returned as a result of the getMergedCells method
Specified by:
unmergeCells in interface WritableSheet
Parameters:
r - the range of cells to unmerge

setHeader

public void setHeader(java.lang.String l,
                      java.lang.String c,
                      java.lang.String r)
Sets the header for this page
Specified by:
setHeader in interface WritableSheet
Parameters:
l - the print header to print on the left side
c - the print header to print in the centre
r - the print header to print on the right hand side

setFooter

public void setFooter(java.lang.String l,
                      java.lang.String c,
                      java.lang.String r)
Sets the footer for this page
Specified by:
setFooter in interface WritableSheet
Parameters:
l - the print header to print on the left side
c - the print header to print in the centre
r - the print header to print on the right hand side

setPageSetup

public void setPageSetup(PageOrientation p)
Deprecated. use the SheetSettings bean

Sets the page setup details
Specified by:
setPageSetup in interface WritableSheet
Parameters:
p - the page orientation

setPageSetup

public void setPageSetup(PageOrientation p,
                         double hm,
                         double fm)
Deprecated. use the SheetSettings bean

Sets the page setup details
Specified by:
setPageSetup in interface WritableSheet
Parameters:
p - the page orientation
hm - the header margin, in inches
fm - the footer margin, in inches

setPageSetup

public void setPageSetup(PageOrientation p,
                         PaperSize ps,
                         double hm,
                         double fm)
Deprecated. use the SheetSettings bean

Sets the page setup details
Specified by:
setPageSetup in interface WritableSheet
Parameters:
p - the page orientation
ps - the paper size
hm - the header margin, in inches
fm - the footer margin, in inches

getSettings

public SheetSettings getSettings()
Gets the settings for this sheet
Specified by:
getSettings in interface Sheet
Returns:
the page settings bean

getWorkbookSettings

WorkbookSettings getWorkbookSettings()
Gets the workbook settings

addRowPageBreak

public void addRowPageBreak(int row)
Forces a page break at the specified row
Specified by:
addRowPageBreak in interface WritableSheet
Parameters:
row - the row to break at

getCharts

private Chart[] getCharts()
Accessor for the charts. Used when copying
Returns:
the charts on this sheet

checkMergedBorders

void checkMergedBorders()
Check all the merged cells for borders. Although in an OO sense the logic should belong in this class, in order to reduce the bloated nature of the source code for this object this logic has been delegated to the SheetWriter

getWorkspaceOptions

private WorkspaceInformationRecord getWorkspaceOptions()
Accessor for the workspace options
Returns:
the workspace options

rationalize

void rationalize(IndexMapping xfMapping,
                 IndexMapping fontMapping,
                 IndexMapping formatMapping)
Rationalizes the sheets xf index mapping
Parameters:
xfMapping - the index mapping for XFRecords
fontMapping - the index mapping for fonts
formatMapping - the index mapping for formats

getWorkbook

WritableWorkbookImpl getWorkbook()
Accessor for the workbook
Returns:
the workbook