Package jxl.write
Class WritableWorkbook
java.lang.Object
jxl.write.WritableWorkbook
A writable workbook
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final WritableFont
The default font for Cell formatsstatic final WritableCellFormat
A cell format used to hide the cell contentsstatic final WritableFont
The font used for hyperlinksstatic final WritableCellFormat
The style used for hyperlinksstatic final WritableCellFormat
The default style for cells -
Method Summary
Modifier and TypeMethodDescriptionabstract void
addNameArea
(String name, WritableSheet sheet, int firstCol, int firstRow, int lastCol, int lastRow) Add new named area to this workbook with the given information.abstract void
close()
Closes this workbook, and makes any memory allocated available for garbage collection.void
Deprecated.Copying now occurs implicitly as part of the overloaded factory method Workbook.createWorkboodabstract void
Copy sheet within the same workbook.abstract void
Copies the specified sheet and places it at the index specified by the parameterabstract WritableSheet
createSheet
(String name, int index) Creates, and returns a worksheet at the specified position with the specified name If the index specified is less than or equal to zero, the new sheet is created at the beginning of the workbook.abstract Range[]
findByName
(String name) Gets the named range from this workbook.abstract WritableCell
findCellByName
(String name) Gets the named cell from this workbook.abstract int
Returns the number of sheets in this workbookabstract String[]
Gets the named rangesabstract WritableSheet
getSheet
(int index) Gets the specified sheet within this workbookabstract WritableSheet
Gets the sheet with the specified name from within this workbookabstract String[]
Gets the sheet namesabstract WritableSheet[]
Gets the sheets within this workbook.abstract WritableCell
getWritableCell
(String loc) Returns the cell for the specified location eg.abstract WritableSheet
importSheet
(String name, int index, Sheet s) Imports a sheet from a different workbook.abstract WritableSheet
moveSheet
(int fromIndex, int toIndex) Moves the specified sheet within this workbook to another index position.abstract void
removeRangeName
(String name) Removes the specified named range from the workbook.abstract void
removeSheet
(int index) Removes the sheet at the specified index from this workbookabstract void
setColourRGB
(Colour c, int r, int g, int b) Sets the RGB value for the specified colour for this workbookabstract void
setOutputFile
(File fileName) Sets a new output file.abstract void
setProtected
(boolean prot) Indicates whether or not this workbook is protectedabstract void
write()
Writes out the data held in this workbook in Excel format
-
Field Details
-
ARIAL_10_PT
The default font for Cell formats -
HYPERLINK_FONT
The font used for hyperlinks -
NORMAL_STYLE
The default style for cells -
HYPERLINK_STYLE
The style used for hyperlinks -
HIDDEN_STYLE
A cell format used to hide the cell contents
-
-
Method Details
-
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
-
getSheetNames
Gets the sheet names- Returns:
- an array of strings containing the sheet names
-
getSheet
Gets the specified sheet within this workbook- Parameters:
index
- the zero based index of the reQuired sheet- Returns:
- The sheet specified by the index
- Throws:
IndexOutOfBoundsException
- when index refers to a non-existent sheet
-
getSheet
Gets the sheet with the specified name from within this workbook- Parameters:
name
- the sheet name- Returns:
- The sheet with the specified name, or null if it is not found
-
getWritableCell
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
-
close
Closes this workbook, and makes any memory allocated available for garbage collection. Also closes the underlying output stream if necessary.- Throws:
IOException
WriteException
-
createSheet
Creates, and returns a worksheet at the specified position with the specified name If the index specified is less than or equal to zero, the new sheet is created at the beginning of the workbook. If the index is greater than the number of sheet, then the sheet is created at the end of the workbook.- Parameters:
name
- the sheet nameindex
- the index number at which to insert- Returns:
- the new sheet
-
importSheet
Imports a sheet from a different workbook. Does a deep copy on all elements within that sheet- Parameters:
name
- the name of the new sheetindex
- the position for the new sheet within this workbooksheet
- the sheet (from another workbook) to merge into this one- Returns:
- the new sheet
-
copySheet
Copy sheet within the same workbook. The sheet specified is copied to the new sheet name at the position- Parameters:
s
- the index of the sheet to copyname
- the name of the new sheetindex
- the position of the new sheet
-
copySheet
Copies the specified sheet and places it at the index specified by the parameter- Parameters:
s
- the name of the sheet to copyname
- the name of the new sheetindex
- the position of the new sheet
-
removeSheet
public abstract void removeSheet(int index) Removes the sheet at the specified index from this workbook- Parameters:
index
- the sheet index to remove
-
moveSheet
Moves the specified sheet within this workbook to another index position.- Parameters:
fromIndex
- the zero based index of the required sheettoIndex
- the zero based index of the required sheet- Returns:
- the sheet that has been moved
-
write
Writes out the data held in this workbook in Excel format- Throws:
IOException
-
setProtected
public abstract void setProtected(boolean prot) Indicates whether or not this workbook is protected- Parameters:
prot
- Protected flag
-
setColourRGB
Sets the RGB value for the specified colour for this workbook- Parameters:
c
- the colour whose RGB value is to be overwrittenr
- the red portion to set (0-255)g
- the green portion to set (0-255)b
- the blue portion to set (0-255)
-
copy
Deprecated.Copying now occurs implicitly as part of the overloaded factory method Workbook.createWorkboodThis method can be used to create a writable clone of some other workbook- Parameters:
w
- the workdoock to copy
-
findCellByName
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- 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
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
-
getRangeNames
Gets the named ranges- Returns:
- the list of named cells within the workbook
-
removeRangeName
Removes the specified named range from the workbook. Note that removing a name could cause formulas which use that name to calculate their results incorrectly- Parameters:
name
- the name to remove
-
addNameArea
public abstract void addNameArea(String name, WritableSheet sheet, int firstCol, int firstRow, int lastCol, int lastRow) Add new named area to this workbook with the given information.- Parameters:
name
- name to be created.sheet
- sheet containing the namefirstCol
- 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.
-
setOutputFile
Sets a new output file. This allows the same workbook to be written to various different output files without having to read in any templates again- Parameters:
fileName
- the file name- Throws:
IOException
-