Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.poi.ss.usermodel
Interface Workbook

All Known Implementing Classes:
  HSSFWorkbook

    public interface Workbook

High level representation of a Excel 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
`static int` | `PICTURE_TYPE_DIB` Device independent bitmap
`static int` | `PICTURE_TYPE_EMF` Extended windows meta file
`static int` | `PICTURE_TYPE_JPEG` JPEG format
`static int` | `PICTURE_TYPE_PICT` Mac PICT format
`static int` | `PICTURE_TYPE_PNG` PNG format
`static int` | `PICTURE_TYPE_WMF` Windows Meta File
`static int` | `SHEET_STATE_HIDDEN` Indicates the book window is hidden, but can be shown by the user via the user interface.
`static int` | `SHEET_STATE_VERY_HIDDEN` Indicates the sheet is hidden and cannot be shown in the user interface (UI).
`static int` | `SHEET_STATE_VISIBLE` Indicates the sheet is visible.

Method Summary
`int` | `addPicture(byte[] pictureData, int format)` Adds a picture to the workbook.
`void` | `addToolPack(UDFFinder toopack)` Register a new toolpack in this workbook.
`Sheet` | `cloneSheet(int sheetNum)` Create an Sheet from an existing sheet in the Workbook.
`CellStyle` | `createCellStyle()` Create a new Cell style and add it to the workbook's style table
`DataFormat` | `createDataFormat()` Returns the instance of DataFormat for this workbook.
`Font` | `createFont()` Create a new Font and add it to the workbook's font table
`Name` | `createName()` Creates a new (uninitialised) defined name in this workbook
`Sheet` | `createSheet()` Sreate an Sheet for this Workbook, adds it to the sheets and returns the high level representation.
`Sheet` | `createSheet(java.lang.String sheetname)` Create a new sheet for this Workbook and return the high level representation.
`Font` | `findFont(short boldWeight, short color, short fontHeight, java.lang.String name, boolean italic, boolean strikeout, short typeOffset, byte underline)` Finds a font that matches the one with the supplied attributes
`int` | `getActiveSheetIndex()` Convenience method to get the active sheet.
`java.util.List` | `getAllPictures()` Gets all pictures from the Workbook.
`CellStyle` | `getCellStyleAt(short idx)` Get the cell style object at the given index
`CreationHelper` | `getCreationHelper()` Returns an object that handles instantiating concrete classes of the various instances one needs for HSSF and XSSF.
`int` | `getFirstVisibleTab()` Gets the first tab that is displayed in the list of tabs in excel.
`Font` | `getFontAt(short idx)` Get the font at the given index number
`boolean` | `getForceFormulaRecalculation()` Whether Excel will be asked to recalculate all formulas when the workbook is opened.
`Row.MissingCellPolicy` | `getMissingCellPolicy()` Retrieves the current policy on what to do when getting missing or blank cells from a row.
`Name` | `getName(java.lang.String name)`
`Name` | `getNameAt(int nameIndex)`
`int` | `getNameIndex(java.lang.String name)` Gets the defined name index by name Note: Excel defined names are case-insensitive and this method performs a case-insensitive search.
`short` | `getNumberOfFonts()` Get the number of fonts in the font table
`int` | `getNumberOfNames()`
`int` | `getNumberOfSheets()` Get the number of spreadsheets in the workbook
`short` | `getNumCellStyles()` Get the number of styles the workbook contains
`java.lang.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.
`Sheet` | `getSheet(java.lang.String name)` Get sheet with the given name
`Sheet` | `getSheetAt(int index)` Get the Sheet object at the given index.
`int` | `getSheetIndex(Sheet sheet)` Returns the index of the given sheet
`int` | `getSheetIndex(java.lang.String name)` Returns the index of the sheet by his name
`java.lang.String` | `getSheetName(int sheet)` Get the sheet name
`boolean` | `isHidden()`
`boolean` | `isSheetHidden(int sheetIx)` Check whether a sheet is hidden.
`boolean` | `isSheetVeryHidden(int sheetIx)` Check whether a sheet is very hidden.
`void` | `removeName(int index)` Remove the defined name at the specified index
`void` | `removeName(java.lang.String name)` Remove a defined name by name
`void` | `removePrintArea(int sheetIndex)` Delete the printarea for the sheet specified
`void` | `removeSheetAt(int index)` Removes sheet at the given index
`void` | `setActiveSheet(int sheetIndex)` Convenience method to set the active sheet.
`void` | `setFirstVisibleTab(int sheetIndex)` Sets the first tab that is displayed in the list of tabs in excel.
`void` | `setForceFormulaRecalculation(boolean value)` Whether the application shall perform a full recalculation when the workbook is opened.
`void` | `setHidden(boolean hiddenFlag)`
`void` | `setMissingCellPolicy(Row.MissingCellPolicy missingCellPolicy)` Sets the policy on what to do when getting missing or blank cells from a row.
`void` | `setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)` For the Convenience of Java Programmers maintaining pointers.
`void` | `setPrintArea(int sheetIndex, java.lang.String reference)` Sets the printarea for the sheet provided
`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).
`void` | `setSelectedTab(int index)` Sets the tab whose data is actually seen when the sheet is opened.
`void` | `setSheetHidden(int sheetIx, boolean hidden)` Hide or unhide a sheet
`void` | `setSheetHidden(int sheetIx, int hidden)` Hide or unhide a sheet.
`void` | `setSheetName(int sheet, java.lang.String name)` Set the sheet name.
`void` | `setSheetOrder(java.lang.String sheetname, int pos)` Sets the order of appearance for a given sheet.
`void` | `write(java.io.OutputStream stream)` Write out this workbook to an Outputstream.

Field Detail

### PICTURE_TYPE_EMF

    static final int PICTURE_TYPE_EMF

  Extended windows meta file

  See Also:
    Constant Field Values

### PICTURE_TYPE_WMF

    static final int PICTURE_TYPE_WMF

  Windows Meta File

  See Also:
    Constant Field Values

### PICTURE_TYPE_PICT

    static final int PICTURE_TYPE_PICT

  Mac PICT format

  See Also:
    Constant Field Values

### PICTURE_TYPE_JPEG

    static final int PICTURE_TYPE_JPEG

  JPEG format

  See Also:
    Constant Field Values

### PICTURE_TYPE_PNG

    static final int PICTURE_TYPE_PNG

  PNG format

  See Also:
    Constant Field Values

### PICTURE_TYPE_DIB

    static final int PICTURE_TYPE_DIB

  Device independent bitmap

  See Also:
    Constant Field Values

### SHEET_STATE_VISIBLE

    static final int SHEET_STATE_VISIBLE

  Indicates the sheet is visible.

  See Also:
    `setSheetHidden(int, int)`, Constant Field Values

### SHEET_STATE_HIDDEN

    static final int SHEET_STATE_HIDDEN

  Indicates the book window is hidden, but can be shown by the user via the user interface.

  See Also:
    `setSheetHidden(int, int)`, Constant Field Values

### SHEET_STATE_VERY_HIDDEN

    static final int SHEET_STATE_VERY_HIDDEN

  Indicates the sheet is hidden and cannot be shown in the user interface (UI).

  In Excel this state is only available programmatically in VBA: `ThisWorkbook.Sheets("MySheetName").Visible = xlSheetVeryHidden`

  See Also:
    `setSheetHidden(int, int)`, Constant Field Values

Method Detail

### getActiveSheetIndex

    int getActiveSheetIndex()

  Convenience method to get 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.

  Returns:
    the index of the active sheet (0-based)

### setActiveSheet

    void setActiveSheet(int sheetIndex)

  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.

  Parameters:
    `sheetIndex` - index of the active sheet (0-based)

### getFirstVisibleTab

    int getFirstVisibleTab()

  Gets the first tab that is displayed in the list of tabs in excel.

  Returns:
    the first tab that to display in the list of tabs (0-based).

### setFirstVisibleTab

    void setFirstVisibleTab(int sheetIndex)

  Sets the first tab that is displayed in the list of tabs in excel.

  Parameters:
    `sheetIndex` - the first tab that to display in the list of tabs (0-based)

### setSheetOrder

    void setSheetOrder(java.lang.String sheetname,
                       int pos)

  Sets the order of appearance for a given sheet.

  Parameters:
    `sheetname` - the name of the sheet to reorder
    `pos` - the position that we want to insert the sheet into (0 based)

### setSelectedTab

    void setSelectedTab(int index)

  Sets 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).

  Parameters:
    `index` - the index of the sheet to select (0 based)
  See Also:
    `Sheet.setSelected(boolean)`

### setSheetName

    void setSheetName(int sheet,
                      java.lang.String name)

  Set the sheet name.

  See `WorkbookUtil.createSafeSheetName(String nameProposal)` for a safe way to create valid names

  Parameters:
    `sheet` - number (0 based)
  Throws:
    `java.lang.IllegalArgumentException` - if the name is null or invalid or workbook already contains a sheet with this name
  See Also:
    `createSheet(String)`, `WorkbookUtil.createSafeSheetName(String nameProposal)`

### getSheetName

    java.lang.String getSheetName(int sheet)

  Get the sheet name

  Parameters:
    `sheet` - sheet number (0 based)
  Returns:
    Sheet name

### getSheetIndex

    int getSheetIndex(java.lang.String name)

  Returns the index of the sheet by his name

  Parameters:
    `name` - the sheet name
  Returns:
    index of the sheet (0 based)

### getSheetIndex

    int getSheetIndex(Sheet sheet)

  Returns the index of the given sheet

  Parameters:
    `sheet` - the sheet to look up
  Returns:
    index of the sheet (0 based)

### createSheet

    Sheet createSheet()

  Sreate an Sheet for this Workbook, adds it to the sheets and returns the high level representation. Use this to create new sheets.

  Returns:
    Sheet representing the new sheet.

### createSheet

    Sheet createSheet(java.lang.String sheetname)

  Create a new sheet for this Workbook and return the high level representation. Use this to create new sheets.

  Note that Excel allows sheet names up to 31 chars in length but other applications (such as OpenOffice) allow more. Some versions of Excel crash with names longer than 31 chars, others - truncate such names to 31 character.

  POI's SpreadsheetAPI silently truncates the input argument to 31 characters. Example:

           Sheet sheet = workbook.createSheet("My very long sheet name which is longer than 31 chars"); // will be truncated
           assert 31 == sheet.getSheetName().length();
           assert "My very long sheet name which i" == sheet.getSheetName();

  Except the 31-character constraint, Excel applies some other rules:

  Sheet name MUST be unique in the workbook and MUST NOT contain the any of the following characters:

  - 0x0000
  - 0x0003
  - colon (:)
  - backslash (\)
  - asterisk (*)
  - question mark (?)
  - forward slash (/)
  - opening square bracket ([)
  - closing square bracket (])
  The string MUST NOT begin or end with the single quote (') character.

  See `WorkbookUtil.createSafeSheetName(String nameProposal)` for a safe way to create valid names

  Parameters:
    `sheetname` - sheetname to set for the sheet.
  Returns:
    Sheet representing the new sheet.
  Throws:
    `java.lang.IllegalArgumentException` - if the name is null or invalid or workbook already contains a sheet with this name
  See Also:
    `WorkbookUtil.createSafeSheetName(String nameProposal)`

### cloneSheet

    Sheet cloneSheet(int sheetNum)

  Create an Sheet from an existing sheet in the Workbook.

  Returns:
    Sheet representing the cloned sheet.

### getNumberOfSheets

    int getNumberOfSheets()

  Get the number of spreadsheets in the workbook

  Returns:
    the number of sheets

### getSheetAt

    Sheet getSheetAt(int index)

  Get the Sheet object at the given index.

  Parameters:
    `index` - of the sheet number (0-based physical & logical)
  Returns:
    Sheet at the provided index

### getSheet

    Sheet getSheet(java.lang.String name)

  Get sheet with the given name

  Parameters:
    `name` - of the sheet
  Returns:
    Sheet with the name provided or `null` if it does not exist

### removeSheetAt

    void removeSheetAt(int index)

  Removes sheet at the given index

  Parameters:
    `index` - of the sheet to remove (0-based)

### setRepeatingRowsAndColumns

    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);

  Parameters:
    `sheetIndex` - 0 based index to sheet.
    `startColumn` - 0 based start of repeating columns.
    `endColumn` - 0 based end of repeating columns.
    `startRow` - 0 based start of repeating rows.
    `endRow` - 0 based end of repeating rows.

### createFont

    Font createFont()

  Create a new Font and add it to the workbook's font table

  Returns:
    new font object

### findFont

    Font findFont(short boldWeight,
                  short color,
                  short fontHeight,
                  java.lang.String name,
                  boolean italic,
                  boolean strikeout,
                  short typeOffset,
                  byte underline)

  Finds a font that matches the one with the supplied attributes

  Returns:
    the font with the matched attributes or `null`

### getNumberOfFonts

    short getNumberOfFonts()

  Get the number of fonts in the font table

  Returns:
    number of fonts

### getFontAt

    Font getFontAt(short idx)

  Get the font at the given index number

  Parameters:
    `idx` - index number (0-based)
  Returns:
    font at the index

### createCellStyle

    CellStyle createCellStyle()

  Create a new Cell style and add it to the workbook's style table

  Returns:
    the new Cell Style object

### getNumCellStyles

    short getNumCellStyles()

  Get the number of styles the workbook contains

  Returns:
    count of cell styles

### getCellStyleAt

    CellStyle getCellStyleAt(short idx)

  Get the cell style object at the given index

  Parameters:
    `idx` - index within the set of styles (0-based)
  Returns:
    CellStyle object at the index

### write

    void write(java.io.OutputStream stream)
               throws java.io.IOException

  Write out this workbook to an Outputstream.

  Parameters:
    `stream` - - the java OutputStream you wish to write to
  Throws:
    `java.io.IOException` - if anything can't be written.

### getNumberOfNames

    int getNumberOfNames()

  Returns:
    the total number of defined names in this workbook

### getName

    Name getName(java.lang.String name)

  Parameters:
    `name` - the name of the defined name
  Returns:
    the defined name with the specified name. `null` if not found.

### getNameAt

    Name getNameAt(int nameIndex)

  Parameters:
    `nameIndex` - position of the named range (0-based)
  Returns:
    the defined name at the specified index
  Throws:
    `java.lang.IllegalArgumentException` - if the supplied index is invalid

### createName

    Name createName()

  Creates a new (uninitialised) defined name in this workbook

  Returns:
    new defined name object

### getNameIndex

    int getNameIndex(java.lang.String name)

  Gets the defined name index by name
  Note: Excel defined names are case-insensitive and this method performs a case-insensitive search.

  Parameters:
    `name` - the name of the defined name
  Returns:
    zero based index of the defined name. `-1` if not found.

### removeName

    void removeName(int index)

  Remove the defined name at the specified index

  Parameters:
    `index` - named range index (0 based)

### removeName

    void removeName(java.lang.String name)

  Remove a defined name by name

  Parameters:
    `name` - the name of the defined name

### setPrintArea

    void setPrintArea(int sheetIndex,
                      java.lang.String reference)

  Sets the printarea for the sheet provided

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

  Parameters:
    `sheetIndex` - Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
    `reference` - Valid name Reference for the Print Area

### setPrintArea

    void setPrintArea(int sheetIndex,
                      int startColumn,
                      int endColumn,
                      int startRow,
                      int endRow)

  For the Convenience of Java Programmers maintaining pointers.

  Parameters:
    `sheetIndex` - Zero-based sheet index (0 = First Sheet)
    `startColumn` - Column to begin printarea
    `endColumn` - Column to end the printarea
    `startRow` - Row to begin the printarea
    `endRow` - Row to end the printarea
  See Also:
    `setPrintArea(int, String)`

### getPrintArea

    java.lang.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.

  Parameters:
    `sheetIndex` - Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
  Returns:
    String Null if no print area has been defined

### removePrintArea

    void removePrintArea(int sheetIndex)

  Delete the printarea for the sheet specified

  Parameters:
    `sheetIndex` - Zero-based sheet index (0 = First Sheet)

### getMissingCellPolicy

    Row.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. `Row.MissingCellPolicy`

### setMissingCellPolicy

    void setMissingCellPolicy(Row.MissingCellPolicy missingCellPolicy)

  Sets the policy on what to do when getting missing or blank cells from a row. This will then apply to all calls to `Row.getCell(int)` }. See `Row.MissingCellPolicy`

### createDataFormat

    DataFormat createDataFormat()

  Returns the instance of DataFormat for this workbook.

  Returns:
    the DataFormat object

### addPicture

    int addPicture(byte[] pictureData,
                   int format)

  Adds a picture to the workbook.

  Parameters:
    `pictureData` - The bytes of the picture
    `format` - The format of the picture.
  Returns:
    the index to this picture (1 based).
  See Also:
    `PICTURE_TYPE_EMF`, `PICTURE_TYPE_WMF`, `PICTURE_TYPE_PICT`, `PICTURE_TYPE_JPEG`, `PICTURE_TYPE_PNG`, `PICTURE_TYPE_DIB`

### getAllPictures

    java.util.List getAllPictures()

  Gets all pictures from the Workbook.

  Returns:
    the list of pictures (a list of `PictureData` objects.)

### getCreationHelper

    CreationHelper getCreationHelper()

  Returns an object that handles instantiating concrete classes of the various instances one needs for HSSF and XSSF.

### isHidden

    boolean isHidden()

  Returns:
    `false` if this workbook is not visible in the GUI

### setHidden

    void setHidden(boolean hiddenFlag)

  Parameters:
    `hiddenFlag` - pass `false` to make the workbook visible in the GUI

### isSheetHidden

    boolean isSheetHidden(int sheetIx)

  Check whether a sheet is hidden.

  Note that a sheet could instead be set to be very hidden, which is different (`isSheetVeryHidden(int)`)

  Parameters:
    `sheetIx` - Number
  Returns:
    `true` if sheet is hidden

### isSheetVeryHidden

    boolean isSheetVeryHidden(int sheetIx)

  Check whether a sheet is very hidden.

  This is different from the normal hidden status (`isSheetHidden(int)`)

  Parameters:
    `sheetIx` - sheet index to check
  Returns:
    `true` if sheet is very hidden

### setSheetHidden

    void setSheetHidden(int sheetIx,
                        boolean hidden)

  Hide or unhide a sheet

  Parameters:
    `sheetIx` - the sheet index (0-based)
    `hidden` - True to mark the sheet as hidden, false otherwise

### setSheetHidden

    void setSheetHidden(int sheetIx,
                        int hidden)

  Hide or unhide a sheet.
  - 0 - visible.
  - 1 - hidden.
  - 2 - very hidden.

  Parameters:
    `sheetIx` - the sheet index (0-based)
    `hidden` - one of the following `Workbook` constants: `Workbook.SHEET_STATE_VISIBLE`, `Workbook.SHEET_STATE_HIDDEN`, or `Workbook.SHEET_STATE_VERY_HIDDEN`.
  Throws:
    `java.lang.IllegalArgumentException` - if the supplied sheet index or state is invalid

### addToolPack

    void addToolPack(UDFFinder toopack)

  Register a new toolpack in this workbook.

  Parameters:
    `toopack` - the toolpack to register

### setForceFormulaRecalculation

    void setForceFormulaRecalculation(boolean value)

  Whether the application shall perform a full recalculation when the workbook is opened.

  Typically you want to force formula recalculation when you modify cell formulas or values of a workbook previously created by Excel. When set to true, this flag will tell Excel that it needs to recalculate all formulas in the workbook the next time the file is opened.

  Note, that recalculation updates cached formula results and, thus, modifies the workbook. Depending on the version, Excel may prompt you with "Do you want to save the changes in filename?" on close.

  Parameters:
    `value` - true if the application will perform a full recalculation of workbook values when the workbook is opened
  Since:
    3.8

### getForceFormulaRecalculation

    boolean getForceFormulaRecalculation()

  Whether Excel will be asked to recalculate all formulas when the workbook is opened.

  Since:
    3.8

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD