jxl.read.biff
Class WorkbookParser

java.lang.Object
  extended byjxl.Workbook
      extended byjxl.read.biff.WorkbookParser
All Implemented Interfaces:
ExternalSheet, WorkbookMethods

public class WorkbookParser
extends Workbook
implements ExternalSheet, WorkbookMethods

Parses the biff file passed in, and builds up an internal representation of the spreadsheet


Constructor Summary
WorkbookParser(File f, WorkbookSettings s)
          Constructs this object from the raw excel data
 
Method Summary
 void close()
          Closes this workbook, and frees makes any memory allocated available for garbage collection
 boolean containsMacros()
          Accessor for the containsMacros
 Range[] findByName(java.lang.String name)
          Gets the named range from this workbook.
 Cell findCellByName(java.lang.String name)
          Gets the named cell from this workbook.
 ButtonPropertySetRecord getButtonPropertySet()
          Accessor for the button property set, used during copying
 Cell getCell(java.lang.String loc)
          Returns the cell for the specified location eg.
 CompoundFile getCompoundFile()
          Accessor for the CompoundFile.
 CountryRecord getCountryRecord()
          Accessor for the country record, using during copying
 DrawingGroup getDrawingGroup()
          Accessor for the drawing group
 int getExternalSheetIndex(int index)
          Package protected function which gets the real internal sheet index based upon the external sheet reference.
 int getExternalSheetIndex(java.lang.String sheetName)
          Accessor/implementation method for the external sheet reference
 java.lang.String getExternalSheetName(int index)
          Gets the name of the external sheet specified by the index
 ExternalSheetRecord getExternalSheetRecord()
          Accessor for the externSheet, used by the WritableWorkbook when creating a copy of this
 Fonts getFonts()
          Accessor for the fonts, used by the WritableWorkbook when creating a copy of this
 FormattingRecords getFormattingRecords()
          Accessor for the formattingRecords, used by the WritableWorkbook when creating a copy of this
 int getLastExternalSheetIndex(int index)
          Package protected function which gets the real internal sheet index based upon the external sheet reference.
 int getLastExternalSheetIndex(java.lang.String sheetName)
          Accessor/implementation method for the external sheet reference
 java.lang.String getLastExternalSheetName(int index)
          Gets the name of the external sheet specified by the index
 MsoDrawingGroupRecord getMsoDrawingGroupRecord()
          Accessor for the MsoDrawingGroup, used by the WritableWorkbook when creating a copy of this
 java.lang.String getName(int index)
          Gets the name at the specified index
 int getNameIndex(java.lang.String name)
          Gets the index of the name record for the name
 NameRecord[] getNameRecords()
          Accessor for the name records.
 int getNumberOfSheets()
          Returns the number of sheets in this workbook
 java.lang.String[] getRangeNames()
          Gets the named ranges
 Sheet getReadSheet(int index)
          Interface method from WorkbookMethods - gets the specified sheet within this workbook
 WorkbookSettings getSettings()
          Accessor for the settings
 Sheet getSheet(int index)
          Gets the specified sheet within this workbook
 Sheet getSheet(java.lang.String name)
          Gets the sheet with the specified name from within this workbook
 java.lang.String[] getSheetNames()
          Gets the sheet names
 Sheet[] getSheets()
          Gets the sheets within this workbook.
 SupbookRecord[] getSupbookRecords()
          Accessor for the supbook records, used by the WritableWorkbook when creating a copy of this
 BOFRecord getWorkbookBof()
          Method used when parsing formulas to make sure we are trying to parse a supported biff version
 boolean isProtected()
          Determines whether the sheet is protected
protected  void parse()
          Does the hard work of building up the object graph from the excel bytes
 
Methods inherited from class jxl.Workbook
createWorkbook, createWorkbook, createWorkbook, createWorkbook, createWorkbook, createWorkbook, createWorkbook, createWorkbook, getVersion, getWorkbook, getWorkbook, getWorkbook, getWorkbook
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkbookParser

public WorkbookParser(File f,
                      WorkbookSettings s)
Constructs this object from the raw excel data

Parameters:
f - the excel 97 biff file
s - the workbook settings
Method Detail

getSheets

public Sheet[] getSheets()
Gets the sheets within this workbook. NOTE: Use of this method for very large worksheets can cause performance and out of memory problems. Use the alternative method getSheet() to retrieve each sheet individually

Specified by:
getSheets in class Workbook
Returns:
an array of the individual sheets

getReadSheet

public Sheet getReadSheet(int index)
Interface method from WorkbookMethods - gets the specified sheet within this workbook

Specified by:
getReadSheet in interface WorkbookMethods
Parameters:
index - the zero based index of the required sheet
Returns:
The sheet specified by the index

getSheet

public Sheet getSheet(int index)
Gets the specified sheet within this workbook

Specified by:
getSheet in class Workbook
Parameters:
index - the zero based index of the required sheet
Returns:
The sheet specified by the index

getSheet

public Sheet getSheet(java.lang.String name)
Gets the sheet with the specified name from within this workbook

Specified by:
getSheet in class Workbook
Parameters:
name - the sheet name
Returns:
The sheet with the specified name, or null if it is not found

getSheetNames

public java.lang.String[] getSheetNames()
Gets the sheet names

Specified by:
getSheetNames in class Workbook
Returns:
an array of strings containing the sheet names

getExternalSheetIndex

public int getExternalSheetIndex(int index)
Package protected function which gets the real internal sheet index based upon the external sheet reference. This is used for extern sheet references which are specified in formulas

Specified by:
getExternalSheetIndex in interface ExternalSheet
Parameters:
index - the external sheet reference
Returns:
the actual sheet index

getLastExternalSheetIndex

public int getLastExternalSheetIndex(int index)
Package protected function which gets the real internal sheet index based upon the external sheet reference. This is used for extern sheet references which are specified in formulas

Specified by:
getLastExternalSheetIndex in interface ExternalSheet
Parameters:
index - the external sheet reference
Returns:
the actual sheet index

getExternalSheetName

public java.lang.String getExternalSheetName(int index)
Gets the name of the external sheet specified by the index

Specified by:
getExternalSheetName in interface ExternalSheet
Parameters:
index - the external sheet index
Returns:
the name of the external sheet

getLastExternalSheetName

public java.lang.String getLastExternalSheetName(int index)
Gets the name of the external sheet specified by the index

Parameters:
index - the external sheet index
Returns:
the name of the external sheet

getNumberOfSheets

public int getNumberOfSheets()
Returns the number of sheets in this workbook

Specified by:
getNumberOfSheets in class Workbook
Returns:
the number of sheets in this workbook

close

public void close()
Closes this workbook, and frees makes any memory allocated available for garbage collection

Specified by:
close in class Workbook

parse

protected void parse()
              throws BiffException,
                     PasswordException
Does the hard work of building up the object graph from the excel bytes

Specified by:
parse in class Workbook
Throws:
BiffException
PasswordException - if the workbook is password protected

getFormattingRecords

public FormattingRecords getFormattingRecords()
Accessor for the formattingRecords, used by the WritableWorkbook when creating a copy of this

Returns:
the formatting records

getExternalSheetRecord

public ExternalSheetRecord getExternalSheetRecord()
Accessor for the externSheet, used by the WritableWorkbook when creating a copy of this

Returns:
the external sheet record

getMsoDrawingGroupRecord

public MsoDrawingGroupRecord getMsoDrawingGroupRecord()
Accessor for the MsoDrawingGroup, used by the WritableWorkbook when creating a copy of this

Returns:
the Mso Drawing Group record

getSupbookRecords

public SupbookRecord[] getSupbookRecords()
Accessor for the supbook records, used by the WritableWorkbook when creating a copy of this

Returns:
the supbook records

getNameRecords

public NameRecord[] getNameRecords()
Accessor for the name records. Used by the WritableWorkbook when creating a copy of this

Returns:
the array of names

getFonts

public Fonts getFonts()
Accessor for the fonts, used by the WritableWorkbook when creating a copy of this

Returns:
the fonts used in this workbook

getCell

public Cell getCell(java.lang.String loc)
Returns the cell for the specified location eg. "Sheet1!A4". This is identical to using the CellReferenceHelper with its associated performance overheads, consequently it should be use sparingly

Specified by:
getCell in class Workbook
Parameters:
loc - the cell to retrieve
Returns:
the cell at the specified location

findCellByName

public Cell findCellByName(java.lang.String name)
Gets the named cell from this workbook. If the name refers to a range of cells, then the cell on the top left is returned. If the name cannot be found, null is returned

Specified by:
findCellByName in class Workbook
Parameters:
name - the name of the cell/range to search for
Returns:
the cell in the top left of the range if found, NULL otherwise

findByName

public Range[] findByName(java.lang.String name)
Gets the named range from this workbook. The Range object returns contains all the cells from the top left to the bottom right of the range. If the named range comprises an adjacent range, the Range[] will contain one object; for non-adjacent ranges, it is necessary to return an array of length greater than one. If the named range contains a single cell, the top left and bottom right cell will be the same cell

Specified by:
findByName in class Workbook
Parameters:
name - the name to find
Returns:
the range of cells

getRangeNames

public java.lang.String[] getRangeNames()
Gets the named ranges

Specified by:
getRangeNames in class Workbook
Returns:
the list of named cells within the workbook

getWorkbookBof

public BOFRecord getWorkbookBof()
Method used when parsing formulas to make sure we are trying to parse a supported biff version

Specified by:
getWorkbookBof in interface ExternalSheet
Returns:
the BOF record

isProtected

public boolean isProtected()
Determines whether the sheet is protected

Specified by:
isProtected in class Workbook
Returns:
whether or not the sheet is protected

getSettings

public WorkbookSettings getSettings()
Accessor for the settings

Returns:
the workbook settings

getExternalSheetIndex

public int getExternalSheetIndex(java.lang.String sheetName)
Accessor/implementation method for the external sheet reference

Specified by:
getExternalSheetIndex in interface ExternalSheet
Parameters:
sheetName - the sheet name to look for
Returns:
the external sheet index

getLastExternalSheetIndex

public int getLastExternalSheetIndex(java.lang.String sheetName)
Accessor/implementation method for the external sheet reference

Specified by:
getLastExternalSheetIndex in interface ExternalSheet
Parameters:
sheetName - the sheet name to look for
Returns:
the external sheet index

getName

public java.lang.String getName(int index)
Gets the name at the specified index

Specified by:
getName in interface WorkbookMethods
Parameters:
index - the index into the name table
Returns:
the name of the cell

getNameIndex

public int getNameIndex(java.lang.String name)
Gets the index of the name record for the name

Specified by:
getNameIndex in interface WorkbookMethods
Parameters:
name - the name to search for
Returns:
the index in the name table

getDrawingGroup

public DrawingGroup getDrawingGroup()
Accessor for the drawing group

Returns:
the drawing group

getCompoundFile

public CompoundFile getCompoundFile()
Accessor for the CompoundFile. For this feature to return non-null value, the propertySets feature in WorkbookSettings must be enabled and the workbook must contain additional property sets. This method is used during the workbook copy

Returns:
the base compound file if it contains additional data items and property sets are enabled

containsMacros

public boolean containsMacros()
Accessor for the containsMacros

Returns:
TRUE if this workbook contains macros, FALSE otherwise

getButtonPropertySet

public ButtonPropertySetRecord getButtonPropertySet()
Accessor for the button property set, used during copying

Returns:
the button property set

getCountryRecord

public CountryRecord getCountryRecord()
Accessor for the country record, using during copying

Returns:
the country record read in