jxl
Class Workbook

java.lang.Object
  |
  +--jxl.Workbook
Direct Known Subclasses:
WorkbookParser

public abstract class Workbook
extends java.lang.Object

Represents a Workbook. Provides a handle into the individual sheets


Field Summary
private static java.lang.String version
          The current version of the software
 
Constructor Summary
protected Workbook()
          The constructor
 
Method Summary
abstract  void close()
          Closes this workbook, and frees makes any memory allocated available for garbage collection
static WritableWorkbook createWorkbook(java.io.File file)
          Creates a writable workbook with the given file name
static WritableWorkbook createWorkbook(java.io.File file, Workbook in)
          Creates a writable workbook with the given filename as a copy of the workbook passed in.
static WritableWorkbook createWorkbook(java.io.File file, WorkbookSettings ws)
          Creates a writable workbook with the given file name
static WritableWorkbook createWorkbook(java.io.File file, Workbook in, WorkbookSettings ws)
          Creates a writable workbook with the given filename as a copy of the workbook passed in.
static WritableWorkbook createWorkbook(java.io.OutputStream os)
          Creates a writable workbook.
static WritableWorkbook createWorkbook(java.io.OutputStream os, Workbook in)
          Creates a writable workbook as a copy of the workbook passed in.
static WritableWorkbook createWorkbook(java.io.OutputStream os, WorkbookSettings ws)
          Creates a writable workbook.
static WritableWorkbook createWorkbook(java.io.OutputStream os, Workbook in, WorkbookSettings ws)
          Creates a writable workbook as a copy of the workbook passed in.
abstract  Range[] findByName(java.lang.String name)
          Gets the named range from this workbook.
abstract  Cell findCellByName(java.lang.String name)
          Gets the named cell from this workbook.
abstract  int getNumberOfSheets()
          Returns the number of sheets in this workbook
abstract  Sheet getSheet(int index)
          Gets the specified sheet within this workbook As described in the accompanying technical notes, each call to getSheet forces a reread of the sheet (for memory reasons).
abstract  Sheet getSheet(java.lang.String name)
          Gets the sheet with the specified name from within this workbook.
abstract  Sheet[] getSheets()
          Gets the sheets within this workbook.
static java.lang.String getVersion()
          Accessor for the software version
static Workbook getWorkbook(java.io.File file)
          A factory method which takes in an excel file and reads in the contents.
static Workbook getWorkbook(java.io.File file, WorkbookSettings ws)
          A factory method which takes in an excel file and reads in the contents.
static Workbook getWorkbook(java.io.InputStream is)
          A factory method which takes in an excel file and reads in the contents.
static Workbook getWorkbook(java.io.InputStream is, WorkbookSettings ws)
          A factory method which takes in an excel file and reads in the contents.
abstract  boolean isProtected()
          Determines whether the sheet is protected
protected abstract  void parse()
          Parses the excel file.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

version

private static final java.lang.String version
The current version of the software
Constructor Detail

Workbook

protected Workbook()
The constructor
Method Detail

getSheets

public abstract Sheet[] getSheets()
Gets the sheets within this workbook. Use of this method for large worksheets can cause performance problems.
Returns:
an array of the individual sheets

getSheet

public abstract Sheet getSheet(int index)
                        throws java.lang.IndexOutOfBoundsException
Gets the specified sheet within this workbook As described in the accompanying technical notes, each call to getSheet forces a reread of the sheet (for memory reasons). Therefore, do not make unnecessary calls to this method. Furthermore, do not hold unnecessary references to Sheets in client code, as this will prevent the garbage collector from freeing the memory
Parameters:
index - the zero based index of the reQuired sheet
Returns:
The sheet specified by the index
Throws:
IndexOutOfBoundException - when index refers to a non-existent sheet

getSheet

public abstract Sheet getSheet(java.lang.String name)
Gets the sheet with the specified name from within this workbook. As described in the accompanying technical notes, each call to getSheet forces a reread of the sheet (for memory reasons). Therefore, do not make unnecessary calls to this method. Furthermore, do not hold unnecessary references to Sheets in client code, as this will prevent the garbage collector from freeing the memory
Parameters:
name - the sheet name
Returns:
The sheet with the specified name, or null if it is not found

getVersion

public static java.lang.String getVersion()
Accessor for the software version
Returns:
the version

getNumberOfSheets

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

findCellByName

public abstract Cell findCellByName(java.lang.String name)
Gets the named cell from this workbook. The name refers to a range of cells, then the cell on the top left is returned. If the name cannot be, null is returned. This is a convenience function to quickly access the contents of a single cell. If you need further information (such as the sheet or adjacent cells in the range) use the functionally richer method, findByName which returns a list of ranges
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 abstract 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
Parameters:
name - the name of the cell/range to search for
Returns:
the range of cells, or NULL if the range does not exist

isProtected

public abstract boolean isProtected()
Determines whether the sheet is protected
Returns:
TRUE if the workbook is protected, FALSE otherwise

parse

protected abstract void parse()
                       throws BiffException,
                              PasswordException
Parses the excel file. If the workbook is password protected a PasswordException is thrown in case consumers of the API wish to handle this in a particular way
Throws:
BiffException -  
PasswordException -  

close

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

getWorkbook

public static Workbook getWorkbook(java.io.File file)
                            throws java.io.IOException,
                                   BiffException
A factory method which takes in an excel file and reads in the contents.
Parameters:
file - the excel 97 spreadsheet to parse
Returns:
a workbook instance
Throws:
java.io.IOException -  
BiffException -  

getWorkbook

public static Workbook getWorkbook(java.io.File file,
                                   WorkbookSettings ws)
                            throws java.io.IOException,
                                   BiffException
A factory method which takes in an excel file and reads in the contents.
Parameters:
file - the excel 97 spreadsheet to parse
ws - the settings for the workbook
Returns:
a workbook instance
Throws:
java.io.IOException -  
BiffException -  

getWorkbook

public static Workbook getWorkbook(java.io.InputStream is)
                            throws java.io.IOException,
                                   BiffException
A factory method which takes in an excel file and reads in the contents.
Parameters:
is - an open stream which is the the excel 97 spreadsheet to parse
Returns:
a workbook instance
Throws:
java.io.IOException -  
BiffException -  

getWorkbook

public static Workbook getWorkbook(java.io.InputStream is,
                                   WorkbookSettings ws)
                            throws java.io.IOException,
                                   BiffException
A factory method which takes in an excel file and reads in the contents.
Parameters:
is - an open stream which is the the excel 97 spreadsheet to parse
ws - the settings for the workbook
Returns:
a workbook instance
Throws:
java.io.IOException -  
BiffException -  

createWorkbook

public static WritableWorkbook createWorkbook(java.io.File file)
                                       throws java.io.IOException
Creates a writable workbook with the given file name
Returns:
a writable workbook

createWorkbook

public static WritableWorkbook createWorkbook(java.io.File file,
                                              WorkbookSettings ws)
                                       throws java.io.IOException
Creates a writable workbook with the given file name
Parameters:
ws - the global workbook settings
Returns:
a writable workbook

createWorkbook

public static WritableWorkbook createWorkbook(java.io.File file,
                                              Workbook in)
                                       throws java.io.IOException
Creates a writable workbook with the given filename as a copy of the workbook passed in. Once created, the contents of the writable workbook may be modified
Parameters:
file - the output file for the copy
in - the workbook to copy
Returns:
a writable workbook

createWorkbook

public static WritableWorkbook createWorkbook(java.io.File file,
                                              Workbook in,
                                              WorkbookSettings ws)
                                       throws java.io.IOException
Creates a writable workbook with the given filename as a copy of the workbook passed in. Once created, the contents of the writable workbook may be modified
Parameters:
file - the output file for the copy
in - the workbook to copy
ws - the configuration for this workbook
Returns:
a writable workbook

createWorkbook

public static WritableWorkbook createWorkbook(java.io.OutputStream os,
                                              Workbook in)
                                       throws java.io.IOException
Creates a writable workbook as a copy of the workbook passed in. Once created, the contents of the writable workbook may be modified
Parameters:
file - the output file for the copy
in - the workbook to copy
Returns:
a writable workbook

createWorkbook

public static WritableWorkbook createWorkbook(java.io.OutputStream os,
                                              Workbook in,
                                              WorkbookSettings ws)
                                       throws java.io.IOException
Creates a writable workbook as a copy of the workbook passed in. Once created, the contents of the writable workbook may be modified
Parameters:
file - the output file for the copy
in - the workbook to copy
ws - the configuration for this workbook
Returns:
a writable workbook

createWorkbook

public static WritableWorkbook createWorkbook(java.io.OutputStream os)
                                       throws java.io.IOException
Creates a writable workbook. When the workbook is closed, it will be streamed directly to the output stream. In this manner, a generated excel spreadsheet can be passed from a servlet to the browser over HTTP
Parameters:
os - the output stream
Returns:
the writable workbook

createWorkbook

public static WritableWorkbook createWorkbook(java.io.OutputStream os,
                                              WorkbookSettings ws)
                                       throws java.io.IOException
Creates a writable workbook. When the workbook is closed, it will be streamed directly to the output stream. In this manner, a generated excel spreadsheet can be passed from a servlet to the browser over HTTP
Parameters:
os - the output stream
ws - the configuration for this workbook
Returns:
the writable workbook