org.apache.poi.xssf.usermodel
Class XSSFWorkbook

java.lang.Object
  extended by org.apache.poi.POIXMLDocumentPart
      extended by org.apache.poi.POIXMLDocument
          extended by org.apache.poi.xssf.usermodel.XSSFWorkbook
All Implemented Interfaces:
java.io.Closeable, java.lang.Iterable<Sheet>, Workbook

public class XSSFWorkbook
extends POIXMLDocument
implements Workbook

High level representation of a SpreadsheetML 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.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.poi.POIXMLDocumentPart
POIXMLDocumentPart.RelationPart
 
Field Summary
static float DEFAULT_CHARACTER_WIDTH
          Deprecated. POI 3.17 beta 1
static int PICTURE_TYPE_BMP
           
static int PICTURE_TYPE_EPS
           
static int PICTURE_TYPE_GIF
          Images formats supported by XSSF but not by HSSF
static int PICTURE_TYPE_TIFF
           
static int PICTURE_TYPE_WPG
           
 
Fields inherited from class org.apache.poi.POIXMLDocument
DOCUMENT_CREATOR, OLE_OBJECT_REL_TYPE, PACK_OBJECT_REL_TYPE
 
Fields inherited from interface org.apache.poi.ss.usermodel.Workbook
PICTURE_TYPE_DIB, PICTURE_TYPE_EMF, PICTURE_TYPE_JPEG, PICTURE_TYPE_PICT, PICTURE_TYPE_PNG, PICTURE_TYPE_WMF, SHEET_STATE_HIDDEN, SHEET_STATE_VERY_HIDDEN, SHEET_STATE_VISIBLE
 
Constructor Summary
XSSFWorkbook()
          Create a new SpreadsheetML workbook.
XSSFWorkbook(java.io.File file)
          Constructs a XSSFWorkbook object from a given file.
XSSFWorkbook(java.io.InputStream is)
          Constructs a XSSFWorkbook object, by buffering the whole stream into memory and then opening an OPCPackage object for it.
XSSFWorkbook(OPCPackage pkg)
          Constructs a XSSFWorkbook object given a OpenXML4J Package object, see http://poi.apache.org/oxml4j/.
XSSFWorkbook(java.lang.String path)
          Constructs a XSSFWorkbook object given a file name.
XSSFWorkbook(XSSFWorkbookType workbookType)
          Create a new SpreadsheetML workbook.
 
Method Summary
 int addOlePackage(byte[] oleData, java.lang.String label, java.lang.String fileName, java.lang.String command)
           
 int addPicture(byte[] pictureData, int format)
          Adds a picture to the workbook.
 int addPicture(java.io.InputStream is, int format)
          Adds a picture to the workbook.
protected  org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache addPivotCache(java.lang.String rId)
          Add pivotCache to the workbook
 void addToolPack(UDFFinder toopack)
          Register a new toolpack in this workbook.
protected  void beforeDocumentRead()
           
 XSSFSheet cloneSheet(int sheetNum)
          Create an XSSFSheet from an existing sheet in the XSSFWorkbook.
 XSSFSheet cloneSheet(int sheetNum, java.lang.String newName)
          Create an XSSFSheet from an existing sheet in the XSSFWorkbook.
protected  void commit()
          Save the content in the underlying package part.
 XSSFCellStyle createCellStyle()
          Create a new XSSFCellStyle and add it to the workbook's style table
 XSSFDataFormat createDataFormat()
          Returns the workbook's data format table (a factory for creating data format strings).
protected  XSSFDialogsheet createDialogsheet(java.lang.String sheetname, org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet dialogsheet)
           
 XSSFFont createFont()
          Create a new Font and add it to the workbook's font table
 XSSFName createName()
           
 XSSFSheet createSheet()
          Create an XSSFSheet for this workbook, adds it to the sheets and returns the high level representation.
 XSSFSheet createSheet(java.lang.String sheetname)
          Create a new sheet for this Workbook and return the high level representation.
 XSSFFont findFont(boolean bold, 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<PackagePart> getAllEmbedds()
          Get the document's embedded files.
 java.util.List<XSSFName> getAllNames()
          Get a list of all the named ranges in the workbook.
 java.util.List<XSSFPictureData> getAllPictures()
          Gets all pictures from the Workbook.
 CalculationChain getCalculationChain()
          Return the CalculationChain object for this workbook
 XSSFCellStyle getCellStyleAt(int idx)
          Get the cell style object at the given index
 XSSFCreationHelper getCreationHelper()
          Returns an object that handles instantiating concrete classes of the various instances for XSSF.
 org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook getCTWorkbook()
          Return the underlying XML bean
 java.util.Collection<XSSFMap> getCustomXMLMappings()
           
 java.util.List<ExternalLinksTable> getExternalLinksTable()
          Returns the list of ExternalLinksTable object for this workbook
 int getFirstVisibleTab()
          Gets the first tab that is displayed in the list of tabs in excel.
 XSSFFont 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.
 MapInfo getMapInfo()
           
 Row.MissingCellPolicy getMissingCellPolicy()
          Retrieves the current policy on what to do when getting missing or blank cells from a row.
 XSSFName getName(java.lang.String name)
          Get the first named range with the given name.
 XSSFName getNameAt(int nameIndex)
          Deprecated. 3.16. New projects should avoid accessing named ranges by index.
 int getNameIndex(java.lang.String name)
          Deprecated. 3.16. New projects should avoid accessing named ranges by index. Use getName(String) instead.
 java.util.List<XSSFName> getNames(java.lang.String name)
          Get the named ranges with the given name.
 short getNumberOfFonts()
          Get the number of fonts in the this workbook
 int getNumberOfNames()
          Get the number of named ranges in the this workbook
 int getNumberOfSheets()
          Get the number of worksheets in the this workbook
 int getNumCellStyles()
          Get the number of styles the workbook contains
 java.util.List<XSSFPivotTable> getPivotTables()
           
 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.
 SharedStringsTable getSharedStringSource()
          Returns SharedStringsTable - tha cache of string for this workbook
 XSSFSheet getSheet(java.lang.String name)
          Get sheet with the given name (case insensitive match)
 XSSFSheet getSheetAt(int index)
          Get the XSSFSheet 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 (case insensitive match)
 java.lang.String getSheetName(int sheetIx)
          Get the sheet name
 SheetVisibility getSheetVisibility(int sheetIx)
           
 SpreadsheetVersion getSpreadsheetVersion()
          Returns the spreadsheet version (EXCLE2007) of this workbook
 StylesTable getStylesSource()
          Return a object representing a collection of shared objects used for styling content, e.g.
 XSSFTable getTable(java.lang.String name)
          Returns the data table with the given name (case insensitive).
 ThemesTable getTheme()
          Returns the Theme of current workbook.
 XSSFWorkbookType getWorkbookType()
           
 boolean isDate1904()
          Gets a boolean value that indicates whether the date systems used in the workbook starts in 1904.
 boolean isHidden()
           
 boolean isMacroEnabled()
          Are we a normal workbook (.xlsx), or a macro enabled workbook (.xlsm)?
 boolean isRevisionLocked()
          Specifies a boolean value that indicates whether the workbook is locked for revisions.
 boolean isSheetHidden(int sheetIx)
           
 boolean isSheetVeryHidden(int sheetIx)
           
 boolean isStructureLocked()
          Specifies a boolean value that indicates whether structure of workbook is locked.
 boolean isWindowsLocked()
          Specifies a boolean value that indicates whether the windows that comprise the workbook are locked.
 java.util.Iterator<Sheet> iterator()
          Alias for sheetIterator() to allow foreach loops Note: remove() is not supported on this iterator.
 int linkExternalWorkbook(java.lang.String name, Workbook workbook)
          Adds the External Link Table part and relations required to allow formulas referencing the specified external workbook to be added to this one.
 void lockRevision()
          Locks the workbook for revisions.
 void lockStructure()
          Locks the structure of workbook.
 void lockWindows()
          Locks the windows that comprise the workbook.
protected static OPCPackage newPackage(XSSFWorkbookType workbookType)
          Create a new SpreadsheetML package and setup the default minimal content
protected  void onDeleteFormula(XSSFCell cell)
          Fired when a formula is deleted from this workbook, for example when calling cell.setCellFormula(null)
protected  void onDocumentRead()
          Fired when a package part is read
 void parseSheet(java.util.Map<java.lang.String,XSSFSheet> shIdMap, org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet ctSheet)
          Not normally to be called externally, but possibly to be overridden to avoid the DOM based parse of large sheets (see examples).
 void removeName(int nameIndex)
          Deprecated. 3.16. New projects should use removeName(Name).
 void removeName(Name name)
          As removeName(String) is not necessarily unique (name + sheet index is unique), this method is more accurate.
 void removeName(java.lang.String name)
          Deprecated. 3.16. New projects should use removeName(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 index)
          Convenience method to set the active sheet.
 void setFirstVisibleTab(int index)
          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.
protected  void setPivotTables(java.util.List<XSSFPivotTable> pivotTables)
           
 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 setRevisionsPassword(java.lang.String password, HashAlgorithm hashAlgo)
          Sets the revisions password.
 void setSelectedTab(int index)
          We only set one sheet as selected for compatibility with HSSF.
 void setSheetHidden(int sheetIx, boolean hidden)
           
 void setSheetHidden(int sheetIx, int state)
          Deprecated. 
 void setSheetName(int sheetIndex, java.lang.String sheetname)
          Set the sheet name.
 void setSheetOrder(java.lang.String sheetname, int pos)
          sets the order of appearance for a given sheet.
 void setSheetVisibility(int sheetIx, SheetVisibility visibility)
           
 void setVBAProject(java.io.InputStream vbaProjectStream)
          Adds a vbaProject.bin file to the workbook.
 void setVBAProject(XSSFWorkbook macroWorkbook)
          Adds a vbaProject.bin file taken from another, given workbook to this one.
 void setWorkbookPassword(java.lang.String password, HashAlgorithm hashAlgo)
          Sets the workbook password.
 void setWorkbookType(XSSFWorkbookType type)
          Sets whether the workbook will be an .xlsx or .xlsm (macro-enabled) file.
 java.util.Iterator<Sheet> sheetIterator()
          Returns an iterator of the sheets in the workbook in sheet order.
 void unLock()
          Removes the workbook protection settings
 void unLockRevision()
          Unlocks the workbook for revisions.
 void unLockStructure()
          Unlocks the structure of workbook.
 void unLockWindows()
          Unlocks the windows that comprise the workbook.
 boolean validateRevisionsPassword(java.lang.String password)
          Validate the password against the stored hash, the hashing method will be determined by the existing password attributes
 boolean validateWorkbookPassword(java.lang.String password)
          Validate the password against the stored hash, the hashing method will be determined by the existing password attributes
 
Methods inherited from class org.apache.poi.POIXMLDocument
close, getCorePart, getPackage, getProperties, getRelatedByType, load, openPackage, write
 
Methods inherited from class org.apache.poi.POIXMLDocumentPart
_invokeOnDocumentRead, addRelation, createRelationship, createRelationship, createRelationship, getNextPartNumber, getPackagePart, getParent, getRelationById, getRelationId, getRelationParts, getRelations, getTargetPart, onDocumentCreate, onDocumentRemove, onSave, prepareForCommit, read, rebase, removeRelation, removeRelation, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.poi.ss.usermodel.Workbook
close, write
 

Field Detail

DEFAULT_CHARACTER_WIDTH

@Removal(version="3.19")
public static final float DEFAULT_CHARACTER_WIDTH
Deprecated. POI 3.17 beta 1
Width of one character of the default font in pixels. Same for Calibry and Arial.

See Also:
Units.DEFAULT_CHARACTER_WIDTH, Constant Field Values

PICTURE_TYPE_GIF

public static final int PICTURE_TYPE_GIF
Images formats supported by XSSF but not by HSSF

See Also:
Constant Field Values

PICTURE_TYPE_TIFF

public static final int PICTURE_TYPE_TIFF
See Also:
Constant Field Values

PICTURE_TYPE_EPS

public static final int PICTURE_TYPE_EPS
See Also:
Constant Field Values

PICTURE_TYPE_BMP

public static final int PICTURE_TYPE_BMP
See Also:
Constant Field Values

PICTURE_TYPE_WPG

public static final int PICTURE_TYPE_WPG
See Also:
Constant Field Values
Constructor Detail

XSSFWorkbook

public XSSFWorkbook()
Create a new SpreadsheetML workbook.


XSSFWorkbook

public XSSFWorkbook(XSSFWorkbookType workbookType)
Create a new SpreadsheetML workbook.

Parameters:
workbookType - The type of workbook to make (.xlsx or .xlsm).

XSSFWorkbook

public XSSFWorkbook(OPCPackage pkg)
             throws java.io.IOException
Constructs a XSSFWorkbook object given a OpenXML4J Package object, see http://poi.apache.org/oxml4j/.

Once you have finished working with the Workbook, you should close the package by calling either POIXMLDocument.close() or OPCPackage.close(), to avoid leaving file handles open.

Creating a XSSFWorkbook from a file-backed OPC Package has a lower memory footprint than an InputStream backed one.

Parameters:
pkg - the OpenXML4J OPC Package object.
Throws:
java.io.IOException

XSSFWorkbook

public XSSFWorkbook(java.io.InputStream is)
             throws java.io.IOException
Constructs a XSSFWorkbook object, by buffering the whole stream into memory and then opening an OPCPackage object for it.

Using an InputStream requires more memory than using a File, so if a File is available then you should instead do something like


       OPCPackage pkg = OPCPackage.open(path);
       XSSFWorkbook wb = new XSSFWorkbook(pkg);
       // work with the wb object
       ......
       pkg.close(); // gracefully closes the underlying zip file
   

Throws:
java.io.IOException

XSSFWorkbook

public XSSFWorkbook(java.io.File file)
             throws java.io.IOException,
                    InvalidFormatException
Constructs a XSSFWorkbook object from a given file.

Once you have finished working with the Workbook, you should close the package by calling POIXMLDocument.close(), to avoid leaving file handles open.

Opening a XSSFWorkbook from a file has a lower memory footprint than opening from an InputStream

Parameters:
file - the file to open
Throws:
java.io.IOException
InvalidFormatException

XSSFWorkbook

public XSSFWorkbook(java.lang.String path)
             throws java.io.IOException
Constructs a XSSFWorkbook object given a file name.

Once you have finished working with the Workbook, you should close the package by calling POIXMLDocument.close(), to avoid leaving file handles open.

Opening a XSSFWorkbook from a file has a lower memory footprint than opening from an InputStream

Parameters:
path - the file name.
Throws:
java.io.IOException
Method Detail

beforeDocumentRead

protected void beforeDocumentRead()

onDocumentRead

protected void onDocumentRead()
                       throws java.io.IOException
Description copied from class: POIXMLDocumentPart
Fired when a package part is read

Overrides:
onDocumentRead in class POIXMLDocumentPart
Throws:
java.io.IOException - a subclass may throw an IOException when a document is read

parseSheet

public void parseSheet(java.util.Map<java.lang.String,XSSFSheet> shIdMap,
                       org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet ctSheet)
Not normally to be called externally, but possibly to be overridden to avoid the DOM based parse of large sheets (see examples).


newPackage

protected static OPCPackage newPackage(XSSFWorkbookType workbookType)
Create a new SpreadsheetML package and setup the default minimal content


getCTWorkbook

@Internal
public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook getCTWorkbook()
Return the underlying XML bean

Returns:
the underlying CTWorkbook bean

addPicture

public int addPicture(byte[] pictureData,
                      int format)
Adds a picture to the workbook.

Specified by:
addPicture in interface Workbook
Parameters:
pictureData - The bytes of the picture
format - The format of the picture.
Returns:
the index to this picture (0 based), the added picture can be obtained from getAllPictures() .
See Also:
Workbook.PICTURE_TYPE_EMF, Workbook.PICTURE_TYPE_WMF, Workbook.PICTURE_TYPE_PICT, Workbook.PICTURE_TYPE_JPEG, Workbook.PICTURE_TYPE_PNG, Workbook.PICTURE_TYPE_DIB, getAllPictures()

addPicture

public int addPicture(java.io.InputStream is,
                      int format)
               throws java.io.IOException
Adds a picture to the workbook.

Parameters:
is - The sream to read image from
format - The format of the picture.
Returns:
the index to this picture (0 based), the added picture can be obtained from getAllPictures() .
Throws:
java.io.IOException
See Also:
Workbook.PICTURE_TYPE_EMF, Workbook.PICTURE_TYPE_WMF, Workbook.PICTURE_TYPE_PICT, Workbook.PICTURE_TYPE_JPEG, Workbook.PICTURE_TYPE_PNG, Workbook.PICTURE_TYPE_DIB, getAllPictures()

cloneSheet

public XSSFSheet cloneSheet(int sheetNum)
Create an XSSFSheet from an existing sheet in the XSSFWorkbook. The cloned sheet is a deep copy of the original.

Specified by:
cloneSheet in interface Workbook
Parameters:
sheetNum - The index of the sheet to clone
Returns:
XSSFSheet representing the cloned sheet.
Throws:
java.lang.IllegalArgumentException - if the sheet index in invalid
POIXMLException - if there were errors when cloning

cloneSheet

public XSSFSheet cloneSheet(int sheetNum,
                            java.lang.String newName)
Create an XSSFSheet from an existing sheet in the XSSFWorkbook. The cloned sheet is a deep copy of the original but with a new given name.

Parameters:
sheetNum - The index of the sheet to clone
newName - The name to set for the newly created sheet
Returns:
XSSFSheet representing the cloned sheet.
Throws:
java.lang.IllegalArgumentException - if the sheet index or the sheet name is invalid
POIXMLException - if there were errors when cloning

createCellStyle

public XSSFCellStyle createCellStyle()
Create a new XSSFCellStyle and add it to the workbook's style table

Specified by:
createCellStyle in interface Workbook
Returns:
the new XSSFCellStyle object

createDataFormat

public XSSFDataFormat createDataFormat()
Returns the workbook's data format table (a factory for creating data format strings).

Specified by:
createDataFormat in interface Workbook
Returns:
the XSSFDataFormat object
See Also:
DataFormat

createFont

public XSSFFont createFont()
Create a new Font and add it to the workbook's font table

Specified by:
createFont in interface Workbook
Returns:
new font object

createName

public XSSFName createName()
Specified by:
createName in interface Workbook

createSheet

public XSSFSheet createSheet()
Create an XSSFSheet for this workbook, adds it to the sheets and returns the high level representation. Use this to create new sheets.

Specified by:
createSheet in interface Workbook
Returns:
XSSFSheet representing the new sheet.

createSheet

public XSSFSheet 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:

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

Specified by:
createSheet in interface Workbook
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)

createDialogsheet

protected XSSFDialogsheet createDialogsheet(java.lang.String sheetname,
                                            org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet dialogsheet)

findFont

public XSSFFont findFont(boolean bold,
                         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

Specified by:
findFont in interface Workbook

getActiveSheetIndex

public 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.

Specified by:
getActiveSheetIndex in interface Workbook

getAllPictures

public java.util.List<XSSFPictureData> getAllPictures()
Gets all pictures from the Workbook.

Specified by:
getAllPictures in interface Workbook
Returns:
the list of pictures (a list of XSSFPictureData objects.)
See Also:
addPicture(byte[], int)

getCellStyleAt

public XSSFCellStyle getCellStyleAt(int idx)
Get the cell style object at the given index

Specified by:
getCellStyleAt in interface Workbook
Parameters:
idx - index within the set of styles
Returns:
XSSFCellStyle object at the index

getFontAt

public XSSFFont getFontAt(short idx)
Get the font at the given index number

Specified by:
getFontAt in interface Workbook
Parameters:
idx - index number
Returns:
XSSFFont at the index

getName

public XSSFName getName(java.lang.String name)
Get the first named range with the given name. Note: names of named ranges are not unique as they are scoped by sheet. getNames(String name) returns all named ranges with the given name.

Specified by:
getName in interface Workbook
Parameters:
name - named range name
Returns:
XSSFName with the given name. null is returned no named range could be found.

getNames

public java.util.List<XSSFName> getNames(java.lang.String name)
Get the named ranges with the given name. Note:Excel named ranges are case-insensitive and this method performs a case-insensitive search.

Specified by:
getNames in interface Workbook
Parameters:
name - named range name
Returns:
list of XSSFNames with the given name. An empty list if no named ranges could be found

getNameAt

@Deprecated
public XSSFName getNameAt(int nameIndex)
Deprecated. 3.16. New projects should avoid accessing named ranges by index.

Get the named range at the given index.

Specified by:
getNameAt in interface Workbook
Parameters:
nameIndex - the index of the named range
Returns:
the XSSFName at the given index

getAllNames

public java.util.List<XSSFName> getAllNames()
Get a list of all the named ranges in the workbook.

Specified by:
getAllNames in interface Workbook
Returns:
list of XSSFNames in the workbook

getNameIndex

@Deprecated
public int getNameIndex(java.lang.String name)
Deprecated. 3.16. New projects should avoid accessing named ranges by index. Use getName(String) instead.

Gets the named range index by name.

Specified by:
getNameIndex in interface Workbook
Parameters:
name - named range name
Returns:
named range index. -1 is returned if no named ranges could be found.

getNumCellStyles

public int getNumCellStyles()
Get the number of styles the workbook contains

Specified by:
getNumCellStyles in interface Workbook
Returns:
count of cell styles

getNumberOfFonts

public short getNumberOfFonts()
Get the number of fonts in the this workbook

Specified by:
getNumberOfFonts in interface Workbook
Returns:
number of fonts

getNumberOfNames

public int getNumberOfNames()
Get the number of named ranges in the this workbook

Specified by:
getNumberOfNames in interface Workbook
Returns:
number of named ranges

getNumberOfSheets

public int getNumberOfSheets()
Get the number of worksheets in the this workbook

Specified by:
getNumberOfSheets in interface Workbook
Returns:
number of worksheets

getPrintArea

public 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.

Specified by:
getPrintArea in interface Workbook
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

getSheet

public XSSFSheet getSheet(java.lang.String name)
Get sheet with the given name (case insensitive match)

Specified by:
getSheet in interface Workbook
Parameters:
name - of the sheet
Returns:
XSSFSheet with the name provided or null if it does not exist

getSheetAt

public XSSFSheet getSheetAt(int index)
Get the XSSFSheet object at the given index.

Specified by:
getSheetAt in interface Workbook
Parameters:
index - of the sheet number (0-based physical & logical)
Returns:
XSSFSheet at the provided index
Throws:
java.lang.IllegalArgumentException - if the index is out of range (index < 0 || index >= getNumberOfSheets()).

getSheetIndex

public int getSheetIndex(java.lang.String name)
Returns the index of the sheet by his name (case insensitive match)

Specified by:
getSheetIndex in interface Workbook
Parameters:
name - the sheet name
Returns:
index of the sheet (0 based) or -1

getSheetIndex

public int getSheetIndex(Sheet sheet)
Returns the index of the given sheet

Specified by:
getSheetIndex in interface Workbook
Parameters:
sheet - the sheet to look up
Returns:
index of the sheet (0 based). -1 if not found

getSheetName

public java.lang.String getSheetName(int sheetIx)
Get the sheet name

Specified by:
getSheetName in interface Workbook
Parameters:
sheetIx - Number
Returns:
Sheet name

sheetIterator

public java.util.Iterator<Sheet> sheetIterator()
Returns an iterator of the sheets in the workbook in sheet order. Includes hidden and very hidden sheets. Note: remove() is not supported on this iterator. Use removeSheetAt(int) to remove sheets instead.

Specified by:
sheetIterator in interface Workbook
Returns:
an iterator of the sheets.

iterator

public java.util.Iterator<Sheet> iterator()
Alias for sheetIterator() to allow foreach loops Note: remove() is not supported on this iterator. Use removeSheetAt(int) to remove sheets instead.

Specified by:
iterator in interface java.lang.Iterable<Sheet>
Returns:
an iterator of the sheets.

isMacroEnabled

public boolean isMacroEnabled()
Are we a normal workbook (.xlsx), or a macro enabled workbook (.xlsm)?


removeName

@Deprecated
public void removeName(int nameIndex)
Deprecated. 3.16. New projects should use removeName(Name).

Remove the named range at the given index.

Specified by:
removeName in interface Workbook
Parameters:
nameIndex - the index of the named range name to remove

removeName

@Deprecated
public void removeName(java.lang.String name)
Deprecated. 3.16. New projects should use removeName(Name).

Remove the first named range found with the given name. Note: names of named ranges are not unique (name + sheet index is unique), so removeName(Name) should be used if possible.

Specified by:
removeName in interface Workbook
Parameters:
name - the named range name to remove
Throws:
java.lang.IllegalArgumentException - if no named range could be found

removeName

public void removeName(Name name)
As removeName(String) is not necessarily unique (name + sheet index is unique), this method is more accurate.

Specified by:
removeName in interface Workbook
Parameters:
name - the name to remove.
Throws:
java.lang.IllegalArgumentException - if the named range is not a part of this XSSFWorkbook

removePrintArea

public void removePrintArea(int sheetIndex)
Delete the printarea for the sheet specified

Specified by:
removePrintArea in interface Workbook
Parameters:
sheetIndex - 0-based sheet index (0 = First Sheet)

removeSheetAt

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.

Specified by:
removeSheetAt in interface Workbook
Parameters:
index - of the sheet (0-based)

getMissingCellPolicy

public 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

Specified by:
getMissingCellPolicy in interface Workbook

setMissingCellPolicy

public 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

Specified by:
setMissingCellPolicy in interface Workbook

setActiveSheet

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.

Specified by:
setActiveSheet in interface Workbook

getFirstVisibleTab

public int getFirstVisibleTab()
Gets the first tab that is displayed in the list of tabs in excel.

Specified by:
getFirstVisibleTab in interface Workbook
Returns:
integer that contains the index to the active sheet in this book view.

setFirstVisibleTab

public void setFirstVisibleTab(int index)
Sets the first tab that is displayed in the list of tabs in excel.

Specified by:
setFirstVisibleTab in interface Workbook
Parameters:
index - integer that contains the index to the active sheet in this book view.

setPrintArea

public void setPrintArea(int sheetIndex,
                         java.lang.String reference)
Sets the printarea for the sheet provided

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

Specified by:
setPrintArea in interface Workbook
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

public void setPrintArea(int sheetIndex,
                         int startColumn,
                         int endColumn,
                         int startRow,
                         int endRow)
For the Convenience of Java Programmers maintaining pointers.

Specified by:
setPrintArea in interface Workbook
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)

setSelectedTab

public void setSelectedTab(int index)
We only set one sheet as selected for compatibility with HSSF.

Specified by:
setSelectedTab in interface Workbook

setSheetName

public void setSheetName(int sheetIndex,
                         java.lang.String sheetname)
Set the sheet name.

Specified by:
setSheetName in interface Workbook
Parameters:
sheetIndex - sheet number (0 based)
sheetname - the new sheet name
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)

setSheetOrder

public void setSheetOrder(java.lang.String sheetname,
                          int pos)
sets the order of appearance for a given sheet.

Specified by:
setSheetOrder in interface Workbook
Parameters:
sheetname - the name of the sheet to reorder
pos - the position that we want to insert the sheet into (0 based)

commit

protected void commit()
               throws java.io.IOException
Description copied from class: POIXMLDocumentPart
Save the content in the underlying package part. Default implementation is empty meaning that the package part is left unmodified. Sub-classes should override and add logic to marshal the "model" into Ooxml4J. For example, the code saving a generic XML entry may look as follows:
 protected void commit() throws IOException {
   PackagePart part = getPackagePart();
   OutputStream out = part.getOutputStream();
   XmlObject bean = getXmlBean(); //the "model" which holds changes in memory
   bean.save(out, DEFAULT_XML_OPTIONS);
   out.close();
 }
 

Overrides:
commit in class POIXMLDocumentPart
Throws:
java.io.IOException - a subclass may throw an IOException if the changes can't be committed

getSharedStringSource

@Internal
public SharedStringsTable getSharedStringSource()
Returns SharedStringsTable - tha cache of string for this workbook

Returns:
the shared string table

getStylesSource

public StylesTable getStylesSource()
Return a object representing a collection of shared objects used for styling content, e.g. fonts, cell styles, colors, etc.


getTheme

public ThemesTable getTheme()
Returns the Theme of current workbook.


getCreationHelper

public XSSFCreationHelper getCreationHelper()
Returns an object that handles instantiating concrete classes of the various instances for XSSF.

Specified by:
getCreationHelper in interface Workbook

isDate1904

@Internal
public boolean isDate1904()
Gets a boolean value that indicates whether the date systems used in the workbook starts in 1904.

The default value is false, meaning that the workbook uses the 1900 date system, where 1/1/1900 is the first day in the system..

Returns:
true if the date systems used in the workbook starts in 1904

getAllEmbedds

public java.util.List<PackagePart> getAllEmbedds()
                                          throws OpenXML4JException
Get the document's embedded files.

Specified by:
getAllEmbedds in class POIXMLDocument
Returns:
the document's embedded files
Throws:
OpenXML4JException - if the embedded parts can't be determined

isHidden

@NotImplemented
public boolean isHidden()
Specified by:
isHidden in interface Workbook

setHidden

@NotImplemented
public void setHidden(boolean hiddenFlag)
Specified by:
setHidden in interface Workbook

isSheetHidden

public boolean isSheetHidden(int sheetIx)
Specified by:
isSheetHidden in interface Workbook

isSheetVeryHidden

public boolean isSheetVeryHidden(int sheetIx)
Specified by:
isSheetVeryHidden in interface Workbook

getSheetVisibility

public SheetVisibility getSheetVisibility(int sheetIx)
Specified by:
getSheetVisibility in interface Workbook

setSheetHidden

public void setSheetHidden(int sheetIx,
                           boolean hidden)
Specified by:
setSheetHidden in interface Workbook

setSheetHidden

@Deprecated
@Removal(version="3.18")
public void setSheetHidden(int sheetIx,
                                                     int state)
Deprecated. 

Specified by:
setSheetHidden in interface Workbook

setSheetVisibility

public void setSheetVisibility(int sheetIx,
                               SheetVisibility visibility)
Specified by:
setSheetVisibility in interface Workbook

onDeleteFormula

protected void onDeleteFormula(XSSFCell cell)
Fired when a formula is deleted from this workbook, for example when calling cell.setCellFormula(null)

See Also:
XSSFCell.setCellFormula(String)

getCalculationChain

@Internal
public CalculationChain getCalculationChain()
Return the CalculationChain object for this workbook

The calculation chain object specifies the order in which the cells in a workbook were last calculated

Returns:
the CalculationChain object or null if not defined

getExternalLinksTable

@Internal
public java.util.List<ExternalLinksTable> getExternalLinksTable()
Returns the list of ExternalLinksTable object for this workbook

The external links table specifies details of named ranges etc that are referenced from other workbooks, along with the last seen values of what they point to.

Note that Excel uses index 0 for the current workbook, so the first External Links in a formula would be '[1]Foo' which corresponds to entry 0 in this list.

Returns:
the ExternalLinksTable list, which may be empty

getCustomXMLMappings

public java.util.Collection<XSSFMap> getCustomXMLMappings()
Returns:
a collection of custom XML mappings defined in this workbook

getMapInfo

@Internal
public MapInfo getMapInfo()
Returns:
the helper class used to query the custom XML mapping defined in this workbook

linkExternalWorkbook

@NotImplemented
public int linkExternalWorkbook(java.lang.String name,
                                               Workbook workbook)
Adds the External Link Table part and relations required to allow formulas referencing the specified external workbook to be added to this one. Allows formulas such as "[MyOtherWorkbook.xlsx]Sheet3!$A$5" to be added to the file, for workbooks not already linked / referenced. Note: this is not implemented and thus currently throws an Exception stating this.

Specified by:
linkExternalWorkbook in interface Workbook
Parameters:
name - The name the workbook will be referenced as in formulas
workbook - The open workbook to fetch the link required information from
Throws:
java.lang.RuntimeException - stating that this method is not implemented yet.

isStructureLocked

public boolean isStructureLocked()
Specifies a boolean value that indicates whether structure of workbook is locked.
A value true indicates the structure of the workbook is locked. Worksheets in the workbook can't be moved, deleted, hidden, unhidden, or renamed, and new worksheets can't be inserted.
A value of false indicates the structure of the workbook is not locked.

Returns:
true if structure of workbook is locked

isWindowsLocked

public boolean isWindowsLocked()
Specifies a boolean value that indicates whether the windows that comprise the workbook are locked.
A value of true indicates the workbook windows are locked. Windows are the same size and position each time the workbook is opened.
A value of false indicates the workbook windows are not locked.

Returns:
true if windows that comprise the workbook are locked

isRevisionLocked

public boolean isRevisionLocked()
Specifies a boolean value that indicates whether the workbook is locked for revisions.

Returns:
true if the workbook is locked for revisions.

lockStructure

public void lockStructure()
Locks the structure of workbook.


unLockStructure

public void unLockStructure()
Unlocks the structure of workbook.


lockWindows

public void lockWindows()
Locks the windows that comprise the workbook.


unLockWindows

public void unLockWindows()
Unlocks the windows that comprise the workbook.


lockRevision

public void lockRevision()
Locks the workbook for revisions.


unLockRevision

public void unLockRevision()
Unlocks the workbook for revisions.


setWorkbookPassword

public void setWorkbookPassword(java.lang.String password,
                                HashAlgorithm hashAlgo)
Sets the workbook password.

Parameters:
password - if null, the password will be removed
hashAlgo - if null, the password will be set as XOR password (Excel 2010 and earlier) otherwise the given algorithm is used for calculating the hash password (Excel 2013)

validateWorkbookPassword

public boolean validateWorkbookPassword(java.lang.String password)
Validate the password against the stored hash, the hashing method will be determined by the existing password attributes

Returns:
true, if the hashes match (... though original password may differ ...)

setRevisionsPassword

public void setRevisionsPassword(java.lang.String password,
                                 HashAlgorithm hashAlgo)
Sets the revisions password.

Parameters:
password - if null, the password will be removed
hashAlgo - if null, the password will be set as XOR password (Excel 2010 and earlier) otherwise the given algorithm is used for calculating the hash password (Excel 2013)

validateRevisionsPassword

public boolean validateRevisionsPassword(java.lang.String password)
Validate the password against the stored hash, the hashing method will be determined by the existing password attributes

Returns:
true if the hashes match (... though original password may differ ...)

unLock

public void unLock()
Removes the workbook protection settings


addToolPack

public void addToolPack(UDFFinder toopack)
Register a new toolpack in this workbook.

Specified by:
addToolPack in interface Workbook
Parameters:
toopack - the toolpack to register

setForceFormulaRecalculation

public 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.

Specified by:
setForceFormulaRecalculation in interface Workbook
Parameters:
value - true if the application will perform a full recalculation of workbook values when the workbook is opened
Since:
3.8

getForceFormulaRecalculation

public boolean getForceFormulaRecalculation()
Whether Excel will be asked to recalculate all formulas when the workbook is opened.

Specified by:
getForceFormulaRecalculation in interface Workbook
Since:
3.8

addPivotCache

@Beta
protected org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCache addPivotCache(java.lang.String rId)
Add pivotCache to the workbook


getPivotTables

@Beta
public java.util.List<XSSFPivotTable> getPivotTables()

setPivotTables

@Beta
protected void setPivotTables(java.util.List<XSSFPivotTable> pivotTables)

getWorkbookType

public XSSFWorkbookType getWorkbookType()

setWorkbookType

public void setWorkbookType(XSSFWorkbookType type)
Sets whether the workbook will be an .xlsx or .xlsm (macro-enabled) file.


setVBAProject

public void setVBAProject(java.io.InputStream vbaProjectStream)
                   throws java.io.IOException
Adds a vbaProject.bin file to the workbook. This will change the workbook type if necessary.

Throws:
java.io.IOException - If copying data from the stream fails.

setVBAProject

public void setVBAProject(XSSFWorkbook macroWorkbook)
                   throws java.io.IOException,
                          InvalidFormatException
Adds a vbaProject.bin file taken from another, given workbook to this one.

Throws:
java.io.IOException - If copying the VBAProject stream fails.
InvalidFormatException - If an error occurs while handling parts of the XSSF format

getSpreadsheetVersion

public SpreadsheetVersion getSpreadsheetVersion()
Returns the spreadsheet version (EXCLE2007) of this workbook

Specified by:
getSpreadsheetVersion in interface Workbook
Returns:
EXCEL2007 SpreadsheetVersion enum
Since:
3.14 beta 2

getTable

public XSSFTable getTable(java.lang.String name)
Returns the data table with the given name (case insensitive).

Parameters:
name - the data table name (case-insensitive)
Returns:
The Data table in the workbook named name, or null if no table is named name.
Since:
3.15 beta 2

addOlePackage

public int addOlePackage(byte[] oleData,
                         java.lang.String label,
                         java.lang.String fileName,
                         java.lang.String command)
                  throws java.io.IOException
Specified by:
addOlePackage in interface Workbook
Throws:
java.io.IOException