jxl.write.biff
Class WritableWorkbookImpl

java.lang.Object
  extended byjxl.write.WritableWorkbook
      extended byjxl.write.biff.WritableWorkbookImpl
All Implemented Interfaces:
ExternalSheet, WorkbookMethods

public class WritableWorkbookImpl
extends WritableWorkbook
implements ExternalSheet, WorkbookMethods

A writable workbook


Field Summary
 
Fields inherited from class jxl.write.WritableWorkbook
ARIAL_10_PT, HIDDEN_STYLE, HYPERLINK_FONT, HYPERLINK_STYLE, NORMAL_STYLE
 
Constructor Summary
WritableWorkbookImpl(java.io.OutputStream os, boolean cs, WorkbookSettings ws)
          Constructor.
WritableWorkbookImpl(java.io.OutputStream os, Workbook w, boolean cs, WorkbookSettings ws)
          A pseudo copy constructor.
 
Method Summary
 void addNameArea(java.lang.String name, WritableSheet sheet, int firstCol, int firstRow, int lastCol, int lastRow)
          Add new named area to this workbook with the given information.
 void close()
          Closes this workbook, and frees makes any memory allocated available for garbage collection
 void copySheet(int s, java.lang.String name, int index)
          Copies the specified sheet and places it at the index specified by the parameter
 void copySheet(java.lang.String s, java.lang.String name, int index)
          Copies the specified sheet and places it at the index specified by the parameter
 WritableSheet createSheet(java.lang.String name, int index)
          Creates a new sheet within the workbook, at the specified position.
 Range[] findByName(java.lang.String name)
          Gets the named range from this workbook.
 WritableCell findCellByName(java.lang.String name)
          Gets the named cell from this workbook.
 RGB getColourRGB(Colour c)
          Accessor for the RGB value for the specified colour
 int getExternalSheetIndex(int index)
          Gets the index of the external sheet for the name
 int getExternalSheetIndex(java.lang.String sheetName)
          Gets the external sheet index for the sheet name
 java.lang.String getExternalSheetName(int index)
          Gets the name of the external sheet specified by the index
 int getLastExternalSheetIndex(int index)
          Gets the index of the external sheet for the name
 int getLastExternalSheetIndex(java.lang.String sheetName)
          Gets the last external sheet index for the sheet name
 java.lang.String getLastExternalSheetName(int index)
          Gets the name of the last external sheet specified by the index
 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
 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
 WritableSheet getSheet(int index)
          Gets the specified sheet within this workbook
 WritableSheet getSheet(java.lang.String name)
          Gets the sheet with the specified name from within this workbook
 java.lang.String[] getSheetNames()
          Gets the sheet names
 WritableSheet[] getSheets()
          Gets the sheets within this workbook.
 BOFRecord getWorkbookBof()
          Parsing of formulas is only supported for a subset of the available biff version, so we need to test to see if this version is acceptable
 WritableCell getWritableCell(java.lang.String loc)
          Returns the cell for the specified location eg.
 WritableSheet moveSheet(int fromIndex, int toIndex)
          Moves the specified sheet within this workbook to another index position.
 void removeSheet(int index)
          Removes a sheet from this workbook, the other sheets indices being altered accordingly.
 void setColourRGB(Colour c, int r, int g, int b)
          Sets the RGB value for the specified colour for this workbook
 void setOutputFile(java.io.File fileName)
          Sets a new output file.
 void setProtected(boolean prot)
          Indicates whether or not this workbook is protected
 void write()
          Writes out this sheet to the output file.
 
Methods inherited from class jxl.write.WritableWorkbook
copy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WritableWorkbookImpl

public WritableWorkbookImpl(java.io.OutputStream os,
                            boolean cs,
                            WorkbookSettings ws)
                     throws java.io.IOException
Constructor. Writes the workbook direct to the existing output stream

Parameters:
os - the output stream
cs - TRUE if the workbook should close the output stream, FALSE
ws - the configuration for this workbook otherwise
Throws:
java.io.IOException

WritableWorkbookImpl

public WritableWorkbookImpl(java.io.OutputStream os,
                            Workbook w,
                            boolean cs,
                            WorkbookSettings ws)
                     throws java.io.IOException
A pseudo copy constructor. Takes the handles to the font and formatting records

Parameters:
w - the workbook to copy
os - the output stream to write the data to
cs - TRUE if the workbook should close the output stream, FALSE
ws - the configuration for this workbook
Throws:
java.io.IOException
Method Detail

getSheets

public WritableSheet[] getSheets()
Gets the sheets within this workbook. Use of this method for large worksheets can cause performance problems.

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

getSheetNames

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

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

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 WritableSheet getSheet(int index)
Gets the specified sheet within this workbook

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

getSheet

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

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

getNumberOfSheets

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

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

close

public void close()
           throws java.io.IOException,
                  JxlWriteException
Closes this workbook, and frees makes any memory allocated available for garbage collection

Specified by:
close in class WritableWorkbook
Throws:
java.io.IOException
JxlWriteException

setOutputFile

public void setOutputFile(java.io.File fileName)
                   throws java.io.IOException
Sets a new output file. This allows the smae workbook to be written to various different output files without having to read in any templates again

Specified by:
setOutputFile in class WritableWorkbook
Parameters:
fileName - the file name
Throws:
java.io.IOException

createSheet

public WritableSheet createSheet(java.lang.String name,
                                 int index)
Creates a new sheet within the workbook, at the specified position. The new sheet is inserted at the specified position, or prepended/appended to the list of sheets if the index specified is somehow inappropriate

Specified by:
createSheet in class WritableWorkbook
Parameters:
name - the name of the new sheet
index - the index at which to add the sheet
Returns:
the created sheet

removeSheet

public void removeSheet(int index)
Removes a sheet from this workbook, the other sheets indices being altered accordingly. If the sheet referenced by the index does not exist, then no action is taken.

Specified by:
removeSheet in class WritableWorkbook
Parameters:
index - the index of the sheet to remove

moveSheet

public WritableSheet moveSheet(int fromIndex,
                               int toIndex)
Moves the specified sheet within this workbook to another index position.

Specified by:
moveSheet in class WritableWorkbook
Parameters:
fromIndex - the zero based index of the reQuired sheet
toIndex - the zero based index of the reQuired sheet
Returns:
the sheet that has been moved

write

public void write()
           throws java.io.IOException
Writes out this sheet to the output file. First it writes out the standard workbook information required by excel, before calling the write method on each sheet individually

Specified by:
write in class WritableWorkbook
Throws:
java.io.IOException

copySheet

public void copySheet(int s,
                      java.lang.String name,
                      int index)
Copies the specified sheet and places it at the index specified by the parameter

Specified by:
copySheet in class WritableWorkbook
Parameters:
s - the index of the sheet to copy
name - the name of the new sheet
index - the position of the new sheet

copySheet

public void copySheet(java.lang.String s,
                      java.lang.String name,
                      int index)
Copies the specified sheet and places it at the index specified by the parameter

Specified by:
copySheet in class WritableWorkbook
Parameters:
s - the name of the sheet to copy
name - the name of the new sheet
index - the position of the new sheet

setProtected

public void setProtected(boolean prot)
Indicates whether or not this workbook is protected

Specified by:
setProtected in class WritableWorkbook
Parameters:
prot - protected flag

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 last external sheet specified by the index

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

getWorkbookBof

public BOFRecord getWorkbookBof()
Parsing of formulas is only supported for a subset of the available biff version, so we need to test to see if this version is acceptable

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

getExternalSheetIndex

public int getExternalSheetIndex(int index)
Gets the index of the external sheet for the name

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

getLastExternalSheetIndex

public int getLastExternalSheetIndex(int index)
Gets the index of the external sheet for the name

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

getExternalSheetIndex

public int getExternalSheetIndex(java.lang.String sheetName)
Gets the external sheet index for the sheet name

Specified by:
getExternalSheetIndex in interface ExternalSheet
Parameters:
sheetName -
Returns:
the sheet index or -1 if the sheet could not be found

getLastExternalSheetIndex

public int getLastExternalSheetIndex(java.lang.String sheetName)
Gets the last external sheet index for the sheet name

Specified by:
getLastExternalSheetIndex in interface ExternalSheet
Parameters:
sheetName -
Returns:
the sheet index or -1 if the sheet could not be found

setColourRGB

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

Specified by:
setColourRGB in class WritableWorkbook
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

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 -
Returns:
the index in the name table

findCellByName

public WritableCell 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 WritableWorkbook
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 WritableWorkbook
Returns:
the range of cells

getRangeNames

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

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

addNameArea

public void addNameArea(java.lang.String name,
                        WritableSheet sheet,
                        int firstCol,
                        int firstRow,
                        int lastCol,
                        int lastRow)
Add new named area to this workbook with the given information.

Specified by:
addNameArea in class WritableWorkbook
Parameters:
name - name to be created.
sheet - sheet containing the name
firstCol - first column this name refers to.
firstRow - first row this name refers to.
lastCol - last column this name refers to.
lastRow - last row this name refers to.

getWritableCell

public WritableCell getWritableCell(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:
getWritableCell in class WritableWorkbook
Parameters:
loc - the cell to retrieve
Returns:
the cell at the specified location