|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.poi.POIDocument
org.apache.poi.hssf.usermodel.HSSFWorkbook
public class HSSFWorkbook
High level representation of a 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.
Workbook
,
HSSFSheet
Field Summary | |
---|---|
protected java.util.List |
_sheets
this holds the HSSFSheet objects attached to this workbook |
static byte |
ENCODING_COMPRESSED_UNICODE
Deprecated. POI will now properly handle unicode strings without forceing an encoding |
static byte |
ENCODING_UTF_16
Deprecated. POI will now properly handle unicode strings without forceing an encoding |
static int |
INITIAL_CAPACITY
used for compile-time performance/memory optimization. |
static int |
PICTURE_TYPE_DIB
Device independant 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 |
Fields inherited from class org.apache.poi.POIDocument |
---|
directory, dsInf, filesystem, initialized, logger, sInf |
Constructor Summary | |
---|---|
|
HSSFWorkbook()
Creates new HSSFWorkbook from scratch (start here!) |
|
HSSFWorkbook(DirectoryNode directory,
POIFSFileSystem fs,
boolean preserveNodes)
given a POI POIFSFileSystem object, and a specific directory within it, read in its Workbook and populate the high and low level models. |
|
HSSFWorkbook(java.io.InputStream s)
|
|
HSSFWorkbook(java.io.InputStream s,
boolean preserveNodes)
Companion to HSSFWorkbook(POIFSFileSystem), this constructs the POI filesystem around your inputstream. |
|
HSSFWorkbook(POIFSFileSystem fs)
|
|
HSSFWorkbook(POIFSFileSystem fs,
boolean preserveNodes)
given a POI POIFSFileSystem object, read in its Workbook and populate the high and low level models. |
protected |
HSSFWorkbook(Workbook book)
|
Method Summary | |
---|---|
int |
addPicture(byte[] pictureData,
int format)
Adds a picture to the workbook. |
int |
addSSTString(java.lang.String string)
Deprecated. Do not call this method from your applications. Use the methods available in the HSSFRow to add string HSSFCells |
HSSFSheet |
cloneSheet(int sheetNum)
create an HSSFSheet from an existing sheet in the HSSFWorkbook. |
HSSFCellStyle |
createCellStyle()
create a new Cell style and add it to the workbook's style table |
HSSFDataFormat |
createDataFormat()
Returns the instance of HSSFDataFormat for this workbook. |
HSSFFont |
createFont()
create a new Font and add it to the workbook's font table |
HSSFName |
createName()
creates a new named range and add it to the model |
HSSFSheet |
createSheet()
create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns the high level representation. |
HSSFSheet |
createSheet(java.lang.String sheetname)
create an HSSFSheet for this HSSFWorkbook, adds it to the sheets and returns the high level representation. |
void |
dumpDrawingGroupRecords(boolean fat)
Spits out a list of all the drawing records in the workbook. |
HSSFFont |
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 |
int |
getActiveSheetIndex()
gets the tab whose data is actually seen when the sheet is opened. |
java.util.List |
getAllEmbeddedObjects()
Gets all embedded OLE2 objects from the Workbook. |
java.util.List |
getAllPictures()
Gets all pictures from the Workbook. |
boolean |
getBackupFlag()
determine whether the Excel GUI will backup the workbook when saving. |
byte[] |
getBytes()
Method getBytes - get the bytes of just the HSSF portions of the XLS file. |
HSSFCellStyle |
getCellStyleAt(short idx)
get the cell style object at the given index |
org.apache.poi.ss.usermodel.CreationHelper |
getCreationHelper()
|
HSSFPalette |
getCustomPalette()
|
short |
getDisplayedTab()
Deprecated. - Misleading name - use getFirstVisibleTab() |
int |
getExternalSheetIndex(int internalSheetIndex)
Returns the external sheet index of the sheet with the given internal index, creating one if needed. |
int |
getFirstVisibleTab()
sets the first tab that is displayed in the list of tabs in excel. |
HSSFFont |
getFontAt(short idx)
Get the font at the given index number |
org.apache.poi.ss.usermodel.Row.MissingCellPolicy |
getMissingCellPolicy()
Retrieves the current policy on what to do when getting missing or blank cells from a row. |
HSSFName |
getNameAt(int index)
gets the Named range |
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. |
java.lang.String |
getNameName(int index)
gets the named range name |
short |
getNumberOfFonts()
get the number of fonts in the font table |
int |
getNumberOfNames()
gets the total number of named ranges in the workboko |
int |
getNumberOfSheets()
get the number of spreadsheets in the workbook (this will be three after serialization) |
short |
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. |
short |
getSelectedTab()
Deprecated. - Misleading name - use getActiveSheetIndex() |
HSSFSheet |
getSheet(java.lang.String name)
Get sheet with the given name (case insensitive match) |
HSSFSheet |
getSheetAt(int index)
Get the HSSFSheet object at the given index. |
int |
getSheetIndex(org.apache.poi.ss.usermodel.Sheet sheet)
Returns the index of the given sheet |
int |
getSheetIndex(java.lang.String name)
Returns the index of the sheet by his name |
int |
getSheetIndexFromExternSheetIndex(int externSheetNumber)
|
java.lang.String |
getSheetName(int sheetIx)
get the sheet name |
SheetReferences |
getSheetReferences()
|
java.lang.String |
getSSTString(int index)
Deprecated. Do not call this method from your applications. Use the methods available in the HSSFRow to get string HSSFCells |
protected Workbook |
getWorkbook()
|
void |
insertChartRecord()
Test only. |
boolean |
isSheetHidden(int sheetIx)
check whether a sheet is hidden |
boolean |
isWriteProtected()
Is the workbook protected with a password (not encrypted)? |
void |
removeName(int index)
remove the named range by his index |
void |
removeName(java.lang.String name)
remove the named range by his name |
void |
removePrintArea(int sheetIndex)
Delete the printarea for the sheet specified |
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. |
java.lang.String |
resolveNameXText(int refIndex,
int definedNameIndex)
TODO - make this less cryptic / move elsewhere |
void |
setActiveSheet(int index)
Convenience method to set the active sheet. |
void |
setBackupFlag(boolean backupValue)
determine whether the Excel GUI will backup the workbook when saving. |
void |
setDisplayedTab(short index)
Deprecated. - Misleading name - use setFirstVisibleTab() |
void |
setFirstVisibleTab(int index)
sets the first tab that is displayed in the list of tabs in excel. |
void |
setMissingCellPolicy(org.apache.poi.ss.usermodel.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 |
void |
setRepeatingRowsAndColumns(int sheetIndex,
int startColumn,
int endColumn,
int startRow,
int endRow)
Sets the repeating rows and columns for a sheet (as found in File->PageSetup->Sheet). |
void |
setSelectedTab(int index)
Selects a single sheet. |
void |
setSelectedTab(short index)
Deprecated. use setSelectedTab(int) |
void |
setSelectedTabs(int[] indexes)
|
void |
setSheetHidden(int sheetIx,
boolean hidden)
Hide or unhide a sheet |
void |
setSheetName(int sheetIx,
java.lang.String name)
set the sheet name. |
void |
setSheetName(int sheetIx,
java.lang.String name,
short encoding)
Deprecated. 3-Jan-2006 POI now automatically detects unicode and sets the encoding appropriately. Simply use setSheetName(int sheet, String encoding) |
void |
setSheetOrder(java.lang.String sheetname,
int pos)
sets the order of appearance for a given sheet. |
void |
unwriteProtectWorkbook()
removes the write protect flag |
void |
write(java.io.OutputStream stream)
Method write - write out this workbook to an Outputstream. |
void |
writeProtectWorkbook(java.lang.String password,
java.lang.String username)
protect a workbook with a password (not encypted, just sets writeprotect flags and the password. |
Methods inherited from class org.apache.poi.POIDocument |
---|
copyNodes, getDocumentSummaryInformation, getPropertySet, getSummaryInformation, readProperties, writeProperties, writeProperties, writePropertySet |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int INITIAL_CAPACITY
protected java.util.List _sheets
public static final int PICTURE_TYPE_EMF
public static final int PICTURE_TYPE_WMF
public static final int PICTURE_TYPE_PICT
public static final int PICTURE_TYPE_JPEG
public static final int PICTURE_TYPE_PNG
public static final int PICTURE_TYPE_DIB
public static final byte ENCODING_COMPRESSED_UNICODE
public static final byte ENCODING_UTF_16
Constructor Detail |
---|
public HSSFWorkbook()
protected HSSFWorkbook(Workbook book)
public HSSFWorkbook(POIFSFileSystem fs) throws java.io.IOException
java.io.IOException
public HSSFWorkbook(POIFSFileSystem fs, boolean preserveNodes) throws java.io.IOException
fs
- the POI filesystem that contains the Workbook stream.preserveNodes
- whether to preseve other nodes, such as
macros. This takes more memory, so only say yes if you
need to. If set, will store all of the POIFSFileSystem
in memory
java.io.IOException
- if the stream cannot be readPOIFSFileSystem
public HSSFWorkbook(DirectoryNode directory, POIFSFileSystem fs, boolean preserveNodes) throws java.io.IOException
directory
- the POI filesystem directory to process fromfs
- the POI filesystem that contains the Workbook stream.preserveNodes
- whether to preseve other nodes, such as
macros. This takes more memory, so only say yes if you
need to. If set, will store all of the POIFSFileSystem
in memory
java.io.IOException
- if the stream cannot be readPOIFSFileSystem
public HSSFWorkbook(java.io.InputStream s) throws java.io.IOException
java.io.IOException
public HSSFWorkbook(java.io.InputStream s, boolean preserveNodes) throws java.io.IOException
s
- the POI filesystem that contains the Workbook stream.preserveNodes
- whether to preseve other nodes, such as
macros. This takes more memory, so only say yes if you
need to.
java.io.IOException
- if the stream cannot be readPOIFSFileSystem
,
HSSFWorkbook(POIFSFileSystem)
Method Detail |
---|
public org.apache.poi.ss.usermodel.Row.MissingCellPolicy getMissingCellPolicy()
Row.MissingCellPolicy
getMissingCellPolicy
in interface org.apache.poi.ss.usermodel.Workbook
public void setMissingCellPolicy(org.apache.poi.ss.usermodel.Row.MissingCellPolicy missingCellPolicy)
HSSFRow.getCell()
. See
Row.MissingCellPolicy
setMissingCellPolicy
in interface org.apache.poi.ss.usermodel.Workbook
public void setSheetOrder(java.lang.String sheetname, int pos)
setSheetOrder
in interface org.apache.poi.ss.usermodel.Workbook
sheetname
- the name of the sheet to reorderpos
- the position that we want to insert the sheet into (0 based)public void setSelectedTab(int index)
public void setSelectedTab(short index)
setSelectedTab
in interface org.apache.poi.ss.usermodel.Workbook
public void setSelectedTabs(int[] indexes)
public void setActiveSheet(int index)
public int getActiveSheetIndex()
HSSFSheet.setSelected(boolean)
public short getSelectedTab()
getSelectedTab
in interface org.apache.poi.ss.usermodel.Workbook
public void setFirstVisibleTab(int index)
index
- public void setDisplayedTab(short index)
setDisplayedTab
in interface org.apache.poi.ss.usermodel.Workbook
public int getFirstVisibleTab()
public short getDisplayedTab()
getDisplayedTab
in interface org.apache.poi.ss.usermodel.Workbook
public void setSheetName(int sheetIx, java.lang.String name)
setSheetName
in interface org.apache.poi.ss.usermodel.Workbook
sheetIx
- number (0 based)public void setSheetName(int sheetIx, java.lang.String name, short encoding)
setSheetName
in interface org.apache.poi.ss.usermodel.Workbook
sheet
- number (0 based)
java.lang.IllegalArgumentException
- if the name is greater than 31 chars
or contains /\?*[]public java.lang.String getSheetName(int sheetIx)
getSheetName
in interface org.apache.poi.ss.usermodel.Workbook
sheetIx
- Number
public boolean isSheetHidden(int sheetIx)
sheetIx
- Number
public void setSheetHidden(int sheetIx, boolean hidden)
sheetIx
- The sheet indexhidden
- True to mark the sheet as hidden, false otherwisepublic int getSheetIndex(java.lang.String name)
getSheetIndex
in interface org.apache.poi.ss.usermodel.Workbook
name
- the sheet name
public int getSheetIndex(org.apache.poi.ss.usermodel.Sheet sheet)
getSheetIndex
in interface org.apache.poi.ss.usermodel.Workbook
sheet
- the sheet to look up
public int getExternalSheetIndex(int internalSheetIndex)
getExternalSheetIndex
in interface org.apache.poi.ss.usermodel.Workbook
public HSSFSheet createSheet()
createSheet
in interface org.apache.poi.ss.usermodel.Workbook
public HSSFSheet cloneSheet(int sheetNum)
cloneSheet
in interface org.apache.poi.ss.usermodel.Workbook
public HSSFSheet createSheet(java.lang.String sheetname)
createSheet
in interface org.apache.poi.ss.usermodel.Workbook
sheetname
- sheetname to set for the sheet.
java.lang.IllegalArgumentException
- if there is already a sheet present with a case-insensitive
match for the specified name.public int getNumberOfSheets()
getNumberOfSheets
in interface org.apache.poi.ss.usermodel.Workbook
public int getSheetIndexFromExternSheetIndex(int externSheetNumber)
getSheetIndexFromExternSheetIndex
in interface org.apache.poi.ss.usermodel.Workbook
public HSSFSheet getSheetAt(int index)
getSheetAt
in interface org.apache.poi.ss.usermodel.Workbook
index
- of the sheet number (0-based physical & logical)
public HSSFSheet getSheet(java.lang.String name)
getSheet
in interface org.apache.poi.ss.usermodel.Workbook
name
- of the sheet
null
if it does not existpublic SheetReferences getSheetReferences()
getSheetReferences
in interface org.apache.poi.ss.usermodel.Workbook
public void removeSheetAt(int index)
removeSheetAt
in interface org.apache.poi.ss.usermodel.Workbook
index
- of the sheet (0-based)public void setBackupFlag(boolean backupValue)
setBackupFlag
in interface org.apache.poi.ss.usermodel.Workbook
backupValue
- true to indicate a backup will be performed.public boolean getBackupFlag()
getBackupFlag
in interface org.apache.poi.ss.usermodel.Workbook
public void setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow)
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);
setRepeatingRowsAndColumns
in interface org.apache.poi.ss.usermodel.Workbook
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.public HSSFFont createFont()
createFont
in interface org.apache.poi.ss.usermodel.Workbook
public HSSFFont findFont(short boldWeight, short color, short fontHeight, java.lang.String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
findFont
in interface org.apache.poi.ss.usermodel.Workbook
public short getNumberOfFonts()
getNumberOfFonts
in interface org.apache.poi.ss.usermodel.Workbook
public HSSFFont getFontAt(short idx)
getFontAt
in interface org.apache.poi.ss.usermodel.Workbook
idx
- index number
public HSSFCellStyle createCellStyle()
createCellStyle
in interface org.apache.poi.ss.usermodel.Workbook
public short getNumCellStyles()
getNumCellStyles
in interface org.apache.poi.ss.usermodel.Workbook
public HSSFCellStyle getCellStyleAt(short idx)
getCellStyleAt
in interface org.apache.poi.ss.usermodel.Workbook
idx
- index within the set of styles
public void write(java.io.OutputStream stream) throws java.io.IOException
write
in interface org.apache.poi.ss.usermodel.Workbook
write
in class POIDocument
stream
- - the java OutputStream you wish to write the XLS to
java.io.IOException
- if anything can't be written.POIFSFileSystem
public byte[] getBytes()
getBytes
in interface org.apache.poi.ss.usermodel.Workbook
Workbook
,
Sheet
public int addSSTString(java.lang.String string)
addSSTString
in interface org.apache.poi.ss.usermodel.Workbook
public java.lang.String getSSTString(int index)
getSSTString
in interface org.apache.poi.ss.usermodel.Workbook
protected Workbook getWorkbook()
public int getNumberOfNames()
getNumberOfNames
in interface org.apache.poi.ss.usermodel.Workbook
public HSSFName getNameAt(int index)
getNameAt
in interface org.apache.poi.ss.usermodel.Workbook
index
- position of the named range
public java.lang.String getNameName(int index)
getNameName
in interface org.apache.poi.ss.usermodel.Workbook
index
- the named range index (0 based)
public java.lang.String resolveNameXText(int refIndex, int definedNameIndex)
resolveNameXText
in interface org.apache.poi.ss.usermodel.Workbook
refIndex
- Index to REF entry in EXTERNSHEET record in the Link TabledefinedNameIndex
- zero-based to DEFINEDNAME or EXTERNALNAME record
public void setPrintArea(int sheetIndex, java.lang.String reference)
i.e. Reference = $A$1:$B$2
setPrintArea
in interface org.apache.poi.ss.usermodel.Workbook
sheetIndex
- 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 org.apache.poi.ss.usermodel.Workbook
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)
public java.lang.String getPrintArea(int sheetIndex)
getPrintArea
in interface org.apache.poi.ss.usermodel.Workbook
sheetIndex
- Zero-based sheet index (0 Represents the first sheet to keep consistent with java)
public void removePrintArea(int sheetIndex)
removePrintArea
in interface org.apache.poi.ss.usermodel.Workbook
sheetIndex
- Zero-based sheet index (0 = First Sheet)public HSSFName createName()
createName
in interface org.apache.poi.ss.usermodel.Workbook
public int getNameIndex(java.lang.String name)
getNameIndex
in interface org.apache.poi.ss.usermodel.Workbook
name
- named range name
public void removeName(int index)
removeName
in interface org.apache.poi.ss.usermodel.Workbook
index
- named range index (0 based)public HSSFDataFormat createDataFormat()
createDataFormat
in interface org.apache.poi.ss.usermodel.Workbook
FormatRecord
,
Record
public void removeName(java.lang.String name)
removeName
in interface org.apache.poi.ss.usermodel.Workbook
name
- named range namepublic HSSFPalette getCustomPalette()
getCustomPalette
in interface org.apache.poi.ss.usermodel.Workbook
public void insertChartRecord()
insertChartRecord
in interface org.apache.poi.ss.usermodel.Workbook
public void dumpDrawingGroupRecords(boolean fat)
dumpDrawingGroupRecords
in interface org.apache.poi.ss.usermodel.Workbook
public int addPicture(byte[] pictureData, int format)
addPicture
in interface org.apache.poi.ss.usermodel.Workbook
pictureData
- The bytes of the pictureformat
- The format of the picture. One of PICTURE_TYPE_*
public java.util.List getAllPictures()
getAllPictures
in interface org.apache.poi.ss.usermodel.Workbook
HSSFPictureData
objects.)public boolean isWriteProtected()
public void writeProtectWorkbook(java.lang.String password, java.lang.String username)
writeProtectWorkbook
in interface org.apache.poi.ss.usermodel.Workbook
password
- to setpublic void unwriteProtectWorkbook()
unwriteProtectWorkbook
in interface org.apache.poi.ss.usermodel.Workbook
public java.util.List getAllEmbeddedObjects()
getAllEmbeddedObjects
in interface org.apache.poi.ss.usermodel.Workbook
HSSFObjectData
objects.)public org.apache.poi.ss.usermodel.CreationHelper getCreationHelper()
getCreationHelper
in interface org.apache.poi.ss.usermodel.Workbook
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |