Class XSSFWorkbook
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<Sheet>
,Date1904Support
,Workbook
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
POIXMLDocumentPart.RelationPart
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
Images formats supported by XSSF but not by HSSFstatic final int
static final int
Fields inherited from class org.apache.poi.ooxml.POIXMLDocument
DOCUMENT_CREATOR, OLE_OBJECT_REL_TYPE, PACK_OBJECT_REL_TYPE
Fields inherited from interface org.apache.poi.ss.usermodel.Workbook
MAX_SENSITIVE_SHEET_NAME_LEN, PICTURE_TYPE_DIB, PICTURE_TYPE_EMF, PICTURE_TYPE_JPEG, PICTURE_TYPE_PICT, PICTURE_TYPE_PNG, PICTURE_TYPE_WMF
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new SpreadsheetML workbook.XSSFWorkbook
(File file) Constructs a XSSFWorkbook object from a given file.Constructs a XSSFWorkbook object, by buffering the whole stream into memory and then opening anOPCPackage
object for it.XSSFWorkbook
(String path) Constructs a XSSFWorkbook object given a file name.XSSFWorkbook
(OPCPackage pkg) Constructs a XSSFWorkbook object given a OpenXML4JPackage
object, see https://poi.apache.org/oxml4j/.XSSFWorkbook
(PackagePart part) Constructs a XSSFWorkbook object using Package Part.XSSFWorkbook
(XSSFFactory factory) XSSFWorkbook
(XSSFWorkbookType workbookType) Create a new SpreadsheetML workbook. -
Method Summary
Modifier and TypeMethodDescriptionint
addOlePackage
(byte[] oleData, String label, String fileName, String command) Adds an OLE package manager object with the given content to the sheetint
addPicture
(byte[] pictureData, int format) Adds a picture to the workbook.int
addPicture
(InputStream is, int format) Adds a picture to the workbook.void
addToolPack
(UDFFinder toolpack) Register a new toolpack in this workbook.cloneSheet
(int sheetNum) Create an XSSFSheet from an existing sheet in the XSSFWorkbook.cloneSheet
(int sheetNum, String newName) Create an XSSFSheet from an existing sheet in the XSSFWorkbook.void
close()
Closes the underlyingOPCPackage
from which this document was read, if there is oneCreate a new XSSFCellStyle and add it to the workbook's style tableReturns the workbook's data format table (a factory for creating data format strings).Create a new Font and add it to the workbook's font tableCreates a new (uninitialised) defined name in this workbookCreate an XSSFSheet for this workbook, adds it to the sheets and returns the high level representation.createSheet
(String sheetname) Create a new sheet for this Workbook and return the high level representation.findFont
(boolean bold, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) Finds a font that matches the one with the supplied attributesint
Convenience method to get the active sheet.Get the document's embedded files.Get a list of all the named ranges in the workbook.Gets all pictures from the Workbook.Return theCalculationChain
object for this workbookboolean
Whether a call toCellBase.setCellFormula(String)
will validate the formula or not.getCellStyleAt
(int idx) Get the cell style object at the given indexReturns an object that handles instantiating concrete classes of the various instances for XSSF.Return the underlying XML beanReturns the list ofExternalLinksTable
object for this workbookint
Gets the first tab that is displayed in the list of tabs in excel.getFontAt
(int idx) Get the font at the given index numberboolean
Whether Excel will be asked to recalculate all formulas when the workbook is opened.Retrieves the current policy on what to do when getting missing or blank cells from a row.Get the first named range with the given name.Get the named ranges with the given name.int
Get the number of fonts in the font tableint
Deprecated.int
Get the number of named ranges in the this workbookint
Get the number of worksheets in the this workbookint
Get the number of styles the workbook containsgetPrintArea
(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.Returns SharedStringsTable - tha cache of string for this workbookGet sheet with the given name (case insensitive match)getSheetAt
(int index) Get the XSSFSheet object at the given index.int
getSheetIndex
(String name) Returns the index of the sheet by his name (case insensitive match)int
getSheetIndex
(Sheet sheet) Returns the index of the given sheetgetSheetName
(int sheetIx) Get the sheet namegetSheetVisibility
(int sheetIx) Get the visibility (visible, hidden, very hidden) of a sheet in this workbookReturns the spreadsheet version (EXCLE2007) of this workbookReturn a object representing a collection of shared objects used for styling content, e.g.Returns the data table with the given name (case insensitive).getTheme()
Returns the Theme of current workbook.boolean
Gets a boolean value that indicates whether the date systems used in the workbook starts in 1904.boolean
isHidden()
boolean
Are we a normal workbook (.xlsx), or a macro enabled workbook (.xlsm)?boolean
Specifies a boolean value that indicates whether the workbook is locked for revisions.boolean
isSheetHidden
(int sheetIx) Check whether a sheet is hidden.boolean
isSheetVeryHidden
(int sheetIx) Check whether a sheet is very hidden.boolean
Specifies a boolean value that indicates whether structure of workbook is locked.boolean
Specifies a boolean value that indicates whether the windows that comprise the workbook are locked.iterator()
Alias forsheetIterator()
to allow foreach loops Note: remove() is not supported on this iterator.int
linkExternalWorkbook
(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
Locks the workbook for revisions.void
Locks the structure of workbook.void
Locks the windows that comprise the workbook.void
parseSheet
(Map<String, XSSFSheet> shIdMap, 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
(Name name) Remove a defined namevoid
removePrintArea
(int sheetIndex) Delete the printarea for the sheet specifiedvoid
removeSheetAt
(int index) Removes sheet at the given index.void
setActiveSheet
(int index) Convenience method to set the active sheet.void
setCellFormulaValidation
(boolean value) Whether a call toCellBase.setCellFormula(String)
will validate the formula or not.void
setCellReferenceType
(CellReferenceType cellReferenceType) 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.void
setPrintArea
(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) For the Convenience of Java Programmers maintaining pointers.void
setPrintArea
(int sheetIndex, String reference) Sets the printarea for the sheet providedvoid
setRevisionsPassword
(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) Hide or unhide a sheet.void
setSheetName
(int sheetIndex, String sheetname) Set the sheet name.void
setSheetOrder
(String sheetname, int pos) sets the order of appearance for a given sheet.void
setSheetVisibility
(int sheetIx, SheetVisibility visibility) Hide or unhide a sheet.void
setVBAProject
(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
(String password, HashAlgorithm hashAlgo) Sets the workbook password.void
Sets whether the workbook will be an .xlsx or .xlsm (macro-enabled) file.Returns an iterator of the sheets in the workbook in sheet order.Returns a spliterator of the sheets in the workbook in sheet order.void
unLock()
Removes the workbook protection settingsvoid
Unlocks the workbook for revisions.void
Unlocks the structure of workbook.void
Unlocks the windows that comprise the workbook.boolean
validateRevisionsPassword
(String password) Validate the password against the stored hash, the hashing method will be determined by the existing password attributesboolean
validateWorkbookPassword
(String password) Validate the password against the stored hash, the hashing method will be determined by the existing password attributesMethods inherited from class org.apache.poi.ooxml.POIXMLDocument
getPackage, getProperties, openPackage, write
Methods inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
_invokeOnDocumentRead, addRelation, createRelationship, createRelationship, createRelationship, getNextPartNumber, getPackagePart, getParent, getRelationById, getRelationId, getRelationPartById, getRelationParts, getRelations, isCommitted, setCommitted, toString
-
Field Details
-
PICTURE_TYPE_GIF
public static final int PICTURE_TYPE_GIFImages formats supported by XSSF but not by HSSF- See Also:
-
PICTURE_TYPE_TIFF
public static final int PICTURE_TYPE_TIFF- See Also:
-
PICTURE_TYPE_EPS
public static final int PICTURE_TYPE_EPS- See Also:
-
PICTURE_TYPE_BMP
public static final int PICTURE_TYPE_BMP- See Also:
-
PICTURE_TYPE_WPG
public static final int PICTURE_TYPE_WPG- See Also:
-
-
Constructor Details
-
XSSFWorkbook
public XSSFWorkbook()Create a new SpreadsheetML workbook. -
XSSFWorkbook
-
XSSFWorkbook
Create a new SpreadsheetML workbook.- Parameters:
workbookType
- The type of workbook to make (.xlsx or .xlsm).
-
XSSFWorkbook
Constructs a XSSFWorkbook object given a OpenXML4JPackage
object, see https://poi.apache.org/oxml4j/.Once you have finished working with the Workbook, you should close the package by calling either
close()
orOPCPackage.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 OpenXML4JOPC Package
object.- Throws:
IOException
- If reading data from the package failsPOIXMLException
- a RuntimeException that can be caused by invalid OOXML dataRuntimeException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
XSSFWorkbook
Constructs a XSSFWorkbook object, by buffering the whole stream into memory and then opening anOPCPackage
object for it.Using an
InputStream
requires more memory than using a File, so if aFile
is available then you should instead do something likeOPCPackage pkg = OPCPackage.open(path); XSSFWorkbook wb = new XSSFWorkbook(pkg); // work with the wb object ...... pkg.close(); // gracefully closes the underlying zip file
- Throws:
IOException
- If reading data from the stream failsPOIXMLException
- a RuntimeException that can be caused by invalid OOXML dataRuntimeException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
XSSFWorkbook
Constructs a XSSFWorkbook object from a given file.Once you have finished working with the Workbook, you should close the package by calling
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:
IOException
- If reading data from the file failsInvalidFormatException
- If the file has a format that cannot be read or if the file is corruptedPOIXMLException
- a RuntimeException that can be caused by invalid OOXML dataRuntimeException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
XSSFWorkbook
Constructs a XSSFWorkbook object given a file name.Once you have finished working with the Workbook, you should close the package by calling
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:
IOException
- If reading data from the file failsPOIXMLException
- a RuntimeException that can be caused by invalid OOXML dataRuntimeException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
XSSFWorkbook
Constructs a XSSFWorkbook object using Package Part.- Parameters:
part
- package part- Throws:
IOException
- If reading data from the Package Part failsPOIXMLException
- a RuntimeException that can be caused by invalid OOXML dataRuntimeException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format- Since:
- POI 4.0.0
-
-
Method Details
-
getXssfFactory
- Returns:
- the XSSFFactory
- Since:
- POI 5.1.0
-
parseSheet
Not normally to be called externally, but possibly to be overridden to avoid the DOM based parse of large sheets (see examples).- Throws:
POIXMLException
- a RuntimeException that can be caused by invalid OOXML dataRuntimeException
- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
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 interfaceWorkbook
- Parameters:
pictureData
- The bytes of the pictureformat
- The format of the picture.- Returns:
- the index to this picture (0 based), the added picture can be obtained from
getAllPictures()
. - See Also:
-
addPicture
Adds a picture to the workbook.- Parameters:
is
- The sream to read image fromformat
- The format of the picture.- Returns:
- the index to this picture (0 based), the added picture can be obtained from
getAllPictures()
. - Throws:
IOException
- See Also:
-
cloneSheet
Create an XSSFSheet from an existing sheet in the XSSFWorkbook. The cloned sheet is a deep copy of the original.- Specified by:
cloneSheet
in interfaceWorkbook
- Parameters:
sheetNum
- The index of the sheet to clone- Returns:
- XSSFSheet representing the cloned sheet.
- Throws:
IllegalArgumentException
- if the sheet index in invalidPOIXMLException
- if there were errors when cloning
-
close
Description copied from class:POIXMLDocument
Closes the underlyingOPCPackage
from which this document was read, if there is oneOnce this has been called, no further operations, updates or reads should be performed on the document.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceWorkbook
- Overrides:
close
in classPOIXMLDocument
- Throws:
IOException
- for writable packages, if an IO exception occur during the saving process.
-
cloneSheet
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 clonenewName
- The name to set for the newly created sheet- Returns:
- XSSFSheet representing the cloned sheet.
- Throws:
IllegalArgumentException
- if the sheet index or the sheet name is invalidPOIXMLException
- if there were errors when cloning
-
createCellStyle
Create a new XSSFCellStyle and add it to the workbook's style table- Specified by:
createCellStyle
in interfaceWorkbook
- Returns:
- the new XSSFCellStyle object
-
createDataFormat
Returns the workbook's data format table (a factory for creating data format strings).- Specified by:
createDataFormat
in interfaceWorkbook
- Returns:
- the XSSFDataFormat object
- See Also:
-
createFont
Create a new Font and add it to the workbook's font table- Specified by:
createFont
in interfaceWorkbook
- Returns:
- new font object
-
createName
Description copied from interface:Workbook
Creates a new (uninitialised) defined name in this workbook- Specified by:
createName
in interfaceWorkbook
- Returns:
- new defined name object
-
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 interfaceWorkbook
- Returns:
- XSSFSheet representing the new sheet.
-
createSheet
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:
Except the 31-character constraint, Excel applies some other rules: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();
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 (])
See
WorkbookUtil.createSafeSheetName(String nameProposal)
for a safe way to create valid names- Specified by:
createSheet
in interfaceWorkbook
- Parameters:
sheetname
- sheetname to set for the sheet.- Returns:
- Sheet representing the new sheet.
- Throws:
IllegalArgumentException
- if the name is null or invalid or workbook already contains a sheet with this name- See Also:
-
findFont
public XSSFFont findFont(boolean bold, 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 -
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 interfaceWorkbook
- Returns:
- the index of the active sheet (0-based)
-
getAllPictures
Gets all pictures from the Workbook.- Specified by:
getAllPictures
in interfaceWorkbook
- Returns:
- the list of pictures (a list of
XSSFPictureData
objects.) - See Also:
-
getCellStyleAt
Get the cell style object at the given index- Specified by:
getCellStyleAt
in interfaceWorkbook
- Parameters:
idx
- index within the set of styles- Returns:
- XSSFCellStyle object at the index
-
getFontAt
Description copied from interface:Workbook
Get the font at the given index number -
getName
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. -
getNames
Get the named ranges with the given name. Note:Excel named ranges are case-insensitive and this method performs a case-insensitive search. -
getAllNames
Get a list of all the named ranges in the workbook.- Specified by:
getAllNames
in interfaceWorkbook
- Returns:
- list of XSSFNames in the workbook
-
getNumCellStyles
public int getNumCellStyles()Get the number of styles the workbook contains- Specified by:
getNumCellStyles
in interfaceWorkbook
- Returns:
- count of cell styles
-
getNumberOfFonts
public int getNumberOfFonts()Description copied from interface:Workbook
Get the number of fonts in the font table- Specified by:
getNumberOfFonts
in interfaceWorkbook
- Returns:
- number of fonts (as int since POI 5.0.0)
-
getNumberOfFontsAsInt
Deprecated.Description copied from interface:Workbook
Get the number of fonts in the font table- Specified by:
getNumberOfFontsAsInt
in interfaceWorkbook
- Returns:
- number of fonts
-
getNumberOfNames
public int getNumberOfNames()Get the number of named ranges in the this workbook- Specified by:
getNumberOfNames
in interfaceWorkbook
- Returns:
- number of named ranges
-
getNumberOfSheets
public int getNumberOfSheets()Get the number of worksheets in the this workbook- Specified by:
getNumberOfSheets
in interfaceWorkbook
- Returns:
- number of worksheets
-
getPrintArea
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 interfaceWorkbook
- 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
Get sheet with the given name (case insensitive match) -
getSheetAt
Get the XSSFSheet object at the given index.- Specified by:
getSheetAt
in interfaceWorkbook
- Parameters:
index
- of the sheet number (0-based physical & logical)- Returns:
- XSSFSheet at the provided index
- Throws:
IllegalArgumentException
- if the index is out of range (index < 0 || index >= getNumberOfSheets()).
-
getSheetIndex
Returns the index of the sheet by his name (case insensitive match)- Specified by:
getSheetIndex
in interfaceWorkbook
- Parameters:
name
- the sheet name- Returns:
- index of the sheet (0 based) or
-1
if not found
-
getSheetIndex
Returns the index of the given sheet- Specified by:
getSheetIndex
in interfaceWorkbook
- Parameters:
sheet
- the sheet to look up- Returns:
- index of the sheet (0 based).
-1
if not found
-
getSheetName
Get the sheet name- Specified by:
getSheetName
in interfaceWorkbook
- Parameters:
sheetIx
- Number- Returns:
- Sheet name
-
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. UseremoveSheetAt(int)
to remove sheets instead.- Specified by:
sheetIterator
in interfaceWorkbook
- Returns:
- an iterator of the sheets.
-
iterator
Alias forsheetIterator()
to allow foreach loops Note: remove() is not supported on this iterator. UseremoveSheetAt(int)
to remove sheets instead. -
spliterator
Returns a spliterator of the sheets in the workbook in sheet order. Includes hidden and very hidden sheets.- Specified by:
spliterator
in interfaceIterable<Sheet>
- Specified by:
spliterator
in interfaceWorkbook
- Returns:
- a spliterator of the sheets.
- Since:
- POI 5.2.0
-
isMacroEnabled
public boolean isMacroEnabled()Are we a normal workbook (.xlsx), or a macro enabled workbook (.xlsm)? -
removeName
Description copied from interface:Workbook
Remove a defined name- Specified by:
removeName
in interfaceWorkbook
- Parameters:
name
- the name to remove.- Throws:
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 interfaceWorkbook
- 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 interfaceWorkbook
- Parameters:
index
- of the sheet (0-based)
-
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 interfaceWorkbook
-
setMissingCellPolicy
Sets the policy on what to do when getting missing or blank cells from a row. This will then apply to all calls toRow.getCell(int)
}. SeeRow.MissingCellPolicy
- Specified by:
setMissingCellPolicy
in interfaceWorkbook
-
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 interfaceWorkbook
- Parameters:
index
- index of the active sheet (0-based)
-
getFirstVisibleTab
public int getFirstVisibleTab()Gets the first tab that is displayed in the list of tabs in excel.- Specified by:
getFirstVisibleTab
in interfaceWorkbook
- 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 interfaceWorkbook
- Parameters:
index
- integer that contains the index to the active sheet in this book view.
-
setPrintArea
Sets the printarea for the sheet providedi.e. Reference = $A$1:$B$2
- Specified by:
setPrintArea
in interfaceWorkbook
- 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 interfaceWorkbook
- Parameters:
sheetIndex
- Zero-based sheet index (0 = First Sheet)startColumn
- Column to begin printareaendColumn
- Column to end the printareastartRow
- Row to begin the printareaendRow
- Row to end the printarea- See Also:
-
getCellReferenceType
- Specified by:
getCellReferenceType
in interfaceWorkbook
- Returns:
- the type of cell references used
-
setCellReferenceType
- Specified by:
setCellReferenceType
in interfaceWorkbook
- Parameters:
cellReferenceType
- the type of cell references used
-
setSelectedTab
public void setSelectedTab(int index) We only set one sheet as selected for compatibility with HSSF.- Specified by:
setSelectedTab
in interfaceWorkbook
- Parameters:
index
- the index of the sheet to select (0 based)- See Also:
-
setSheetName
Set the sheet name.- Specified by:
setSheetName
in interfaceWorkbook
- Parameters:
sheetIndex
- sheet number (0 based)sheetname
- the new sheet name- Throws:
IllegalArgumentException
- if the name is null or invalid or workbook already contains a sheet with this name- See Also:
-
setSheetOrder
sets the order of appearance for a given sheet.- Specified by:
setSheetOrder
in interfaceWorkbook
- Parameters:
sheetname
- the name of the sheet to reorderpos
- the position that we want to insert the sheet into (0 based)
-
getStylesSource
Return a object representing a collection of shared objects used for styling content, e.g. fonts, cell styles, colors, etc. -
getTheme
Returns the Theme of current workbook. -
getCreationHelper
Returns an object that handles instantiating concrete classes of the various instances for XSSF.- Specified by:
getCreationHelper
in interfaceWorkbook
-
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..
- Specified by:
isDate1904
in interfaceDate1904Support
- Returns:
- true if the date systems used in the workbook starts in 1904
-
getAllEmbeddedParts
Get the document's embedded files.- Specified by:
getAllEmbeddedParts
in classPOIXMLDocument
- Returns:
- the document's embedded files
- Throws:
OpenXML4JException
- if the embedded parts can't be determined
-
isHidden
-
setHidden
-
isSheetHidden
public boolean isSheetHidden(int sheetIx) Description copied from interface:Workbook
Check whether a sheet is hidden.Note that a sheet could instead be set to be very hidden, which is different (
Workbook.isSheetVeryHidden(int)
)- Specified by:
isSheetHidden
in interfaceWorkbook
- Parameters:
sheetIx
- Number- Returns:
true
if sheet is hidden- See Also:
-
isSheetVeryHidden
public boolean isSheetVeryHidden(int sheetIx) Description copied from interface:Workbook
Check whether a sheet is very hidden.This is different from the normal hidden status (
Workbook.isSheetHidden(int)
)- Specified by:
isSheetVeryHidden
in interfaceWorkbook
- Parameters:
sheetIx
- sheet index to check- Returns:
true
if sheet is very hidden- See Also:
-
getSheetVisibility
Description copied from interface:Workbook
Get the visibility (visible, hidden, very hidden) of a sheet in this workbook- Specified by:
getSheetVisibility
in interfaceWorkbook
- Parameters:
sheetIx
- the index of the sheet- Returns:
- the sheet visibility
-
setSheetHidden
public void setSheetHidden(int sheetIx, boolean hidden) Description copied from interface:Workbook
Hide or unhide a sheet. Please note that the sheet currently set as active sheet (sheet 0 in a newly created workbook or the one set via setActiveSheet()) cannot be hidden.- Specified by:
setSheetHidden
in interfaceWorkbook
- Parameters:
sheetIx
- the sheet index (0-based)hidden
- True to mark the sheet as hidden, false otherwise- See Also:
-
setSheetVisibility
Description copied from interface:Workbook
Hide or unhide a sheet. Please note that the sheet currently set as active sheet (sheet 0 in a newly created workbook or the one set via setActiveSheet()) cannot be hidden.- Specified by:
setSheetVisibility
in interfaceWorkbook
- Parameters:
sheetIx
- the sheet index (0-based)visibility
- the sheet visibility to set
-
getCalculationChain
Return theCalculationChain
object for this workbookThe calculation chain object specifies the order in which the cells in a workbook were last calculated
- Returns:
- the
CalculationChain
object ornull
if not defined
-
getExternalLinksTable
Returns the list ofExternalLinksTable
object for this workbookThe 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
- Returns:
- a collection of custom XML mappings defined in this workbook
-
getMapInfo
- Returns:
- the helper class used to query the custom XML mapping defined in this workbook
-
linkExternalWorkbook
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.This support is still regarded as in beta and may change
see https://bz.apache.org/bugzilla/show_bug.cgi?id=57184
- Specified by:
linkExternalWorkbook
in interfaceWorkbook
- Parameters:
name
- The name the workbook will be referenced as in formulasworkbook
- The open workbook to fetch the link required information from- Returns:
- index position for external workbook
- Since:
- POI 5.1.0
-
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
Sets the workbook password.- Parameters:
password
- if null, the password will be removedhashAlgo
- 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
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
Sets the revisions password.- Parameters:
password
- if null, the password will be removedhashAlgo
- 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
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
Register a new toolpack in this workbook.- Specified by:
addToolPack
in interfaceWorkbook
- Parameters:
toolpack
- 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 interfaceWorkbook
- 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 interfaceWorkbook
- Since:
- 3.8
-
getPivotTables
-
getWorkbookType
-
setWorkbookType
Sets whether the workbook will be an .xlsx or .xlsm (macro-enabled) file. -
setVBAProject
Adds a vbaProject.bin file to the workbook. This will change the workbook type if necessary.- Throws:
IOException
- If copying data from the stream fails.
-
setVBAProject
Adds a vbaProject.bin file taken from another, given workbook to this one.- Throws:
IOException
- If copying the VBAProject stream fails.InvalidFormatException
- If an error occurs while handling parts of the XSSF format
-
getSpreadsheetVersion
Returns the spreadsheet version (EXCLE2007) of this workbook- Specified by:
getSpreadsheetVersion
in interfaceWorkbook
- Returns:
- EXCEL2007 SpreadsheetVersion enum
- Since:
- 3.14 beta 2
-
getTable
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
, ornull
if no table is namedname
. - Since:
- 3.15 beta 2
-
addOlePackage
public int addOlePackage(byte[] oleData, String label, String fileName, String command) throws IOException Description copied from interface:Workbook
Adds an OLE package manager object with the given content to the sheet- Specified by:
addOlePackage
in interfaceWorkbook
- Parameters:
oleData
- the payloadlabel
- the label of the payloadfileName
- the original filenamecommand
- the command to open the payload- Returns:
- the index of the added ole object, i.e. the storage id
- Throws:
IOException
- if the object can't be embedded
-
setCellFormulaValidation
public void setCellFormulaValidation(boolean value) Whether a call toCellBase.setCellFormula(String)
will validate the formula or not. When enabled (which is the default), this option can lead to formulas being modified by POI formula renderer.- Parameters:
value
- true if the application will validate the formula is correct- Since:
- 3.17
-
getCellFormulaValidation
public boolean getCellFormulaValidation()Whether a call toCellBase.setCellFormula(String)
will validate the formula or not. When enabled (which is the default), this option can lead to formulas being modified by POI formula renderer.- Since:
- 3.17
-
createEvaluationWorkbook
- Specified by:
createEvaluationWorkbook
in interfaceWorkbook
- Returns:
- an evaluation workbook
-