jxl

Class Workbook


public abstract class Workbook
extends java.lang.Object

Represents a Workbook. Contains the various factory methods and provides a variety of accessors which provide access to the work sheets.

Method Summary

abstract void
close()
Closes this workbook, and frees makes any memory allocated available for garbage collection
static WritableWorkbook
createWorkbook(OutputStream os)
Creates a writable workbook.
static WritableWorkbook
createWorkbook(OutputStream os, Workbook in)
Creates a writable workbook as a copy of the workbook passed in.
static WritableWorkbook
createWorkbook(OutputStream os, Workbook in, WorkbookSettings ws)
Creates a writable workbook as a copy of the workbook passed in.
static WritableWorkbook
createWorkbook(OutputStream os, WorkbookSettings ws)
Creates a writable workbook.
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, 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.File file, WorkbookSettings ws)
Creates a writable workbook with the given file name
abstract Range[]
findByName(String name)
Gets the named range from this workbook.
abstract Cell
findCellByName(String name)
Gets the named cell from this workbook.
abstract Cell
getCell(String loc)
Returns the cell for the specified location eg.
abstract int
getNumberOfSheets()
Returns the number of sheets in this workbook
abstract String[]
getRangeNames()
Gets the named ranges
abstract Sheet
getSheet(String name)
Gets the sheet with the specified name from within 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 String[]
getSheetNames()
Gets the sheet names
abstract Sheet[]
getSheets()
Gets the sheets within this workbook.
static String
getVersion()
Accessor for the software version
static Workbook
getWorkbook(InputStream is)
A factory method which takes in an excel file and reads in the contents.
static Workbook
getWorkbook(InputStream is, WorkbookSettings ws)
A factory method which takes in an excel file and reads in the contents.
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.
abstract boolean
isProtected()
Determines whether the sheet is protected

Method Details

close

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

createWorkbook

public static WritableWorkbook createWorkbook(OutputStream os)
            throws 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(OutputStream os,
                                              Workbook in)
            throws 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:
os - the stream to write to
in - the workbook to copy
Returns:
a writable workbook

createWorkbook

public static WritableWorkbook createWorkbook(OutputStream os,
                                              Workbook in,
                                              WorkbookSettings ws)
            throws 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:
os - the output stream to write to
in - the workbook to copy
ws - the configuration for this workbook
Returns:
a writable workbook

createWorkbook

public static WritableWorkbook createWorkbook(OutputStream os,
                                              WorkbookSettings ws)
            throws 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

createWorkbook

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

createWorkbook

public static WritableWorkbook createWorkbook(java.io.File file,
                                              Workbook in)
            throws 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 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.File file,
                                              WorkbookSettings ws)
            throws IOException
Creates a writable workbook with the given file name
Parameters:
file - the file to copy from
ws - the global workbook settings
Returns:
a writable workbook

findByName

public abstract Range[] findByName(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

findCellByName

public abstract Cell findCellByName(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. 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

getCell

public abstract Cell getCell(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
Parameters:
loc - the cell to retrieve
Returns:
the cell at the specified location

getNumberOfSheets

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

getRangeNames

public abstract String[] getRangeNames()
Gets the named ranges
Returns:
the list of named cells within the workbook

getSheet

public abstract Sheet getSheet(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

getSheet

public abstract Sheet getSheet(int index)
            throws 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

getSheetNames

public abstract String[] getSheetNames()
Gets the sheet names
Returns:
an array of strings containing the sheet names

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

getVersion

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

getWorkbook

public static Workbook getWorkbook(InputStream is)
            throws IOException,
                   jxl.read.biff.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:
jxl.read.biff.BiffException -

getWorkbook

public static Workbook getWorkbook(InputStream is,
                                   WorkbookSettings ws)
            throws IOException,
                   jxl.read.biff.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:
jxl.read.biff.BiffException -

getWorkbook

public static Workbook getWorkbook(java.io.File file)
            throws IOException,
                   jxl.read.biff.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:
jxl.read.biff.BiffException -

getWorkbook

public static Workbook getWorkbook(java.io.File file,
                                   WorkbookSettings ws)
            throws IOException,
                   jxl.read.biff.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:
jxl.read.biff.BiffException -

isProtected

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