jxl.biff
Class FormattingRecords

java.lang.Object
  extended byjxl.biff.FormattingRecords
Direct Known Subclasses:
WritableFormattingRecords

public class FormattingRecords
extends java.lang.Object

The list of XF records and formatting records for the workbook


Constructor Summary
FormattingRecords(Fonts f)
          Constructor
 
Method Summary
 void addFormat(DisplayFormat fr)
          Adds a cell format to the hash map, keyed on its index.
 void addStyle(XFRecord xf)
          Adds an extended formatting record to the list.
 RGB getColourRGB(Colour c)
          Accessor for the RGB value for the specified colour
 java.text.DateFormat getDateFormat(int pos)
          Gets the DateFormat used to format the cell.
protected  Fonts getFonts()
          Accessor for the fonts used by this workbook
 java.text.NumberFormat getNumberFormat(int pos)
          Gets the NumberFormat used to format the cell.
protected  int getNumberOfFormatRecords()
          Gets the number of formatting records on the list.
 PaletteRecord getPalette()
          Accessor for the colour palette
 XFRecord getXFRecord(int index)
          Gets the XFRecord for the specified index.
 boolean isDate(int pos)
          Sees if the extended formatting record at the specified position represents a date.
 IndexMapping rationalize(IndexMapping fontMapping, IndexMapping formatMapping)
          Rationalizes the cell formats.
 IndexMapping rationalizeDisplayFormats()
          Rationalizes the display formats.
 IndexMapping rationalizeFonts()
          Rationalizes all the fonts, removing duplicate entries
 void setColourRGB(Colour c, int r, int g, int b)
          Sets the RGB value for the specified colour for this workbook
 void setPalette(PaletteRecord pr)
          Called from the WorkbookParser to set the colour palette
 void write(File outputFile)
          Writes out all the format records and the XF records
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormattingRecords

public FormattingRecords(Fonts f)
Constructor

Parameters:
f - the container for the fonts
Method Detail

addStyle

public final void addStyle(XFRecord xf)
                    throws NumFormatRecordsException
Adds an extended formatting record to the list. If the XF record passed in has not been initialized, its index is determined based on the xfRecords list, and this position is passed to the XF records initialize method

Parameters:
xf - the xf record to add
Throws:
NumFormatRecordsException

addFormat

public final void addFormat(DisplayFormat fr)
                     throws NumFormatRecordsException
Adds a cell format to the hash map, keyed on its index. If the format record is not initialized, then its index number is determined and its initialize method called. If the font is not a built in format, then it is added to the list of formats for writing out

Parameters:
fr - the format record
Throws:
NumFormatRecordsException

isDate

public final boolean isDate(int pos)
Sees if the extended formatting record at the specified position represents a date. First checks against the built in formats, and then checks against the hash map of FormatRecords

Parameters:
pos - the xf format index
Returns:
TRUE if this format index is formatted as a Date

getDateFormat

public final java.text.DateFormat getDateFormat(int pos)
Gets the DateFormat used to format the cell.

Parameters:
pos - the xf format index
Returns:
the DateFormat object used to format the date in the original excel cell

getNumberFormat

public final java.text.NumberFormat getNumberFormat(int pos)
Gets the NumberFormat used to format the cell.

Parameters:
pos - the xf format index
Returns:
the DateFormat object used to format the date in the original excel cell

write

public void write(File outputFile)
           throws java.io.IOException
Writes out all the format records and the XF records

Parameters:
outputFile - the file to write to
Throws:
java.io.IOException

getFonts

protected final Fonts getFonts()
Accessor for the fonts used by this workbook

Returns:
the fonts container

getXFRecord

public final XFRecord getXFRecord(int index)
Gets the XFRecord for the specified index. Used when copying individual cells

Parameters:
index - the XF record to retrieve
Returns:
the XF record at the specified index

getNumberOfFormatRecords

protected final int getNumberOfFormatRecords()
Gets the number of formatting records on the list. This is used by the writable subclass because there is an upper limit on the amount of format records that are allowed to be present in an excel sheet

Returns:
the number of format records present

rationalizeFonts

public IndexMapping rationalizeFonts()
Rationalizes all the fonts, removing duplicate entries

Returns:
the list of new font index number

rationalize

public IndexMapping rationalize(IndexMapping fontMapping,
                                IndexMapping formatMapping)
Rationalizes the cell formats. Duplicate formats are removed and the format indexed of the cells adjusted accordingly

Parameters:
fontMapping - the font mapping index numbers
formatMapping - the format mapping index numbers
Returns:
the list of new font index number

rationalizeDisplayFormats

public IndexMapping rationalizeDisplayFormats()
Rationalizes the display formats. Duplicate formats are removed and the format indices of the cells adjusted accordingly. It is invoked immediately prior to writing writing out the sheet

Returns:
the index mapping between the old display formats and the rationalized ones

getPalette

public PaletteRecord getPalette()
Accessor for the colour palette

Returns:
the palette

setPalette

public void setPalette(PaletteRecord pr)
Called from the WorkbookParser to set the colour palette

Parameters:
pr - the palette

setColourRGB

public void setColourRGB(Colour c,
                         int r,
                         int g,
                         int b)
Sets the RGB value for the specified colour for this workbook

Parameters:
c - the colour whose RGB value is to be overwritten
r - the red portion to set (0-255)
g - the green portion to set (0-255)
b - the blue portion to set (0-255)

getColourRGB

public RGB getColourRGB(Colour c)
Accessor for the RGB value for the specified colour

Returns:
the RGB for the specified colour