public class HSSFWorkbook extends POIDocument
Modifier and Type | Field and Description |
---|---|
private static int |
DEBUG |
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
|
private HSSFDataFormat |
formatter
Used to keep track of the data formatter so that all
createDataFormatter calls return the same one for a given
book.
|
static int |
INITIAL_CAPACITY
used for compile-time performance/memory optimization.
|
private static POILogger |
log |
private ArrayList |
names
this holds the HSSFName objects attached to this workbook
|
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
|
private boolean |
preserveNodes
holds whether or not to preserve other nodes in the POIFS.
|
protected ArrayList |
sheets
this holds the HSSFSheet objects attached to this workbook
|
private Workbook |
workbook
this is the reference to the low level Workbook object
|
dsInf, filesystem, logger, sInf
Modifier | Constructor and Description |
---|---|
|
HSSFWorkbook()
Creates new HSSFWorkbook from scratch (start here!)
|
|
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.
|
|
HSSFWorkbook(RandomAccessInputStream s) |
|
HSSFWorkbook(RandomAccessInputStream s,
boolean preserveNodes)
Companion to HSSFWorkbook(POIFSFileSystem), this constructs the POI filesystem around your
inputstream.
|
protected |
HSSFWorkbook(Workbook book) |
Modifier and Type | Method and Description |
---|---|
int |
addPicture(byte[] pictureData,
int format)
Adds a picture to the workbook.
|
int |
addSSTString(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.
|
private void |
convertLabelRecords(List records,
int offset)
This is basically a kludge to deal with the now obsolete Label records.
|
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(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.
|
private NameRecord |
findExistingRowColHeaderNameRecord(int sheetIndex) |
private int |
findExistingRowColHeaderNameRecordIdx(int sheetIndex) |
HSSFFont |
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
|
List |
getAllEmbeddedObjects()
Gets all embedded OLE2 objects from the Workbook.
|
private void |
getAllEmbeddedObjects(List records,
List objects)
Gets all embedded OLE2 objects from the Workbook.
|
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
|
HSSFPalette |
getCustomPalette() |
short |
getDisplayedTab()
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
|
HSSFName |
getNameAt(int index)
gets the Named range
|
int |
getNameIndex(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.
|
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
|
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()
gets the tab whose data is actually seen when the sheet is opened.
|
HSSFSheet |
getSheet(String name)
Get sheet with the given name
|
HSSFSheet |
getSheetAt(int index)
Get the HSSFSheet object at the given index.
|
int |
getSheetIndex(HSSFSheet 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
|
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.
|
private boolean |
isRowColHeaderRecord(NameRecord r) |
private byte[] |
newUID() |
void |
removeName(int index)
remove the named range by his index
|
void |
removeName(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
|
private void |
searchForPictures(List escherRecords,
List pictures)
Performs a recursive search for pictures in the given list of escher records.
|
void |
setBackupFlag(boolean backupValue)
determine whether the Excel GUI will backup the workbook when saving.
|
void |
setDisplayedTab(short index)
sets the first tab that is displayed in the list of tabs
in excel.
|
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
|
private void |
setPropertiesFromWorkbook(Workbook book)
used internally to set the workbook properties.
|
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(short index)
sets the tab whose data is actually seen when the sheet is opened.
|
void |
setSheetName(int sheet,
String name)
set the sheet name.
|
void |
setSheetName(int sheet,
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(String sheetname,
int pos)
sets the order of appearance for a given sheet.
|
void |
unwriteProtectWorkbook()
removes the write protect flag
|
void |
write(OutputStream stream)
Method write - write out this workbook to an Outputstream.
|
void |
writeProtectWorkbook(String password,
String username)
protect a workbook with a password (not encypted, just sets writeprotect
flags and the password.
|
copyNodes, getDocumentSummaryInformation, getPropertySet, getSummaryInformation, readProperties, writeProperties, writeProperties, writePropertySet
private static final int DEBUG
public static final int INITIAL_CAPACITY
private Workbook workbook
protected ArrayList sheets
private ArrayList names
private boolean preserveNodes
private HSSFDataFormat formatter
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
private static POILogger log
public static final byte ENCODING_COMPRESSED_UNICODE
public static final byte ENCODING_UTF_16
public HSSFWorkbook()
protected HSSFWorkbook(Workbook book)
public HSSFWorkbook(POIFSFileSystem fs) throws IOException
IOException
public HSSFWorkbook(POIFSFileSystem fs, boolean preserveNodes) throws 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 memoryIOException
- if the stream cannot be readPOIFSFileSystem
public HSSFWorkbook(RandomAccessInputStream s) throws IOException
IOException
public HSSFWorkbook(RandomAccessInputStream s, boolean preserveNodes) throws 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.IOException
- if the stream cannot be readPOIFSFileSystem
,
HSSFWorkbook(POIFSFileSystem)
private void setPropertiesFromWorkbook(Workbook book)
private void convertLabelRecords(List records, int offset)
records
- sheet's matching low level Workbook structure containing the SSTRecord.LabelRecord
,
LabelSSTRecord
,
SSTRecord
public 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)public void setSelectedTab(short index)
index
- HSSFSheet.setSelected(boolean)
public short getSelectedTab()
HSSFSheet.setSelected(boolean)
public void setDisplayedTab(short index)
index
- public short getDisplayedTab()
public void setSheetName(int sheet, String name)
sheet
- number (0 based)public void setSheetName(int sheet, String name, short encoding)
sheet
- number (0 based)IllegalArgumentException
- if the name is greater than 31 chars
or contains /\?*[]public String getSheetName(int sheet)
sheet
- Numberpublic int getSheetIndex(String name)
name
- the sheet namepublic int getSheetIndex(HSSFSheet sheet)
sheet
- the sheet to look uppublic HSSFSheet createSheet()
public HSSFSheet cloneSheet(int sheetNum)
public HSSFSheet createSheet(String sheetname)
sheetname
- sheetname to set for the sheet.public int getNumberOfSheets()
public HSSFSheet getSheetAt(int index)
index
- of the sheet number (0-based physical & logical)public HSSFSheet getSheet(String name)
name
- of the sheetpublic void removeSheetAt(int index)
index
- of the sheet (0-based)public void setBackupFlag(boolean backupValue)
backupValue
- true to indicate a backup will be performed.public boolean getBackupFlag()
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);
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.private NameRecord findExistingRowColHeaderNameRecord(int sheetIndex)
private int findExistingRowColHeaderNameRecordIdx(int sheetIndex)
private boolean isRowColHeaderRecord(NameRecord r)
public HSSFFont createFont()
public HSSFFont findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline)
public short getNumberOfFonts()
public HSSFFont getFontAt(short idx)
idx
- index numberpublic HSSFCellStyle createCellStyle()
public short getNumCellStyles()
public HSSFCellStyle getCellStyleAt(short idx)
idx
- index within the set of stylespublic void write(OutputStream stream) throws IOException
stream
- - the java OutputStream you wish to write the XLS toIOException
- if anything can't be written.POIFSFileSystem
public byte[] getBytes()
public int addSSTString(String string)
public String getSSTString(int index)
protected Workbook getWorkbook()
public int getNumberOfNames()
public HSSFName getNameAt(int index)
index
- position of the named rangepublic String getNameName(int index)
index
- the named range index (0 based)public void 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 Areapublic void 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)
public String getPrintArea(int sheetIndex)
sheetIndex
- Zero-based sheet index (0 Represents the first sheet to keep consistent with java)public void removePrintArea(int sheetIndex)
sheetIndex
- Zero-based sheet index (0 = First Sheet)public HSSFName createName()
public int getNameIndex(String name)
name
- named range namepublic void removeName(int index)
index
- named range index (0 based)public HSSFDataFormat createDataFormat()
FormatRecord
,
Record
public void removeName(String name)
name
- named range namepublic HSSFPalette getCustomPalette()
public void insertChartRecord()
public void dumpDrawingGroupRecords(boolean fat)
public int addPicture(byte[] pictureData, int format)
pictureData
- The bytes of the pictureformat
- The format of the picture. One of PICTURE_TYPE_*
public List getAllPictures()
HSSFPictureData
objects.)private void searchForPictures(List escherRecords, List pictures)
escherRecords
- the escher records.pictures
- the list to populate with the pictures.public void writeProtectWorkbook(String password, String username)
password
- to setpublic void unwriteProtectWorkbook()
public List getAllEmbeddedObjects()
HSSFObjectData
objects.)private void getAllEmbeddedObjects(List records, List objects)
records
- the list of records to search.objects
- the list of embedded objects to populate.private byte[] newUID()
Copyright © 2016 Open Microscopy Environment