org.apache.poi.hssf.usermodel
Class HSSFWorkbook

java.lang.Object
  |
  +--org.apache.poi.hssf.usermodel.HSSFWorkbook

public class HSSFWorkbook
extends java.lang.Object

High level representation of a workbook. This is the first object most users will construct whether they are reading or writing a workbook. It is also the top level object for creating new sheets/etc.

Version:
2.0-pre
Author:
Andrew C. Oliver (acoliver at apache dot org), Glen Stampoultzis (glens at apache.org)
See Also:
Workbook, HSSFSheet

Field Summary
static int INITIAL_CAPACITY
          used for compile-time performance/memory optimization.
 
Constructor Summary
HSSFWorkbook()
          Creates new HSSFWorkbook from scratch (start here!)
HSSFWorkbook(java.io.InputStream s)
          Companion to HSSFWorkbook(POIFSFileSystem), this constructs the POI filesystem around your inputstream.
HSSFWorkbook(POIFSFileSystem fs)
          given a POI POIFSFileSystem object, read in its Workbook and populate the high and low level models.
 
Method Summary
 int addSSTString(java.lang.String string)
           
 HSSFCellStyle createCellStyle()
          create a new Cell style and add it to the workbook's style table
 HSSFFont createFont()
          create a new Font and add it to the workbook's font table
 HSSFSheet createSheet()
          create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns the high level representation.
 HSSFSheet createSheet(java.lang.String sheetname)
          create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns the high level representation.
 boolean getBackupFlag()
          determine whether the Excel GUI will backup the workbook when saving.
 byte[] getBytes()
          Method getBytes - get the bytes of just the HSSF portions of the XLS file.
 HSSFCellStyle getCellStyleAt(short idx)
          get the cell style object at the given index
 HSSFFont getFontAt(short idx)
          get the font at the given index number
 short getNumberOfFonts()
          get the number of fonts in the font table
 int getNumberOfSheets()
          get the number of spreadsheets in the workbook (this will be three after serialization)
 short getNumCellStyles()
          get the number of styles the workbook contains
 HSSFSheet getSheet(java.lang.String name)
          Get sheet with the given name
 HSSFSheet getSheetAt(int index)
          Get the HSSFSheet object at the given index.
 int getSheetIndex(java.lang.String name)
          get the sheet's index
 java.lang.String getSheetName(int sheet)
          get the sheet name
 java.lang.String getSSTString(int index)
           
 void removeSheetAt(int index)
          removes sheet at the given index
 void setBackupFlag(boolean backupValue)
          determine whether the Excel GUI will backup the workbook when saving.
 void setSheetName(int sheet, java.lang.String name)
          set the sheet name.
 void write(java.io.OutputStream stream)
          Method write - write out this workbook to an Outputstream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INITIAL_CAPACITY

public static final int INITIAL_CAPACITY
used for compile-time performance/memory optimization. This determines the initial capacity for the sheet collection. Its currently set to 3. Changing it in this release will decrease performance since you're never allowed to have more or less than three sheets!
Constructor Detail

HSSFWorkbook

public HSSFWorkbook()
Creates new HSSFWorkbook from scratch (start here!)

HSSFWorkbook

public HSSFWorkbook(POIFSFileSystem fs)
             throws java.io.IOException
given a POI POIFSFileSystem object, read in its Workbook and populate the high and low level models. If you're reading in a workbook...start here.
Parameters:
fs - the POI filesystem that contains the Workbook stream.
Throws:
java.io.IOException - if the stream cannot be read
See Also:
POIFSFileSystem

HSSFWorkbook

public HSSFWorkbook(java.io.InputStream s)
             throws java.io.IOException
Companion to HSSFWorkbook(POIFSFileSystem), this constructs the POI filesystem around your inputstream.
Parameters:
s - the POI filesystem that contains the Workbook stream.
Throws:
java.io.IOException - if the stream cannot be read
See Also:
POIFSFileSystem, HSSFWorkbook(POIFSFileSystem)
Method Detail

setSheetName

public void setSheetName(int sheet,
                         java.lang.String name)
set the sheet name.
Parameters:
sheet - number (0 based)
sheet - name

getSheetName

public java.lang.String getSheetName(int sheet)
get the sheet name
Parameters:
sheet - Number
Returns:
Sheet name

getSheetIndex

public int getSheetIndex(java.lang.String name)
get the sheet's index
Parameters:
name - sheet name
Returns:
sheet index or -1 if it was not found.

createSheet

public HSSFSheet createSheet()
create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns the high level representation. Use this to create new sheets.
Returns:
HSSFSheet representing the new sheet.

createSheet

public HSSFSheet createSheet(java.lang.String sheetname)
create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns the high level representation. Use this to create new sheets.
Parameters:
sheetname - sheetname to set for the sheet.
Returns:
HSSFSheet representing the new sheet.

getNumberOfSheets

public int getNumberOfSheets()
get the number of spreadsheets in the workbook (this will be three after serialization)
Returns:
number of sheets

getSheetAt

public HSSFSheet getSheetAt(int index)
Get the HSSFSheet object at the given index.
Parameters:
index - of the sheet number (0-based physical & logical)
Returns:
HSSFSheet at the provided index

getSheet

public HSSFSheet getSheet(java.lang.String name)
Get sheet with the given name
Parameters:
name - of the sheet
Returns:
HSSFSheet with the name provided or null if it does not exist

removeSheetAt

public void removeSheetAt(int index)
removes sheet at the given index
Parameters:
index - of the sheet (0-based)

setBackupFlag

public void setBackupFlag(boolean backupValue)
determine whether the Excel GUI will backup the workbook when saving.
Parameters:
backupValue - true to indicate a backup will be performed.

getBackupFlag

public boolean getBackupFlag()
determine whether the Excel GUI will backup the workbook when saving.
Returns:
the current setting for backups.

createFont

public HSSFFont createFont()
create a new Font and add it to the workbook's font table
Returns:
new font object

getNumberOfFonts

public short getNumberOfFonts()
get the number of fonts in the font table
Returns:
number of fonts

getFontAt

public HSSFFont getFontAt(short idx)
get the font at the given index number
Parameters:
idx - index number
Returns:
HSSFFont at the index

createCellStyle

public HSSFCellStyle createCellStyle()
create a new Cell style and add it to the workbook's style table
Returns:
the new Cell Style object

getNumCellStyles

public short getNumCellStyles()
get the number of styles the workbook contains
Returns:
count of cell styles

getCellStyleAt

public HSSFCellStyle getCellStyleAt(short idx)
get the cell style object at the given index
Parameters:
idx - index within the set of styles
Returns:
HSSFCellStyle object at the index

write

public void write(java.io.OutputStream stream)
           throws java.io.IOException
Method write - write out this workbook to an Outputstream. Constructs a new POI POIFSFileSystem, passes in the workbook binary representation and writes it out.
Parameters:
stream - - the java OutputStream you wish to write the XLS to
Throws:
java.io.IOException - if anything can't be written.
See Also:
POIFSFileSystem

getBytes

public byte[] getBytes()
Method getBytes - get the bytes of just the HSSF portions of the XLS file. Use this to construct a POI POIFSFileSystem yourself.
Returns:
byte[] array containing the binary representation of this workbook and all contained sheets, rows, cells, etc.
See Also:
Workbook, Sheet

addSSTString

public int addSSTString(java.lang.String string)

getSSTString

public java.lang.String getSSTString(int index)


Copyright © 2002 Apache jakarta-poi project. All Rights Reserved.