public interface Workbook
Modifier and Type | Field and Description |
---|---|
static int |
PICTURE_TYPE_DIB
Device independent bitmap
|
static int |
PICTURE_TYPE_EMF
Extended windows meta file
|
static int |
PICTURE_TYPE_JPEG
JPEG format
|
static int |
PICTURE_TYPE_PICT
Mac PICT format
|
static int |
PICTURE_TYPE_PNG
PNG format
|
static int |
PICTURE_TYPE_WMF
Windows Meta File
|
static int |
SHEET_STATE_HIDDEN
Indicates the book window is hidden, but can be shown by the user via the user interface.
|
static int |
SHEET_STATE_VERY_HIDDEN
Indicates the sheet is hidden and cannot be shown in the user interface (UI).
|
static int |
SHEET_STATE_VISIBLE
Indicates the sheet is visible.
|
Modifier and Type | Method and Description |
---|---|
void |
addDefaultCellStyle(CellStyle cellStyle) |
int |
addDxfCellStyle(DxfCellStyle cellStyle) |
void |
addNamedStyle(NamedStyle namedStyle) |
int |
addPicture(byte[] pictureData,
int format)
Adds a picture to the workbook.
|
void |
addTableStyle(TableStyle tbStyle) |
void |
addToolPack(UDFFinder toopack)
Register a new toolpack in this workbook.
|
void |
clearDefaultCellStyles() |
void |
clearDxfCellStyles() |
void |
clearNamedStyles() |
void |
clearTableStyles() |
Sheet |
cloneSheet(int sheetNum)
Create an Sheet from an existing sheet in the Workbook.
|
CellStyle |
createCellStyle()
Create a new Cell style and add it to the workbook's style table
|
DataFormat |
createDataFormat()
Returns the instance of DataFormat for this workbook.
|
DxfCellStyle |
createDxfCellStyle() |
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
|
NamedStyle |
createNamedStyle(String name,
boolean custom,
int builtinId,
int index) |
PivotCache |
createPivotCache(AreaReference sourceRef) |
Sheet |
createSheet()
Create a Sheet for this Workbook, adds it to the sheets and returns
the high level representation.
|
Sheet |
createSheet(String sheetname)
Create a new sheet for this Workbook and return the high level representation.
|
TableStyle |
createTableStyle(String name) |
Font |
findFont(short boldWeight,
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
|
int |
getActiveSheetIndex()
Convenience method to get the active sheet.
|
List<? extends PictureData> |
getAllPictures()
Gets all pictures from the Workbook.
|
CellStyle |
getCellStyleAt(int idx)
Get the cell style object at the given index
Note since 3.9.9 we have changed the return value type from short to int because the limit of
distinct cell style in Excel 2007's is 64000 while that of Excel 97-2003 is 4000
only; have to extend it to accommodate the capacity.
|
CreationHelper |
getCreationHelper()
Returns an object that handles instantiating concrete
classes of the various instances one needs for HSSF and XSSF.
|
List<CellStyle> |
getDefaultCellStyles() |
String |
getDefaultPivotStyle() |
String |
getDefaultTableStyle() |
List<DxfCellStyle> |
getDxfCellStyles() |
int |
getDxfIndex(DxfCellStyle dxfCellStyle) |
int |
getFirstVisibleTab()
Gets the first tab that is displayed in the list of tabs in excel.
|
Font |
getFontAt(short idx)
Get the font at the given index number
|
boolean |
getForceFormulaRecalculation()
Whether Excel will be asked to recalculate all formulas when the workbook is opened.
|
Row.MissingCellPolicy |
getMissingCellPolicy()
Retrieves the current policy on what to do when
getting missing or blank cells from a row.
|
Name |
getName(String name) |
Name |
getNameAt(int nameIndex) |
List<NamedStyle> |
getNamedStyles() |
int |
getNameIndex(String name)
Gets the defined name index by name
Note: Excel defined names are case-insensitive and this method performs a case-insensitive search. |
short |
getNumberOfFonts()
Get the number of fonts in the font table
|
int |
getNumberOfNames() |
int |
getNumberOfSheets()
Get the number of spreadsheets in the workbook
|
short |
getNumCellStyles()
Get the number of styles the workbook contains
|
List<PivotCache> |
getPivotCaches() |
String |
getPrintArea(int sheetIndex)
Retrieves the reference for the printarea of the specified sheet,
the sheet name is appended to the reference even if it was not specified.
|
Sheet |
getSheet(String name)
Get sheet with the given name
|
Sheet |
getSheetAt(int index)
Get the Sheet object at the given index.
|
int |
getSheetIndex(Sheet sheet)
Returns the index of the given sheet
|
int |
getSheetIndex(String name)
Returns the index of the sheet by his name
|
String |
getSheetName(int sheet)
Get the sheet name
|
List<TableStyle> |
getTableStyles() |
boolean |
isHidden() |
boolean |
isSheetHidden(int sheetIx)
Check whether a sheet is hidden.
|
boolean |
isSheetVeryHidden(int sheetIx)
Check whether a sheet is very hidden.
|
void |
removeName(int index)
Remove the defined name at the specified index
|
void |
removeName(String name)
Remove a defined name by name
|
void |
removePrintArea(int sheetIndex)
Delete the printarea for the sheet specified
|
void |
removeSheetAt(int index)
Removes sheet at the given index
|
void |
setActiveSheet(int sheetIndex)
Convenience method to set the active sheet.
|
void |
setDefaultPivotStyle(String defaultPivotStyle) |
void |
setDefaultTableStyle(String defaultTableStyle) |
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,
String reference)
Sets the printarea for the sheet provided
|
void |
setRepeatingRowsAndColumns(int sheetIndex,
int startColumn,
int endColumn,
int startRow,
int endRow)
|
void |
setSelectedTab(int index)
Sets the tab whose data is actually seen when the sheet is opened.
|
void |
setSheetHidden(int sheetIx,
boolean hidden)
Hide or unhide a sheet
|
void |
setSheetHidden(int sheetIx,
int hidden)
Hide or unhide a sheet.
|
void |
setSheetName(int sheet,
String name)
Set the sheet name.
|
void |
setSheetOrder(String sheetname,
int pos)
Sets the order of appearance for a given sheet.
|
void |
write(OutputStream stream)
Write out this workbook to an Outputstream.
|
static final int PICTURE_TYPE_EMF
static final int PICTURE_TYPE_WMF
static final int PICTURE_TYPE_PICT
static final int PICTURE_TYPE_JPEG
static final int PICTURE_TYPE_PNG
static final int PICTURE_TYPE_DIB
static final int SHEET_STATE_VISIBLE
setSheetHidden(int, int)
,
Constant Field Valuesstatic final int SHEET_STATE_HIDDEN
setSheetHidden(int, int)
,
Constant Field Valuesstatic final int SHEET_STATE_VERY_HIDDEN
In Excel this state is only available programmatically in VBA:
ThisWorkbook.Sheets("MySheetName").Visible = xlSheetVeryHidden
setSheetHidden(int, int)
,
Constant Field Valuesint getActiveSheetIndex()
void setActiveSheet(int sheetIndex)
sheetIndex
- index of the active sheet (0-based)int getFirstVisibleTab()
void setFirstVisibleTab(int sheetIndex)
sheetIndex
- the first tab that to display in the list of tabs (0-based)void setSheetOrder(String sheetname, int pos)
sheetname
- the name of the sheet to reorderpos
- the position that we want to insert the sheet into (0 based)void setSelectedTab(int index)
index
- the index of the sheet to select (0 based)Sheet.setSelected(boolean)
void setSheetName(int sheet, String name)
See WorkbookUtil.createSafeSheetName(String nameProposal)
for a safe way to create valid names
sheet
- number (0 based)IllegalArgumentException
- if the name is null or invalid
or workbook already contains a sheet with this namecreateSheet(String)
,
WorkbookUtil.createSafeSheetName(String nameProposal)
String getSheetName(int sheet)
sheet
- sheet number (0 based)int getSheetIndex(String name)
name
- the sheet nameint getSheetIndex(Sheet sheet)
sheet
- the sheet to look upSheet createSheet()
Sheet createSheet(String sheetname)
Note that Excel allows sheet names up to 31 chars in length but other applications (such as OpenOffice) allow more. Some versions of Excel crash with names longer than 31 chars, others - truncate such names to 31 character.
POI's SpreadsheetAPI silently truncates the input argument to 31 characters. Example:
Sheet sheet = workbook.createSheet("My very long sheet name which is longer than 31 chars"); // will be truncated
assert 31 == sheet.getSheetName().length();
assert "My very long sheet name which i" == sheet.getSheetName();
Except the 31-character constraint, Excel applies some other rules:
Sheet name MUST be unique in the workbook and MUST NOT contain the any of the following characters:
See WorkbookUtil.createSafeSheetName(String nameProposal)
for a safe way to create valid names
sheetname
- sheetname to set for the sheet.IllegalArgumentException
- if the name is null or invalid
or workbook already contains a sheet with this nameWorkbookUtil.createSafeSheetName(String nameProposal)
Sheet cloneSheet(int sheetNum)
int getNumberOfSheets()
Sheet getSheetAt(int index)
index
- of the sheet number (0-based physical & logical)Sheet getSheet(String name)
name
- of the sheetnull
if it does not existvoid removeSheetAt(int index)
index
- of the sheet to remove (0-based)void setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)
Sheet.setRepeatingRows(CellRangeAddress)
or Sheet.setRepeatingColumns(CellRangeAddress)
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);
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.Font createFont()
Font findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
null
short getNumberOfFonts()
Font getFontAt(short idx)
idx
- index number (0-based)CellStyle createCellStyle()
short getNumCellStyles()
CellStyle getCellStyleAt(int idx)
idx
- index within the set of styles (0-based)void write(OutputStream stream) throws IOException
stream
- - the java OutputStream you wish to write toIOException
- if anything can't be written.int getNumberOfNames()
Name getName(String name)
name
- the name of the defined namenull
if not found.Name getNameAt(int nameIndex)
nameIndex
- position of the named range (0-based)IllegalArgumentException
- if the supplied index is invalidName createName()
int getNameIndex(String name)
name
- the name of the defined namevoid removeName(int index)
index
- named range index (0 based)void removeName(String name)
name
- the name of the defined namevoid setPrintArea(int sheetIndex, String reference)
i.e. Reference = $A$1:$B$2
sheetIndex
- Zero-based sheet index (0 Represents the first sheet to keep consistent with java)reference
- Valid name Reference for the Print Areavoid setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)
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 printareasetPrintArea(int, String)
String getPrintArea(int sheetIndex)
sheetIndex
- Zero-based sheet index (0 Represents the first sheet to keep consistent with java)void removePrintArea(int sheetIndex)
sheetIndex
- Zero-based sheet index (0 = First Sheet)Row.MissingCellPolicy getMissingCellPolicy()
The default is to return blank and null cells.
Row.MissingCellPolicy
void setMissingCellPolicy(Row.MissingCellPolicy missingCellPolicy)
Row.getCell(int)
}. See
Row.MissingCellPolicy
DataFormat createDataFormat()
int addPicture(byte[] pictureData, int format)
pictureData
- The bytes of the pictureformat
- The format of the picture.PICTURE_TYPE_EMF
,
PICTURE_TYPE_WMF
,
PICTURE_TYPE_PICT
,
PICTURE_TYPE_JPEG
,
PICTURE_TYPE_PNG
,
PICTURE_TYPE_DIB
List<? extends PictureData> getAllPictures()
PictureData
objects.)CreationHelper getCreationHelper()
boolean isHidden()
false
if this workbook is not visible in the GUIvoid setHidden(boolean hiddenFlag)
hiddenFlag
- pass false
to make the workbook visible in the GUIboolean isSheetHidden(int sheetIx)
Note that a sheet could instead be set to be very hidden, which is different
(isSheetVeryHidden(int)
)
sheetIx
- Numbertrue
if sheet is hiddenboolean isSheetVeryHidden(int sheetIx)
This is different from the normal hidden status
(isSheetHidden(int)
)
sheetIx
- sheet index to checktrue
if sheet is very hiddenvoid setSheetHidden(int sheetIx, boolean hidden)
sheetIx
- the sheet index (0-based)hidden
- True to mark the sheet as hidden, false otherwisevoid setSheetHidden(int sheetIx, int hidden)
sheetIx
- the sheet index (0-based)hidden
- one of the following Workbook
constants:
Workbook.SHEET_STATE_VISIBLE
,
Workbook.SHEET_STATE_HIDDEN
, or
Workbook.SHEET_STATE_VERY_HIDDEN
.IllegalArgumentException
- if the supplied sheet index or state is invalidvoid addToolPack(UDFFinder toopack)
toopack
- the toolpack to registervoid 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 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.
value
- true if the application will perform a full recalculation of
workbook values when the workbook is openedboolean getForceFormulaRecalculation()
List<PivotCache> getPivotCaches()
PivotCache createPivotCache(AreaReference sourceRef)
void clearDefaultCellStyles()
void addDefaultCellStyle(CellStyle cellStyle)
void clearNamedStyles()
void addNamedStyle(NamedStyle namedStyle)
NamedStyle createNamedStyle(String name, boolean custom, int builtinId, int index)
List<NamedStyle> getNamedStyles()
void clearDxfCellStyles()
int addDxfCellStyle(DxfCellStyle cellStyle)
DxfCellStyle createDxfCellStyle()
List<DxfCellStyle> getDxfCellStyles()
void clearTableStyles()
List<TableStyle> getTableStyles()
String getDefaultPivotStyle()
String getDefaultTableStyle()
void setDefaultPivotStyle(String defaultPivotStyle)
void setDefaultTableStyle(String defaultTableStyle)
void addTableStyle(TableStyle tbStyle)
TableStyle createTableStyle(String name)
int getDxfIndex(DxfCellStyle dxfCellStyle)
Copyright © 2020. All rights reserved.