jxl.biff
Class FormattingRecords

java.lang.Object
  |
  +--jxl.biff.FormattingRecords
Direct Known Subclasses:
WritableFormattingRecords

public class FormattingRecords
extends java.lang.Object

The list of XF records and formatting records for the workbook


Field Summary
private static int customFormatStartIndex
          The start index number for custom format records
private  Fonts fonts
          A handle to the available fonts
private  java.util.HashMap formats
          A hash map of FormatRecords, for random access retrieval when reading in a spreadsheet
private  java.util.ArrayList formatsList
          A list of formats, used when writing out a spreadsheet
private static int maxFormatRecordsIndex
          The maximum number of format records.
private static int minXFRecords
          The minimum number of XF records for a sheet.
private  int nextCustomIndexNumber
          The next available index number for custom format records
private  PaletteRecord palette
          The colour palette
private  java.util.ArrayList xfRecords
          The list of extended format records
 
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.
 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
(package private)  FormatRecord getFormatRecord(int index)
          Gets the format record
 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()
           
 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, registerNatives, toString, wait, wait, wait
 

Field Detail

formats

private java.util.HashMap formats
A hash map of FormatRecords, for random access retrieval when reading in a spreadsheet

formatsList

private java.util.ArrayList formatsList
A list of formats, used when writing out a spreadsheet

xfRecords

private java.util.ArrayList xfRecords
The list of extended format records

nextCustomIndexNumber

private int nextCustomIndexNumber
The next available index number for custom format records

fonts

private Fonts fonts
A handle to the available fonts

palette

private PaletteRecord palette
The colour palette

customFormatStartIndex

private static final int customFormatStartIndex
The start index number for custom format records

maxFormatRecordsIndex

private static final int maxFormatRecordsIndex
The maximum number of format records. This is some weird internal Excel constraint

minXFRecords

private static final int minXFRecords
The minimum number of XF records for a sheet. The rationalization processes commences immediately after this number
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

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

getFormatRecord

FormatRecord getFormatRecord(int index)
Gets the format record
Parameters:
index -  
Returns:
the format record at the specified index

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()

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

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
Parameters:
im - the index mapping for the font rationalization

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:
p - 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)