Save This Page
Home » poi-src-3.2-FINAL-20081019 » org.apache » poi » hssf » usermodel » [javadoc | source]
org.apache.poi.hssf.usermodel
public class: HSSFWorkbook [javadoc | source]
java.lang.Object
   org.apache.poi.POIDocument
      org.apache.poi.hssf.usermodel.HSSFWorkbook

Direct Known Subclasses:
    StubHSSFWorkbook

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.
Field Summary
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! 
protected  List _sheets    this holds the HSSFSheet objects attached to this workbook 
public static final  int PICTURE_TYPE_EMF    Extended windows meta file 
public static final  int PICTURE_TYPE_WMF    Windows Meta File 
public static final  int PICTURE_TYPE_PICT    Mac PICT format 
public static final  int PICTURE_TYPE_JPEG    JPEG format 
public static final  int PICTURE_TYPE_PNG    PNG format 
public static final  int PICTURE_TYPE_DIB    Device independant bitmap 
public static final  byte ENCODING_COMPRESSED_UNICODE   
     
    public static final  byte ENCODING_UTF_16   
       
      Fields inherited from org.apache.poi.POIDocument:
      sInf,  dsInf,  filesystem,  directory,  logger,  initialized
      Constructor:
       public HSSFWorkbook() 
       protected HSSFWorkbook(Workbook book) 
       public HSSFWorkbook(POIFSFileSystem fs) throws IOException 
       public HSSFWorkbook(InputStream s) throws IOException 
       public HSSFWorkbook(POIFSFileSystem fs,
          boolean preserveNodes) throws 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.
        preserveNodes - whether to preseve other nodes, such as macros. This takes more memory, so only say yes if you need to. If set, will store all of the POIFSFileSystem in memory
        Throws:
        IOException - if the stream cannot be read
        Also see:
        org.apache.poi.poifs.filesystem.POIFSFileSystem
        exception: IOException - if the stream cannot be read
       public HSSFWorkbook(InputStream s,
          boolean preserveNodes) throws IOException 
        Companion to HSSFWorkbook(POIFSFileSystem), this constructs the POI filesystem around your inputstream.
       public HSSFWorkbook(DirectoryNode directory,
          POIFSFileSystem fs,
          boolean preserveNodes) throws IOException 
        given a POI POIFSFileSystem object, and a specific directory within it, read in its Workbook and populate the high and low level models. If you're reading in a workbook...start here.
        Parameters:
        directory - the POI filesystem directory to process from
        fs - the POI filesystem that contains the Workbook stream.
        preserveNodes - whether to preseve other nodes, such as macros. This takes more memory, so only say yes if you need to. If set, will store all of the POIFSFileSystem in memory
        Throws:
        IOException - if the stream cannot be read
        Also see:
        org.apache.poi.poifs.filesystem.POIFSFileSystem
        exception: IOException - if the stream cannot be read
      Method from org.apache.poi.hssf.usermodel.HSSFWorkbook Summary:
      addPicture,   addSSTString,   cloneSheet,   createCellStyle,   createDataFormat,   createFont,   createName,   createSheet,   createSheet,   dumpDrawingGroupRecords,   findFont,   getActiveSheetIndex,   getAllEmbeddedObjects,   getAllPictures,   getBackupFlag,   getBytes,   getCellStyleAt,   getCustomPalette,   getDisplayedTab,   getExternalSheetIndex,   getFirstVisibleTab,   getFontAt,   getMissingCellPolicy,   getNameAt,   getNameIndex,   getNameName,   getNumCellStyles,   getNumberOfFonts,   getNumberOfNames,   getNumberOfSheets,   getPrintArea,   getSSTString,   getSelectedTab,   getSheet,   getSheetAt,   getSheetIndex,   getSheetIndex,   getSheetName,   getSheetReferences,   getWorkbook,   insertChartRecord,   isSheetHidden,   isWriteProtected,   removeName,   removeName,   removePrintArea,   removeSheetAt,   resolveNameXText,   setActiveSheet,   setBackupFlag,   setDisplayedTab,   setFirstVisibleTab,   setMissingCellPolicy,   setPrintArea,   setPrintArea,   setRepeatingRowsAndColumns,   setSelectedTab,   setSelectedTab,   setSelectedTabs,   setSheetHidden,   setSheetName,   setSheetName,   setSheetOrder,   unwriteProtectWorkbook,   write,   writeProtectWorkbook
      Methods from org.apache.poi.POIDocument:
      copyNodes,   getDocumentSummaryInformation,   getPropertySet,   getSummaryInformation,   readProperties,   write,   writeProperties,   writeProperties,   writePropertySet
      Methods from java.lang.Object:
      equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
      Method from org.apache.poi.hssf.usermodel.HSSFWorkbook Detail:
       public int addPicture(byte[] pictureData,
          int format) 
        Adds a picture to the workbook.
       public int addSSTString(String string) 
      Deprecated! Do - not call this method from your applications. Use the methods available in the HSSFRow to add string HSSFCells

       public HSSFSheet cloneSheet(int sheetNum) 
        create an HSSFSheet from an existing sheet in the HSSFWorkbook.
       public HSSFCellStyle createCellStyle() 
        create a new Cell style and add it to the workbook's style table
       public HSSFDataFormat createDataFormat() 
        Returns the instance of HSSFDataFormat for this workbook.
       public HSSFFont createFont() 
        create a new Font and add it to the workbook's font table
       public HSSFName createName() 
        creates a new named range and add it to the model
       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.
       public HSSFSheet createSheet(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.
       public  void dumpDrawingGroupRecords(boolean fat) 
        Spits out a list of all the drawing records in the workbook.
       public HSSFFont findFont(short boldWeight,
          short color,
          short fontHeight,
          String name,
          boolean italic,
          boolean strikeout,
          short typeOffset,
          byte underline) 
        Finds a font that matches the one with the supplied attributes
       public int getActiveSheetIndex() 
        gets the tab whose data is actually seen when the sheet is opened. This may be different from the "selected sheet" since excel seems to allow you to show the data of one sheet when another is seen "selected" in the tabs (at the bottom).
       public List getAllEmbeddedObjects() 
        Gets all embedded OLE2 objects from the Workbook.
       public List getAllPictures() 
        Gets all pictures from the Workbook.
       public boolean getBackupFlag() 
        determine whether the Excel GUI will backup the workbook when saving.
       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.
       public HSSFCellStyle getCellStyleAt(short idx) 
        get the cell style object at the given index
       public HSSFPalette getCustomPalette() 
       public short getDisplayedTab() 
      Deprecated! - - Misleading name - use getFirstVisibleTab()

        deprecated May 2008
       public short getExternalSheetIndex(int internalSheetIndex) 
        Returns the external sheet index of the sheet with the given internal index, creating one if needed. Used by some of the more obscure formula and named range things.
       public int getFirstVisibleTab() 
        sets the first tab that is displayed in the list of tabs in excel.
       public HSSFFont getFontAt(short idx) 
        get the font at the given index number
       public MissingCellPolicy getMissingCellPolicy() 
        Retrieves the current policy on what to do when getting missing or blank cells from a row. The default is to return blank and null cells. MissingCellPolicy
       public HSSFName getNameAt(int index) 
        gets the Named range
       public int getNameIndex(String name) 
        gets the named range index by his name Note:Excel named ranges are case-insensitive and this method performs a case-insensitive search.
       public String getNameName(int index) 
        gets the named range name
       public short getNumCellStyles() 
        get the number of styles the workbook contains
       public short getNumberOfFonts() 
        get the number of fonts in the font table
       public int getNumberOfNames() 
        gets the total number of named ranges in the workboko
       public int getNumberOfSheets() 
        get the number of spreadsheets in the workbook (this will be three after serialization)
       public String getPrintArea(int sheetIndex) 
        Retrieves the reference for the printarea of the specified sheet, the sheet name is appended to the reference even if it was not specified.
       public String getSSTString(int index) 
      Deprecated! Do - not call this method from your applications. Use the methods available in the HSSFRow to get string HSSFCells

       public short getSelectedTab() 
      Deprecated! - - Misleading name - use getActiveSheetIndex()

        deprecated May 2008
       public HSSFSheet getSheet(String name) 
        Get sheet with the given name (case insensitive match)
       public HSSFSheet getSheetAt(int index) 
        Get the HSSFSheet object at the given index.
       public int getSheetIndex(String name) 
        Returns the index of the sheet by his name
       public int getSheetIndex(HSSFSheet sheet) 
        Returns the index of the given sheet
       public String getSheetName(int sheetIx) 
        get the sheet name
       public SheetReferences getSheetReferences() 
       protected Workbook getWorkbook() 
       public  void insertChartRecord() 
        Test only. Do not use
       public boolean isSheetHidden(int sheetIx) 
        check whether a sheet is hidden
       public boolean isWriteProtected() 
        Is the workbook protected with a password (not encrypted)?
       public  void removeName(int index) 
        remove the named range by his index
       public  void removeName(String name) 
        remove the named range by his name
       public  void removePrintArea(int sheetIndex) 
        Delete the printarea for the sheet specified
       public  void removeSheetAt(int index) 
        Removes sheet at the given index.

        Care must be taken if the removed sheet is the currently active or only selected sheet in the workbook. There are a few situations when Excel must have a selection and/or active sheet. (For example when printing - see Bug 40414).
        This method makes sure that if the removed sheet was active, another sheet will become active in its place. Furthermore, if the removed sheet was the only selected sheet, another sheet will become selected. The newly active/selected sheet will have the same index, or one less if the removed sheet was the last in the workbook.

       public String resolveNameXText(int refIndex,
          int definedNameIndex) 
        TODO - make this less cryptic / move elsewhere
       public  void setActiveSheet(int index) 
        Convenience method to set the active sheet. The active sheet is is the sheet which is currently displayed when the workbook is viewed in Excel. 'Selected' sheet(s) is a distinct concept.
       public  void setBackupFlag(boolean backupValue) 
        determine whether the Excel GUI will backup the workbook when saving.
       public  void setDisplayedTab(short index) 
      Deprecated! - - Misleading name - use setFirstVisibleTab()

        deprecated May 2008
       public  void setFirstVisibleTab(int index) 
        sets the first tab that is displayed in the list of tabs in excel.
       public  void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) 
       public  void setPrintArea(int sheetIndex,
          String reference) 
        Sets the printarea for the sheet provided

        i.e. Reference = $A$1:$B$2

       public  void setPrintArea(int sheetIndex,
          int startColumn,
          int endColumn,
          int startRow,
          int endRow) 
        For the Convenience of Java Programmers maintaining pointers.
       public  void setRepeatingRowsAndColumns(int sheetIndex,
          int startColumn,
          int endColumn,
          int startRow,
          int endRow) 
        Sets the repeating rows and columns for a sheet (as found in File->PageSetup->Sheet). This is function is included in the workbook because it creates/modifies name records which are stored at the workbook level.

        To set just repeating columns:

        workbook.setRepeatingRowsAndColumns(0,0,1,-1-1);
        
        To set just repeating rows:
        workbook.setRepeatingRowsAndColumns(0,-1,-1,0,4);
        
        To remove all repeating rows and columns for a sheet.
        workbook.setRepeatingRowsAndColumns(0,-1,-1,-1,-1);
        
       public  void setSelectedTab(int index) 
        Selects a single sheet. This may be different to the 'active' sheet (which is the sheet with focus).
       public  void setSelectedTab(short index) 
      Deprecated! use - setSelectedTab(int)

        deprecated May 2008
       public  void setSelectedTabs(int[] indexes) 
       public  void setSheetHidden(int sheetIx,
          boolean hidden) 
        Hide or unhide a sheet
       public  void setSheetName(int sheetIx,
          String name) 
        set the sheet name. Will throw IllegalArgumentException if the name is greater than 31 chars or contains /\?*[]
       public  void setSheetName(int sheetIx,
          String name,
          short encoding) 
      Deprecated! 3-Jan-2006 - POI now automatically detects unicode and sets the encoding appropriately. Simply use setSheetName(int sheet, String encoding)

        set the sheet name forcing the encoding. Forcing the encoding IS A BAD IDEA!!!
       public  void setSheetOrder(String sheetname,
          int pos) 
        sets the order of appearance for a given sheet.
       public  void unwriteProtectWorkbook() 
        removes the write protect flag
       public  void write(OutputStream stream) throws 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.
       public  void writeProtectWorkbook(String password,
          String username) 
        protect a workbook with a password (not encypted, just sets writeprotect flags and the password.