public class SXSSFWorkbook extends java.lang.Object implements Workbook
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
SXSSFWorkbook.ISheetInjector |
protected class |
SXSSFWorkbook.SheetIterator<T extends Sheet> |
| Modifier and Type | Field and Description |
|---|---|
protected SharedStringsTable |
_sharedStringSource
shared string table - a cache of strings in this workbook
|
protected XSSFWorkbook |
_wb |
static int |
DEFAULT_WINDOW_SIZE
Specifies how many rows can be accessed at most via
SXSSFSheet.getRow(int). |
protected org.apache.commons.compress.archivers.zip.Zip64Mode |
zip64Mode
controls whether Zip64 mode is used - Always became the default in POI 5.0.0
|
MAX_SENSITIVE_SHEET_NAME_LEN, PICTURE_TYPE_DIB, PICTURE_TYPE_EMF, PICTURE_TYPE_JPEG, PICTURE_TYPE_PICT, PICTURE_TYPE_PNG, PICTURE_TYPE_WMF| Constructor and Description |
|---|
SXSSFWorkbook()
Construct a new workbook with default row window size
|
SXSSFWorkbook(int rowAccessWindowSize)
Construct an empty workbook and specify the window for row access.
|
SXSSFWorkbook(XSSFWorkbook workbook)
Construct a workbook from a template.
|
SXSSFWorkbook(XSSFWorkbook workbook,
int rowAccessWindowSize)
Constructs an workbook from an existing workbook.
|
SXSSFWorkbook(XSSFWorkbook workbook,
int rowAccessWindowSize,
boolean compressTmpFiles)
Constructs an workbook from an existing workbook.
|
SXSSFWorkbook(XSSFWorkbook workbook,
int rowAccessWindowSize,
boolean compressTmpFiles,
boolean useSharedStringsTable)
Constructs an workbook from an existing workbook.
|
| Modifier and Type | Method and Description |
|---|---|
int |
addOlePackage(byte[] oleData,
java.lang.String label,
java.lang.String fileName,
java.lang.String command)
Adds an OLE package manager object with the given content to the sheet
|
int |
addPicture(byte[] pictureData,
int format)
Adds a picture to the workbook.
|
void |
addToolPack(UDFFinder toolpack)
Register a new toolpack in this workbook.
|
Sheet |
cloneSheet(int sheetNum)
Not implemented for SXSSFWorkbook
Create a Sheet from an existing sheet in the Workbook.
|
void |
close()
Closes the underlying
XSSFWorkbook and OPCPackage
on which this Workbook is based, if any. |
protected org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream |
createArchiveOutputStream(java.io.OutputStream out) |
CellStyle |
createCellStyle()
Create a new Cell style and add it to the workbook's style table
|
DataFormat |
createDataFormat()
Returns the instance of DataFormat for this workbook.
|
EvaluationWorkbook |
createEvaluationWorkbook() |
Font |
createFont()
Create a new Font and add it to the workbook's font table
|
Name |
createName()
Creates a new (uninitialised) defined name in this workbook
|
SXSSFSheet |
createSheet()
Create a Sheet for this Workbook, adds it to the sheets and returns
the high level representation.
|
SXSSFSheet |
createSheet(java.lang.String sheetname)
Create a Sheet for this Workbook, adds it to the sheets and returns
the high level representation.
|
protected SheetDataWriter |
createSheetDataWriter() |
protected SXSSFWorkbook.ISheetInjector |
createSheetInjector(SXSSFSheet sxSheet) |
boolean |
dispose()
Dispose of temporary files backing this workbook on disk.
|
Font |
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
|
protected void |
flushSheets() |
int |
getActiveSheetIndex()
Convenience method to get the active sheet.
|
java.util.List<? extends Name> |
getAllNames()
Returns all defined names
|
java.util.List<? extends PictureData> |
getAllPictures()
Gets all pictures from the Workbook.
|
CellReferenceType |
getCellReferenceType() |
CellStyle |
getCellStyleAt(int idx)
Get the cell style object at the given index
|
CreationHelper |
getCreationHelper()
Returns an object that handles instantiating concrete
classes of the various instances one needs for HSSF, XSSF
and SXSSF.
|
int |
getFirstVisibleTab()
Gets the first tab that is displayed in the list of tabs in excel.
|
Font |
getFontAt(int idx)
Get the font at the given index number
|
boolean |
getForceFormulaRecalculation()
Whether Excel will be asked to recalculate all formulas when the workbook is opened.
|
Row.MissingCellPolicy |
getMissingCellPolicy()
Retrieves the current policy on what to do when
getting missing or blank cells from a row.
|
Name |
getName(java.lang.String name) |
java.util.List<? extends Name> |
getNames(java.lang.String name)
Returns all defined names with the given name.
|
int |
getNumberOfFonts()
Get the number of fonts in the font table
|
int |
getNumberOfFontsAsInt()
Deprecated.
|
int |
getNumberOfNames() |
int |
getNumberOfSheets()
Get the number of spreadsheets in the workbook
|
int |
getNumCellStyles()
Get the number of styles the workbook contains
|
java.lang.String |
getPrintArea(int sheetIndex)
Retrieves the reference for the printarea of the specified sheet,
the sheet name is appended to the reference even if it was not specified.
|
int |
getRandomAccessWindowSize()
See the constructors for a more detailed description of the sliding window of rows.
|
protected SharedStringsTable |
getSharedStringSource() |
SXSSFSheet |
getSheet(java.lang.String name)
Get sheet with the given name
|
SXSSFSheet |
getSheetAt(int index)
Get the Sheet object at the given index.
|
protected XSSFSheet |
getSheetFromZipEntryName(java.lang.String sheetRef) |
int |
getSheetIndex(Sheet sheet)
Returns the index of the given sheet
|
int |
getSheetIndex(java.lang.String name)
Returns the index of the sheet by his name
|
java.lang.String |
getSheetName(int sheet)
Set the sheet name
|
SheetVisibility |
getSheetVisibility(int sheetIx)
Get the visibility (visible, hidden, very hidden) of a sheet in this workbook
|
SpreadsheetVersion |
getSpreadsheetVersion()
Returns the spreadsheet version (EXCLE2007) of this workbook
|
XSSFWorkbook |
getXSSFWorkbook() |
protected void |
injectData(ZipEntrySource zipEntrySource,
java.io.OutputStream out) |
boolean |
isCompressTempFiles()
Get whether temp files should be compressed.
|
protected boolean |
isDate1904() |
boolean |
isHidden() |
boolean |
isSheetHidden(int sheetIx)
Check whether a sheet is hidden.
|
boolean |
isSheetVeryHidden(int sheetIx)
Check whether a sheet is very hidden.
|
int |
linkExternalWorkbook(java.lang.String name,
Workbook workbook)
Not implemented for SXSSFWorkbook
Adds the LinkTable records required to allow formulas referencing
the specified external workbook to be added to this one.
|
void |
removeName(Name name)
Remove the given defined name
|
void |
removePrintArea(int sheetIndex)
Delete the printarea for the sheet specified
|
void |
removeSheetAt(int index)
Removes sheet at the given index
|
void |
setActiveSheet(int sheetIndex)
Convenience method to set the active sheet.
|
void |
setCellReferenceType(CellReferenceType cellReferenceType) |
void |
setCompressTempFiles(boolean compress)
Set whether temp files should be compressed.
|
void |
setFirstVisibleTab(int sheetIndex)
Sets the first tab that is displayed in the list of tabs in excel.
|
void |
setForceFormulaRecalculation(boolean value)
Whether the application shall perform a full recalculation when the workbook is opened.
|
void |
setHidden(boolean hiddenFlag) |
void |
setMissingCellPolicy(Row.MissingCellPolicy missingCellPolicy)
Sets the policy on what to do when
getting missing or blank cells from a row.
|
void |
setPrintArea(int sheetIndex,
int startColumn,
int endColumn,
int startRow,
int endRow)
For the Convenience of Java Programmers maintaining pointers.
|
void |
setPrintArea(int sheetIndex,
java.lang.String reference)
Sets the printarea for the sheet provided
|
protected void |
setRandomAccessWindowSize(int rowAccessWindowSize) |
void |
setSelectedTab(int index)
Sets the tab whose data is actually seen when the sheet is opened.
|
void |
setSheetHidden(int sheetIx,
boolean hidden)
Hide or unhide a sheet.
|
void |
setSheetName(int sheet,
java.lang.String name)
Set the sheet name.
|
void |
setSheetOrder(java.lang.String sheetname,
int pos)
Sets the order of appearance for a given sheet.
|
void |
setSheetVisibility(int sheetIx,
SheetVisibility visibility)
Hide or unhide a sheet.
|
void |
setShouldCalculateSheetDimensions(boolean shouldCalculateSheetDimensions) |
void |
setZip64Mode(org.apache.commons.compress.archivers.zip.Zip64Mode zip64Mode)
Sets the Zip64 Mode
|
java.util.Iterator<Sheet> |
sheetIterator()
Returns an iterator of the sheets in the workbook
in sheet order.
|
boolean |
shouldCalculateSheetDimensions() |
java.util.Spliterator<Sheet> |
spliterator()
Returns a spliterator of the sheets in the workbook
in sheet order.
|
void |
write(java.io.OutputStream stream)
Write out this workbook to an OutputStream.
|
void |
writeAvoidingTempFiles(java.io.OutputStream stream)
Write out this workbook to an OutputStream.
|
public static final int DEFAULT_WINDOW_SIZE
SXSSFSheet.getRow(int).
When a new node is created via SXSSFSheet.createRow(int) and the total number
of unflushed records would exceed the specified value, then the
row with the lowest index value is flushed and cannot be accessed
via SXSSFSheet.getRow(int) anymore.protected final XSSFWorkbook _wb
protected final SharedStringsTable _sharedStringSource
protected org.apache.commons.compress.archivers.zip.Zip64Mode zip64Mode
public SXSSFWorkbook()
public SXSSFWorkbook(XSSFWorkbook workbook)
Construct a workbook from a template.
There are three use-cases to use SXSSFWorkbook(XSSFWorkbook) :max(rownum) in the template sheet.
SXSSFSheet.getRow(int) and
SXSSFRow.getCell(int) return null.
workbook - the template workbookpublic SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize)
When a new node is created via SXSSFSheet.createRow(int) and the total number
of unflushed records would exceed the specified value, then the
row with the lowest index value is flushed and cannot be accessed
via SXSSFSheet.getRow(int) anymore.
A value of -1 indicates unlimited access. In this case all
records that have not been flushed by a call to flush() are available
for random access.
A value of 0 is not allowed because it would flush any newly created row
without having a chance to specify any cells.
rowAccessWindowSize - the number of rows that are kept in memory until flushed out, see above.public SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize, boolean compressTmpFiles)
When a new node is created via SXSSFSheet.createRow(int) and the total number
of unflushed records would exceed the specified value, then the
row with the lowest index value is flushed and cannot be accessed
via SXSSFSheet.getRow(int) anymore.
A value of -1 indicates unlimited access. In this case all
records that have not been flushed by a call to flush() are available
for random access.
A value of 0 is not allowed because it would flush any newly created row
without having a chance to specify any cells.
rowAccessWindowSize - the number of rows that are kept in memory until flushed out, see above.compressTmpFiles - whether to use gzip compression for temporary filespublic SXSSFWorkbook(XSSFWorkbook workbook, int rowAccessWindowSize, boolean compressTmpFiles, boolean useSharedStringsTable)
When a new node is created via SXSSFSheet.createRow(int) and the total number
of unflushed records would exceed the specified value, then the
row with the lowest index value is flushed and cannot be accessed
via SXSSFSheet.getRow(int) anymore.
A value of -1 indicates unlimited access. In this case all
records that have not been flushed by a call to flush() are available
for random access.
A value of 0 is not allowed because it would flush any newly created row
without having a chance to specify any cells.
workbook - the template workbookrowAccessWindowSize - the number of rows that are kept in memory until flushed out, see above.compressTmpFiles - whether to use gzip compression for temporary filesuseSharedStringsTable - whether to use a shared strings tablepublic SXSSFWorkbook(int rowAccessWindowSize)
When a new node is created via SXSSFSheet.createRow(int) and the total number
of unflushed records would exceed the specified value, then the
row with the lowest index value is flushed and cannot be accessed
via SXSSFSheet.getRow(int) anymore.
A value of -1 indicates unlimited access. In this case all
records that have not been flushed by a call to flush() are available
for random access.
A value of 0 is not allowed because it would flush any newly created row
without having a chance to specify any cells.
rowAccessWindowSize - the number of rows that are kept in memory until flushed out, see above.public int getRandomAccessWindowSize()
protected void setRandomAccessWindowSize(int rowAccessWindowSize)
@Beta public void setZip64Mode(org.apache.commons.compress.archivers.zip.Zip64Mode zip64Mode)
zip64Mode - Zip64Modepublic boolean isCompressTempFiles()
public void setCompressTempFiles(boolean compress)
SXSSF writes sheet data in temporary files (a temp file per-sheet)
and the size of these temp files can grow to to a very large size,
e.g. for a 20 MB csv data the size of the temp xml file become few GB large.
If the "compress" flag is set to true then the temporary XML is gzipped.
Please note the "compress" option may cause performance penalty.
Setting this option only affects compression for subsequent createSheet()
calls.
compress - whether to compress temp filespublic void setShouldCalculateSheetDimensions(boolean shouldCalculateSheetDimensions)
shouldCalculateSheetDimensions - defaults to true, set to false if
the calculated dimensions are causing troublepublic boolean shouldCalculateSheetDimensions()
true, set to false if
the calculated dimensions are causing trouble@Internal protected SharedStringsTable getSharedStringSource()
protected SheetDataWriter createSheetDataWriter() throws java.io.IOException
java.io.IOExceptionprotected XSSFSheet getSheetFromZipEntryName(java.lang.String sheetRef)
protected void injectData(ZipEntrySource zipEntrySource, java.io.OutputStream out) throws java.io.IOException
java.io.IOExceptionprotected org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream createArchiveOutputStream(java.io.OutputStream out)
protected SXSSFWorkbook.ISheetInjector createSheetInjector(SXSSFSheet sxSheet) throws java.io.IOException
java.io.IOExceptionpublic XSSFWorkbook getXSSFWorkbook()
public int getActiveSheetIndex()
getActiveSheetIndex in interface Workbookpublic void setActiveSheet(int sheetIndex)
setActiveSheet in interface WorkbooksheetIndex - index of the active sheet (0-based)public int getFirstVisibleTab()
getFirstVisibleTab in interface Workbookpublic void setFirstVisibleTab(int sheetIndex)
setFirstVisibleTab in interface WorkbooksheetIndex - the first tab that to display in the list of tabs (0-based)public void setSheetOrder(java.lang.String sheetname,
int pos)
setSheetOrder in interface Workbooksheetname - the name of the sheet to reorderpos - the position that we want to insert the sheet into (0 based)public void setSelectedTab(int index)
setSelectedTab in interface Workbookindex - the index of the sheet to select (0 based)Sheet.setSelected(boolean)public void setSheetName(int sheet,
java.lang.String name)
setSheetName in interface Workbooksheet - number (0 based)java.lang.IllegalArgumentException - if the name is greater than 31 chars or contains /\?*[]Workbook.createSheet(String),
WorkbookUtil.createSafeSheetName(String nameProposal)public java.lang.String getSheetName(int sheet)
getSheetName in interface Workbooksheet - sheet number (0 based)public int getSheetIndex(java.lang.String name)
getSheetIndex in interface Workbookname - the sheet namepublic int getSheetIndex(Sheet sheet)
getSheetIndex in interface Workbooksheet - the sheet to look uppublic SXSSFSheet createSheet()
createSheet in interface Workbookpublic SXSSFSheet createSheet(java.lang.String sheetname)
createSheet in interface Workbooksheetname - sheetname to set for the sheet.java.lang.IllegalArgumentException - if the name is greater than 31 chars or contains /\?*[]WorkbookUtil.createSafeSheetName(String nameProposal)@NotImplemented public Sheet cloneSheet(int sheetNum)
cloneSheet in interface Workbookpublic int getNumberOfSheets()
getNumberOfSheets in interface Workbookpublic java.util.Iterator<Sheet> sheetIterator()
sheetIterator in interface Workbookpublic java.util.Spliterator<Sheet> spliterator()
spliterator in interface java.lang.Iterable<Sheet>spliterator in interface Workbookpublic SXSSFSheet getSheetAt(int index)
getSheetAt in interface Workbookindex - of the sheet number (0-based physical and logical)public SXSSFSheet getSheet(java.lang.String name)
public void removeSheetAt(int index)
removeSheetAt in interface Workbookindex - of the sheet to remove (0-based)public Font createFont()
createFont in interface Workbookpublic Font findFont(boolean bold, short color, short fontHeight, java.lang.String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
public int getNumberOfFonts()
WorkbookgetNumberOfFonts in interface Workbook@Deprecated @Removal(version="6.0.0") public int getNumberOfFontsAsInt()
WorkbookgetNumberOfFontsAsInt in interface Workbookpublic Font getFontAt(int idx)
Workbookpublic CellStyle createCellStyle()
createCellStyle in interface Workbookpublic int getNumCellStyles()
getNumCellStyles in interface Workbookpublic CellStyle getCellStyleAt(int idx)
getCellStyleAt in interface Workbookidx - index within the set of styles (0-based)public void close()
throws java.io.IOException
XSSFWorkbook and OPCPackage
on which this Workbook is based, if any.
Once this has been called, no further operations, updates or reads should be performed on the Workbook.
public void write(java.io.OutputStream stream)
throws java.io.IOException
@Beta public void writeAvoidingTempFiles(java.io.OutputStream stream) throws java.io.IOException
write(java.io.OutputStream) creates but will use more memory as a result. Other SXSSF code can create temp files,
so using this does not guarantee that there will be no temp file usage.stream - - the java OutputStream you wish to write tojava.io.IOException - if anything can't be written.protected void flushSheets()
throws java.io.IOException
java.io.IOExceptionpublic boolean dispose()
public int getNumberOfNames()
getNumberOfNames in interface Workbookpublic Name getName(java.lang.String name)
public java.util.List<? extends Name> getNames(java.lang.String name)
public java.util.List<? extends Name> getAllNames()
getAllNames in interface Workbookpublic Name createName()
createName in interface Workbookpublic void removeName(Name name)
removeName in interface Workbookname - the name to removepublic void setPrintArea(int sheetIndex,
java.lang.String reference)
i.e. Reference = $A$1:$B$2
setPrintArea in interface WorkbooksheetIndex - Zero-based sheet index (0 Represents the first sheet to keep consistent with java)reference - Valid name Reference for the Print Areapublic void setPrintArea(int sheetIndex,
int startColumn,
int endColumn,
int startRow,
int endRow)
setPrintArea in interface WorkbooksheetIndex - 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 printareasetPrintArea(int, String)public java.lang.String getPrintArea(int sheetIndex)
getPrintArea in interface WorkbooksheetIndex - Zero-based sheet index (0 Represents the first sheet to keep consistent with java)public void removePrintArea(int sheetIndex)
removePrintArea in interface WorkbooksheetIndex - Zero-based sheet index (0 = First Sheet)public Row.MissingCellPolicy getMissingCellPolicy()
The default is to return blank and null cells.
Row.MissingCellPolicy
getMissingCellPolicy in interface Workbookpublic void setMissingCellPolicy(Row.MissingCellPolicy missingCellPolicy)
Row.getCell(int). See
Row.MissingCellPolicysetMissingCellPolicy in interface Workbookpublic DataFormat createDataFormat()
createDataFormat in interface Workbookpublic int addPicture(byte[] pictureData,
int format)
addPicture in interface WorkbookpictureData - The bytes of the pictureformat - The format of the picture.Workbook.PICTURE_TYPE_EMF,
Workbook.PICTURE_TYPE_WMF,
Workbook.PICTURE_TYPE_PICT,
Workbook.PICTURE_TYPE_JPEG,
Workbook.PICTURE_TYPE_PNG,
Workbook.PICTURE_TYPE_DIBpublic java.util.List<? extends PictureData> getAllPictures()
getAllPictures in interface WorkbookPictureData objects.)public CreationHelper getCreationHelper()
getCreationHelper in interface Workbookprotected boolean isDate1904()
@NotImplemented(value="XSSFWorkbook#isHidden is not implemented") public boolean isHidden()
@NotImplemented(value="XSSFWorkbook#setHidden is not implemented") public void setHidden(boolean hiddenFlag)
public boolean isSheetHidden(int sheetIx)
Workbook
Note that a sheet could instead be set to be very hidden, which is different
(Workbook.isSheetVeryHidden(int))
isSheetHidden in interface WorkbooksheetIx - Numbertrue if sheet is hiddenWorkbook.getSheetVisibility(int)public boolean isSheetVeryHidden(int sheetIx)
Workbook
This is different from the normal hidden status
(Workbook.isSheetHidden(int))
isSheetVeryHidden in interface WorkbooksheetIx - sheet index to checktrue if sheet is very hiddenWorkbook.getSheetVisibility(int)public SheetVisibility getSheetVisibility(int sheetIx)
WorkbookgetSheetVisibility in interface WorkbooksheetIx - the index of the sheetpublic void setSheetHidden(int sheetIx,
boolean hidden)
WorkbooksetSheetHidden in interface WorkbooksheetIx - the sheet index (0-based)hidden - True to mark the sheet as hidden, false otherwiseWorkbook.setSheetVisibility(int, SheetVisibility)public void setSheetVisibility(int sheetIx,
SheetVisibility visibility)
WorkbooksetSheetVisibility in interface WorkbooksheetIx - the sheet index (0-based)visibility - the sheet visibility to set@NotImplemented public int linkExternalWorkbook(java.lang.String name, Workbook workbook)
linkExternalWorkbook in interface Workbookname - The name the workbook will be referenced as in formulasworkbook - The open workbook to fetch the link required information fromjava.lang.RuntimeException - stating that this method is not implemented yet.public void addToolPack(UDFFinder toolpack)
addToolPack in interface Workbooktoolpack - the toolpack to registerpublic void setForceFormulaRecalculation(boolean value)
Typically you want to force formula recalculation when you modify cell formulas or values of a workbook previously created by Excel. When set to 0, this flag will tell Excel that it needs to recalculate all formulas in the workbook the next time the file is opened.
setForceFormulaRecalculation in interface Workbookvalue - true if the application will perform a full recalculation of
workbook values when the workbook is openedpublic boolean getForceFormulaRecalculation()
getForceFormulaRecalculation in interface Workbookpublic SpreadsheetVersion getSpreadsheetVersion()
getSpreadsheetVersion in interface Workbookpublic int addOlePackage(byte[] oleData,
java.lang.String label,
java.lang.String fileName,
java.lang.String command)
throws java.io.IOException
WorkbookaddOlePackage in interface WorkbookoleData - the payloadlabel - the label of the payloadfileName - the original filenamecommand - the command to open the payloadjava.io.IOException - if the object can't be embeddedpublic EvaluationWorkbook createEvaluationWorkbook()
createEvaluationWorkbook in interface Workbookpublic CellReferenceType getCellReferenceType()
getCellReferenceType in interface Workbookpublic void setCellReferenceType(CellReferenceType cellReferenceType)
setCellReferenceType in interface WorkbookcellReferenceType - the type of cell references usedCopyright 2022 The Apache Software Foundation or its licensors, as applicable.