Class XSSFWorkbook
- java.lang.Object
-
- org.apache.poi.POIXMLDocumentPart
-
- org.apache.poi.POIXMLDocument
-
- org.apache.poi.xssf.usermodel.XSSFWorkbook
-
- All Implemented Interfaces:
- java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable<XSSFSheet>, Workbook
public class XSSFWorkbook extends POIXMLDocument implements Workbook, java.lang.Iterable<XSSFSheet>
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.
-
-
Field Summary
Fields Modifier and Type Field and Description static floatDEFAULT_CHARACTER_WIDTHWidth of one character of the default font in pixels.static intPICTURE_TYPE_BMPstatic intPICTURE_TYPE_EPSstatic intPICTURE_TYPE_GIFImages formats supported by XSSF but not by HSSFstatic intPICTURE_TYPE_TIFFstatic intPICTURE_TYPE_WPG-
Fields inherited from class org.apache.poi.POIXMLDocument
DOCUMENT_CREATOR, OLE_OBJECT_REL_TYPE, PACK_OBJECT_REL_TYPE
-
Fields inherited from class org.apache.poi.POIXMLDocumentPart
DEFAULT_XML_OPTIONS
-
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
Constructors Constructor and Description 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 anOPCPackageobject for it.XSSFWorkbook(OPCPackage pkg)Constructs a XSSFWorkbook object given a OpenXML4JPackageobject, see http://poi.apache.org/oxml4j/.XSSFWorkbook(java.lang.String path)Constructs a XSSFWorkbook object given a file name.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description intaddPicture(byte[] pictureData, int format)Adds a picture to the workbook.intaddPicture(java.io.InputStream is, int format)Adds a picture to the workbook.voidaddToolPack(UDFFinder toopack)Register a new toolpack in this workbook.XSSFSheetcloneSheet(int sheetNum)Create an XSSFSheet from an existing sheet in the XSSFWorkbook.voidclose()Closes the underlyingOPCPackagefrom which the Workbook was read, if any.XSSFCellStylecreateCellStyle()Create a new XSSFCellStyle and add it to the workbook's style tableXSSFDataFormatcreateDataFormat()Returns the instance of XSSFDataFormat for this workbook.XSSFFontcreateFont()Create a new Font and add it to the workbook's font tableXSSFNamecreateName()Creates a new (uninitialised) defined name in this workbookXSSFSheetcreateSheet()Create an XSSFSheet for this workbook, adds it to the sheets and returns the high level representation.XSSFSheetcreateSheet(java.lang.String sheetname)Create a new sheet for this Workbook and return the high level representation.XSSFFontfindFont(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 attributesintgetActiveSheetIndex()Convenience method to get the active sheet.java.util.List<PackagePart>getAllEmbedds()Get the document's embedded files.java.util.List<XSSFPictureData>getAllPictures()Gets all pictures from the Workbook.CalculationChaingetCalculationChain()Return theCalculationChainobject for this workbookXSSFCellStylegetCellStyleAt(int idx)Get the cell style object at the given indexXSSFCellStylegetCellStyleAt(short idx)Get the cell style object at the given indexXSSFCreationHelpergetCreationHelper()Returns an object that handles instantiating concrete classes of the various instances for XSSF.org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookgetCTWorkbook()Return the underlying XML beanjava.util.Collection<XSSFMap>getCustomXMLMappings()java.util.List<ExternalLinksTable>getExternalLinksTable()Returns the list ofExternalLinksTableobject for this workbookintgetFirstVisibleTab()Gets the first tab that is displayed in the list of tabs in excel.XSSFFontgetFontAt(short idx)Get the font at the given index numberbooleangetForceFormulaRecalculation()Whether Excel will be asked to recalculate all formulas when the workbook is opened.MapInfogetMapInfo()Row.MissingCellPolicygetMissingCellPolicy()Retrieves the current policy on what to do when getting missing or blank cells from a row.XSSFNamegetName(java.lang.String name)XSSFNamegetNameAt(int nameIndex)intgetNameIndex(java.lang.String name)Gets the named range index by his name Note:Excel named ranges are case-insensitive and this method performs a case-insensitive search.shortgetNumberOfFonts()Get the number of fonts in the this workbookintgetNumberOfNames()Get the number of named ranges in the this workbookintgetNumberOfSheets()Get the number of worksheets in the this workbookshortgetNumCellStyles()Get the number of styles the workbook containsjava.util.List<XSSFPivotTable>getPivotTables()java.lang.StringgetPrintArea(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.SharedStringsTablegetSharedStringSource()Returns SharedStringsTable - tha cache of string for this workbookXSSFSheetgetSheet(java.lang.String name)Get sheet with the given name (case insensitive match)XSSFSheetgetSheetAt(int index)Get the XSSFSheet object at the given index.intgetSheetIndex(Sheet sheet)Returns the index of the given sheetintgetSheetIndex(java.lang.String name)Returns the index of the sheet by his name (case insensitive match)java.lang.StringgetSheetName(int sheetIx)Get the sheet nameStylesTablegetStylesSource()Return a object representing a collection of shared objects used for styling content, e.g.ThemesTablegetTheme()Returns the Theme of current workbook.booleanisHidden()booleanisMacroEnabled()Are we a normal workbook (.xlsx), or a macro enabled workbook (.xlsm)?booleanisRevisionLocked()Specifies a boolean value that indicates whether the workbook is locked for revisions.booleanisSheetHidden(int sheetIx)Check whether a sheet is hidden.booleanisSheetVeryHidden(int sheetIx)Check whether a sheet is very hidden.booleanisStructureLocked()Specifies a boolean value that indicates whether structure of workbook is locked.booleanisWindowsLocked()Specifies a boolean value that indicates whether the windows that comprise the workbook are locked.java.util.Iterator<XSSFSheet>iterator()Allows foreach loops:intlinkExternalWorkbook(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.voidlockRevision()Locks the workbook for revisions.voidlockStructure()Locks the structure of workbook.voidlockWindows()Locks the windows that comprise the workbook.voidremoveName(int nameIndex)Remove the defined name at the specified indexvoidremoveName(java.lang.String name)Remove a defined name by namevoidremovePrintArea(int sheetIndex)Delete the printarea for the sheet specifiedvoidremoveSheetAt(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.voidsetActiveSheet(int index)Convenience method to set the active sheet.voidsetFirstVisibleTab(int index)Sets the first tab that is displayed in the list of tabs in excel.voidsetForceFormulaRecalculation(boolean value)Whether the application shall perform a full recalculation when the workbook is opened.voidsetHidden(boolean hiddenFlag)voidsetMissingCellPolicy(Row.MissingCellPolicy missingCellPolicy)Sets the policy on what to do when getting missing or blank cells from a row.voidsetPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)For the Convenience of Java Programmers maintaining pointers.voidsetPrintArea(int sheetIndex, java.lang.String reference)Sets the printarea for the sheet providedvoidsetRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)voidsetRevisionsPassword(java.lang.String password, HashAlgorithm hashAlgo)Sets the revisions password.voidsetSelectedTab(int index)We only set one sheet as selected for compatibility with HSSF.voidsetSheetHidden(int sheetIx, boolean hidden)Sets the visible state of this sheet.voidsetSheetHidden(int sheetIx, int state)Hide or unhide a sheet.voidsetSheetName(int sheetIndex, java.lang.String sheetname)Set the sheet name.voidsetSheetOrder(java.lang.String sheetname, int pos)sets the order of appearance for a given sheet.voidsetWorkbookPassword(java.lang.String password, HashAlgorithm hashAlgo)Sets the workbook password.voidunLock()Removes the workbook protection settingsvoidunLockRevision()Unlocks the workbook for revisions.voidunLockStructure()Unlocks the structure of workbook.voidunLockWindows()Unlocks the windows that comprise the workbook.booleanvalidateRevisionsPassword(java.lang.String password)Validate the password against the stored hash, the hashing method will be determined by the existing password attributesbooleanvalidateWorkbookPassword(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
getPackage, getProperties, hasOOXMLHeader, openPackage, write
-
Methods inherited from class org.apache.poi.POIXMLDocumentPart
addRelation, createRelationship, createRelationship, getPackagePart, getPackageRelationship, getParent, getRelationById, getRelationId, getRelations, toString
-
-
-
-
Field Detail
-
DEFAULT_CHARACTER_WIDTH
public static final float DEFAULT_CHARACTER_WIDTH
Width of one character of the default font in pixels. Same for Calibry and Arial.- See Also:
- 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(OPCPackage pkg) throws java.io.IOException
Constructs a XSSFWorkbook object given a OpenXML4JPackageobject, see http://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 Packageobject.- Throws:
java.io.IOException
-
XSSFWorkbook
public XSSFWorkbook(java.io.InputStream is) throws java.io.IOExceptionConstructs a XSSFWorkbook object, by buffering the whole stream into memory and then opening anOPCPackageobject for it.Using an
InputStreamrequires more memory than using a File, so if aFileis 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:
java.io.IOException
-
XSSFWorkbook
public XSSFWorkbook(java.io.File file) throws java.io.IOException, InvalidFormatExceptionConstructs 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:
java.io.IOExceptionInvalidFormatException
-
XSSFWorkbook
public XSSFWorkbook(java.lang.String path) throws java.io.IOExceptionConstructs 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:
java.io.IOException
-
-
Method Detail
-
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:
addPicturein 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:
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.IOExceptionAdds 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:
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:
cloneSheetin interfaceWorkbook- Returns:
- XSSFSheet representing the cloned sheet.
- Throws:
java.lang.IllegalArgumentException- if the sheet index in invalidPOIXMLException- 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:
createCellStylein interfaceWorkbook- Returns:
- the new XSSFCellStyle object
-
createDataFormat
public XSSFDataFormat createDataFormat()
Returns the instance of XSSFDataFormat for this workbook.- Specified by:
createDataFormatin interfaceWorkbook- 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:
createFontin interfaceWorkbook- Returns:
- new font object
-
createName
public XSSFName createName()
Description copied from interface:WorkbookCreates a new (uninitialised) defined name in this workbook- Specified by:
createNamein interfaceWorkbook- Returns:
- new defined name object
-
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:
createSheetin interfaceWorkbook- 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:
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:
createSheetin interfaceWorkbook- 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)
-
findFont
public XSSFFont 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
-
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:
getActiveSheetIndexin interfaceWorkbook- Returns:
- the index of the active sheet (0-based)
-
getAllPictures
public java.util.List<XSSFPictureData> getAllPictures()
Gets all pictures from the Workbook.- Specified by:
getAllPicturesin interfaceWorkbook- Returns:
- the list of pictures (a list of
XSSFPictureDataobjects.) - See Also:
addPicture(byte[], int)
-
getCellStyleAt
public XSSFCellStyle getCellStyleAt(short idx)
Get the cell style object at the given index- Specified by:
getCellStyleAtin interfaceWorkbook- Parameters:
idx- index within the set of styles- Returns:
- XSSFCellStyle object at the index
-
getCellStyleAt
public XSSFCellStyle getCellStyleAt(int idx)
Get the cell style object at the given index- 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
-
getName
public XSSFName getName(java.lang.String name)
-
getNameAt
public XSSFName getNameAt(int nameIndex)
-
getNameIndex
public int getNameIndex(java.lang.String name)
Gets the named range index by his name Note:Excel named ranges are case-insensitive and this method performs a case-insensitive search.- Specified by:
getNameIndexin interfaceWorkbook- Parameters:
name- named range name- Returns:
- named range index
-
getNumCellStyles
public short getNumCellStyles()
Get the number of styles the workbook contains- Specified by:
getNumCellStylesin interfaceWorkbook- Returns:
- count of cell styles
-
getNumberOfFonts
public short getNumberOfFonts()
Get the number of fonts in the this workbook- Specified by:
getNumberOfFontsin interfaceWorkbook- Returns:
- number of fonts
-
getNumberOfNames
public int getNumberOfNames()
Get the number of named ranges in the this workbook- Specified by:
getNumberOfNamesin interfaceWorkbook- Returns:
- number of named ranges
-
getNumberOfSheets
public int getNumberOfSheets()
Get the number of worksheets in the this workbook- Specified by:
getNumberOfSheetsin interfaceWorkbook- 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:
getPrintAreain 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
public XSSFSheet getSheet(java.lang.String name)
Get sheet with the given name (case insensitive match)
-
getSheetAt
public XSSFSheet getSheetAt(int index)
Get the XSSFSheet object at the given index.- Specified by:
getSheetAtin interfaceWorkbook- 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:
getSheetIndexin interfaceWorkbook- 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:
getSheetIndexin interfaceWorkbook- 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:
getSheetNamein interfaceWorkbook- Parameters:
sheetIx- Number- Returns:
- Sheet name
-
iterator
public java.util.Iterator<XSSFSheet> iterator()
Allows foreach loops:XSSFWorkbook wb = new XSSFWorkbook(package); for(XSSFSheet sheet : wb){ }- Specified by:
iteratorin interfacejava.lang.Iterable<XSSFSheet>
-
isMacroEnabled
public boolean isMacroEnabled()
Are we a normal workbook (.xlsx), or a macro enabled workbook (.xlsm)?
-
removeName
public void removeName(int nameIndex)
Description copied from interface:WorkbookRemove the defined name at the specified index- Specified by:
removeNamein interfaceWorkbook- Parameters:
nameIndex- named range index (0 based)
-
removeName
public void removeName(java.lang.String name)
Description copied from interface:WorkbookRemove a defined name by name- Specified by:
removeNamein interfaceWorkbook- Parameters:
name- the name of the defined name
-
removePrintArea
public void removePrintArea(int sheetIndex)
Delete the printarea for the sheet specified- Specified by:
removePrintAreain 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:
removeSheetAtin interfaceWorkbook- 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:
getMissingCellPolicyin interfaceWorkbook
-
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 toRow.getCell(int)}. SeeRow.MissingCellPolicy- Specified by:
setMissingCellPolicyin 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:
setActiveSheetin 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:
getFirstVisibleTabin 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:
setFirstVisibleTabin interfaceWorkbook- 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 providedi.e. Reference = $A$1:$B$2
- Specified by:
setPrintAreain 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:
setPrintAreain 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:
setPrintArea(int, String)
-
setRepeatingRowsAndColumns
@Deprecated public void setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)Deprecated. useXSSFSheet.setRepeatingRows(CellRangeAddress)orXSSFSheet.setRepeatingColumns(CellRangeAddress)Sets the repeating rows and columns for a sheet. 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);
- Specified by:
setRepeatingRowsAndColumnsin interfaceWorkbook- 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.
-
setSelectedTab
public void setSelectedTab(int index)
We only set one sheet as selected for compatibility with HSSF.- Specified by:
setSelectedTabin interfaceWorkbook- Parameters:
index- the index of the sheet to select (0 based)- See Also:
Sheet.setSelected(boolean)
-
setSheetName
public void setSheetName(int sheetIndex, java.lang.String sheetname)Set the sheet name.- Specified by:
setSheetNamein interfaceWorkbook- 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:
setSheetOrderin interfaceWorkbook- Parameters:
sheetname- the name of the sheet to reorderpos- the position that we want to insert the sheet into (0 based)
-
close
public void close() throws java.io.IOExceptionCloses the underlyingOPCPackagefrom which the Workbook was read, if any. Has no effect on newly created Workbooks.
-
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:
getCreationHelperin interfaceWorkbook
-
getAllEmbedds
public java.util.List<PackagePart> getAllEmbedds() throws OpenXML4JException
Get the document's embedded files.- Specified by:
getAllEmbeddsin classPOIXMLDocument- Throws:
OpenXML4JException
-
isHidden
public boolean isHidden()
-
setHidden
public void setHidden(boolean hiddenFlag)
-
isSheetHidden
public 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))- Specified by:
isSheetHiddenin interfaceWorkbook- Parameters:
sheetIx- Number- Returns:
trueif sheet is hidden
-
isSheetVeryHidden
public boolean isSheetVeryHidden(int sheetIx)
Check whether a sheet is very hidden.This is different from the normal hidden status (
isSheetHidden(int))- Specified by:
isSheetVeryHiddenin interfaceWorkbook- Parameters:
sheetIx- sheet index to check- Returns:
trueif sheet is very hidden
-
setSheetHidden
public void setSheetHidden(int sheetIx, boolean hidden)Sets the visible state of this sheet.Calling
setSheetHidden(sheetIndex, true)is equivalent tosetSheetHidden(sheetIndex, Workbook.SHEET_STATE_HIDDEN).
CallingsetSheetHidden(sheetIndex, false)is equivalent tosetSheetHidden(sheetIndex, Workbook.SHEET_STATE_VISIBLE).- Specified by:
setSheetHiddenin interfaceWorkbook- Parameters:
sheetIx- the 0-based index of the sheethidden- whether this sheet is hidden- See Also:
setSheetHidden(int, int)
-
setSheetHidden
public void setSheetHidden(int sheetIx, int state)Hide or unhide a sheet.- 0 - visible.
- 1 - hidden.
- 2 - very hidden.
- Specified by:
setSheetHiddenin interfaceWorkbook- Parameters:
sheetIx- the sheet index (0-based)state- one of the followingWorkbookconstants:Workbook.SHEET_STATE_VISIBLE,Workbook.SHEET_STATE_HIDDEN, orWorkbook.SHEET_STATE_VERY_HIDDEN.- Throws:
java.lang.IllegalArgumentException- if the supplied sheet index or state is invalid
-
getCalculationChain
@Internal public CalculationChain getCalculationChain()
Return theCalculationChainobject for this workbookThe calculation chain object specifies the order in which the cells in a workbook were last calculated
- Returns:
- the
CalculationChainobject ornullif not defined
-
getExternalLinksTable
@Internal public java.util.List<ExternalLinksTable> getExternalLinksTable()
Returns the list ofExternalLinksTableobject 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
ExternalLinksTablelist, 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
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.- Specified by:
linkExternalWorkbookin interfaceWorkbook- Parameters:
name- The name the workbook will be referenced as in formulasworkbook- The open workbook to fetch the link required information from
-
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 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
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 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
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:
addToolPackin interfaceWorkbook- 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:
setForceFormulaRecalculationin 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:
getForceFormulaRecalculationin interfaceWorkbook- Since:
- 3.8
-
getPivotTables
@Beta public java.util.List<XSSFPivotTable> getPivotTables()
-
-
DataMelt 3.0 © DataMelt by jWork.ORG