|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.poi.POIXMLDocumentPart
org.apache.poi.POIXMLDocument
org.apache.poi.xssf.usermodel.XSSFWorkbook
public class XSSFWorkbook
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 | |
|---|---|
static float |
DEFAULT_CHARACTER_WIDTH
Width of one character of the default font in pixels. |
| Fields inherited from class org.apache.poi.POIXMLDocument |
|---|
CORE_PROPERTIES_REL_TYPE, CUSTOM_PROPERTIES_REL_TYPE, EXTENDED_PROPERTIES_REL_TYPE, 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 |
| Constructor Summary | |
|---|---|
XSSFWorkbook()
Create a new SpreadsheetML workbook. |
|
XSSFWorkbook(OPCPackage pkg)
Constructs a XSSFWorkbook object given a OpenXML4J Package object,
see www.openxml4j.org. |
|
XSSFWorkbook(java.lang.String path)
Constructs a XSSFWorkbook object given a file name. |
|
| Method Summary | |
|---|---|
int |
addPicture(byte[] pictureData,
int format)
Adds a picture to the workbook. |
int |
addPicture(java.io.InputStream is,
int format)
Adds a picture to the workbook. |
XSSFSheet |
cloneSheet(int sheetNum)
Create an XSSFSheet from an existing sheet in the XSSFWorkbook. |
protected void |
commit()
Save the content in the underlying package part. |
XSSFCellStyle |
createCellStyle()
Create a new XSSFCellStyle and add it to the workbook's style table |
XSSFDataFormat |
createDataFormat()
Returns the instance of XSSFDataFormat for this workbook. |
protected XSSFDialogsheet |
createDialogsheet(java.lang.String sheetname,
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet dialogsheet)
|
XSSFFont |
createFont()
Create a new Font and add it to the workbook's font table |
XSSFName |
createName()
Creates a new (uninitialised) defined name in this workbook |
XSSFSheet |
createSheet()
Create an XSSFSheet for this workbook, adds it to the sheets and returns the high level representation. |
XSSFSheet |
createSheet(java.lang.String sheetname)
Create an XSSFSheet for this workbook, adds it to the sheets and returns the high level representation. |
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 |
int |
getActiveSheetIndex()
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. |
CalculationChain |
getCalculationChain()
Return the CalculationChain object for this workbook |
XSSFCellStyle |
getCellStyleAt(short idx)
gGet the cell style object at the given index |
XSSFCreationHelper |
getCreationHelper()
Returns an object that handles instantiating concrete classes of the various instances for XSSF. |
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook |
getCTWorkbook()
Return the underlying XML bean |
int |
getFirstVisibleTab()
Gets the first tab that is displayed in the list of tabs in excel. |
XSSFFont |
getFontAt(short idx)
Get the font at the given index number |
Row.MissingCellPolicy |
getMissingCellPolicy()
Retrieves the current policy on what to do when getting missing or blank cells from a row. |
XSSFName |
getName(java.lang.String name)
|
XSSFName |
getNameAt(int nameIndex)
|
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. |
short |
getNumberOfFonts()
Get the number of fonts in the this workbook |
int |
getNumberOfNames()
Get the number of named ranges in the this workbook |
int |
getNumberOfSheets()
Get the number of worksheets in the this workbook |
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. |
SharedStringsTable |
getSharedStringSource()
Returns SharedStringsTable - tha cache of string for this workbook |
XSSFSheet |
getSheet(java.lang.String name)
Get sheet with the given name (case insensitive match) |
XSSFSheet |
getSheetAt(int index)
Get the XSSFSheet object at the given index. |
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 (case insensitive match) |
java.lang.String |
getSheetName(int sheetIx)
Get the sheet name |
StylesTable |
getStylesSource()
Return a object representing a collection of shared objects used for styling content, e.g. |
protected boolean |
isDate1904()
Gets a boolean value that indicates whether the date systems used in the workbook starts in 1904. |
boolean |
isHidden()
|
boolean |
isMacroEnabled()
Are we a normal workbook (.xlsx), or a macro enabled workbook (.xlsm)? |
boolean |
isSheetHidden(int sheetIx)
Check whether a sheet is hidden. |
boolean |
isSheetVeryHidden(int sheetIx)
Check whether a sheet is very hidden. |
java.util.Iterator<XSSFSheet> |
iterator()
Allows foreach loops: |
protected static OPCPackage |
newPackage()
Create a new SpreadsheetML package and setup the default minimal content |
protected void |
onDeleteFormula(XSSFCell cell)
Fired when a formula is deleted from this workbook, for example when calling cell.setCellFormula(null) |
protected void |
onDocumentRead()
Fired when a package part is read |
void |
removeName(int nameIndex)
Remove the defined name at the specified index |
void |
removeName(java.lang.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. Care must be taken if the removed sheet is the currently active or only selected sheet in the workbook. |
void |
setActiveSheet(int index)
Convenience method to set the active sheet. |
void |
setFirstVisibleTab(int index)
Sets the first tab that is displayed in the list of tabs in excel. |
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 |
void |
setRepeatingRowsAndColumns(int sheetIndex,
int startColumn,
int endColumn,
int startRow,
int endRow)
Sets the repeating rows and columns for a sheet. |
void |
setSelectedTab(int index)
We only set one sheet as selected for compatibility with HSSF. |
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,
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. |
| Methods inherited from class org.apache.poi.POIXMLDocument |
|---|
ensureWriteAccess, getCorePart, getPackage, getProperties, getRelatedByType, getTargetPart, getTargetPart, hasOOXMLHeader, openPackage, write |
| Methods inherited from class org.apache.poi.POIXMLDocumentPart |
|---|
addRelation, createRelationship, createRelationship, createRelationship, getPackagePart, getPackageRelationship, getParent, getRelations, onDocumentCreate, onSave, read, removeRelation, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.apache.poi.ss.usermodel.Workbook |
|---|
write |
| Field Detail |
|---|
public static final float DEFAULT_CHARACTER_WIDTH
| Constructor Detail |
|---|
public XSSFWorkbook()
public XSSFWorkbook(OPCPackage pkg)
throws java.io.IOException
Package object,
see www.openxml4j.org.
pkg - the OpenXML4J Package object.
java.io.IOException
public XSSFWorkbook(java.lang.String path)
throws java.io.IOException
path - the file name.
java.io.IOException| Method Detail |
|---|
protected void onDocumentRead()
throws java.io.IOException
POIXMLDocumentPart
onDocumentRead in class POIXMLDocumentPartjava.io.IOExceptionprotected static OPCPackage newPackage()
public org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook getCTWorkbook()
public int addPicture(byte[] pictureData,
int format)
addPicture in interface WorkbookpictureData - The bytes of the pictureformat - The format of the picture.
getAllPictures() .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()
public int addPicture(java.io.InputStream is,
int format)
throws java.io.IOException
is - The sream to read image fromformat - The format of the picture.
getAllPictures() .
java.io.IOExceptionWorkbook.PICTURE_TYPE_EMF,
Workbook.PICTURE_TYPE_WMF,
Workbook.PICTURE_TYPE_PICT,
Workbook.PICTURE_TYPE_JPEG,
Workbook.PICTURE_TYPE_PNG,
Workbook.PICTURE_TYPE_DIB,
getAllPictures()public XSSFSheet cloneSheet(int sheetNum)
cloneSheet in interface Workbookjava.lang.IllegalArgumentException - if the sheet index in invalid
POIXMLException - if there were errors when cloningpublic XSSFCellStyle createCellStyle()
createCellStyle in interface Workbookpublic XSSFDataFormat createDataFormat()
createDataFormat in interface WorkbookDataFormatpublic XSSFFont createFont()
createFont in interface Workbookpublic XSSFName createName()
Workbook
createName in interface Workbookpublic XSSFSheet createSheet()
createSheet in interface Workbookpublic XSSFSheet createSheet(java.lang.String sheetname)
createSheet in interface Workbooksheetname - sheetname to set for the sheet, can't be duplicate, greater than 31 chars or contain /\?*[]
java.lang.IllegalArgumentException - if the sheetname is invalid or the workbook already contains a sheet of this name
protected XSSFDialogsheet createDialogsheet(java.lang.String sheetname,
org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet dialogsheet)
public XSSFFont findFont(short boldWeight,
short color,
short fontHeight,
java.lang.String name,
boolean italic,
boolean strikeout,
short typeOffset,
byte underline)
findFont in interface Workbooknullpublic int getActiveSheetIndex()
getActiveSheetIndex in interface Workbookpublic java.util.List<XSSFPictureData> getAllPictures()
getAllPictures in interface WorkbookXSSFPictureData objects.)addPicture(byte[], int)public XSSFCellStyle getCellStyleAt(short idx)
getCellStyleAt in interface Workbookidx - index within the set of styles
public XSSFFont getFontAt(short idx)
getFontAt in interface Workbookidx - index number
public XSSFName getName(java.lang.String name)
getName in interface Workbookname - the name of the defined name
null if not found.public XSSFName getNameAt(int nameIndex)
getNameAt in interface WorkbooknameIndex - position of the named range (0-based)
public int getNameIndex(java.lang.String name)
getNameIndex in interface Workbookname - named range name
public short getNumCellStyles()
getNumCellStyles in interface Workbookpublic short getNumberOfFonts()
getNumberOfFonts in interface Workbookpublic int getNumberOfNames()
getNumberOfNames in interface Workbookpublic int getNumberOfSheets()
getNumberOfSheets in interface Workbookpublic 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 XSSFSheet getSheet(java.lang.String name)
getSheet in interface Workbookname - of the sheet
null if it does not existpublic XSSFSheet getSheetAt(int index)
getSheetAt in interface Workbookindex - of the sheet number (0-based physical & logical)
java.lang.IllegalArgumentException - if the index is out of range (index
< 0 || index >= getNumberOfSheets()).public int getSheetIndex(java.lang.String name)
getSheetIndex in interface Workbookname - the sheet name
public int getSheetIndex(Sheet sheet)
getSheetIndex in interface Workbooksheet - the sheet to look up
public java.lang.String getSheetName(int sheetIx)
getSheetName in interface WorkbooksheetIx - Number
public java.util.Iterator<XSSFSheet> iterator()
XSSFWorkbook wb = new XSSFWorkbook(package);
for(XSSFSheet sheet : wb){
}
iterator in interface java.lang.Iterable<XSSFSheet>public boolean isMacroEnabled()
public void removeName(int nameIndex)
Workbook
removeName in interface WorkbooknameIndex - named range index (0 based)public void removeName(java.lang.String name)
Workbook
removeName in interface Workbookname - the name of the defined namepublic void removePrintArea(int sheetIndex)
removePrintArea in interface WorkbooksheetIndex - 0-based sheet index (0 = First Sheet)public void removeSheetAt(int index)
removeSheetAt in interface Workbookindex - of the sheet (0-based)public Row.MissingCellPolicy getMissingCellPolicy()
Row.MissingCellPolicy
getMissingCellPolicy in interface Workbookpublic void setMissingCellPolicy(Row.MissingCellPolicy missingCellPolicy)
Row.getCell(int)}. See
Row.MissingCellPolicy
setMissingCellPolicy in interface Workbookpublic void setActiveSheet(int index)
setActiveSheet in interface Workbookindex - index of the active sheet (0-based)public int getFirstVisibleTab()
getFirstVisibleTab in interface Workbookpublic void setFirstVisibleTab(int index)
setFirstVisibleTab in interface Workbookindex - integer that contains the index to the active sheet in this book view.
public 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 Area
public 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 void setRepeatingRowsAndColumns(int sheetIndex,
int startColumn,
int endColumn,
int startRow,
int endRow)
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 WorkbooksheetIndex - 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 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)validateSheetName(String)
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)
protected void commit()
throws java.io.IOException
POIXMLDocumentPart
protected void commit() throws IOException {
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
XmlObject bean = getXmlBean(); //the "model" which holds changes in memory
bean.save(out, DEFAULT_XML_OPTIONS);
out.close();
}
commit in class POIXMLDocumentPartjava.io.IOExceptionpublic SharedStringsTable getSharedStringSource()
public StylesTable getStylesSource()
public XSSFCreationHelper getCreationHelper()
getCreationHelper in interface Workbookprotected boolean isDate1904()
The default value is false, meaning that the workbook uses the 1900 date system, where 1/1/1900 is the first day in the system..
public java.util.List<PackagePart> getAllEmbedds()
throws OpenXML4JException
getAllEmbedds in class POIXMLDocumentOpenXML4JExceptionpublic boolean isHidden()
isHidden in interface Workbookfalse if this workbook is not visible in the GUIpublic void setHidden(boolean hiddenFlag)
setHidden in interface WorkbookhiddenFlag - pass false to make the workbook visible in the GUIpublic 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 - Number
true if sheet is hiddenpublic boolean isSheetVeryHidden(int sheetIx)
Workbook
This is different from the normal hidden status
(Workbook.isSheetHidden(int))
isSheetVeryHidden in interface WorkbooksheetIx - sheet index to check
true if sheet is very hidden
public void setSheetHidden(int sheetIx,
boolean hidden)
Workbook
setSheetHidden in interface WorkbooksheetIx - the sheet index (0-based)hidden - True to mark the sheet as hidden, false otherwise
public void setSheetHidden(int sheetIx,
int hidden)
Workbook0 = not hidden 1 = hidden 2 = very hidden.
setSheetHidden in interface WorkbooksheetIx - The sheet numberhidden - 0 for not hidden, 1 for hidden, 2 for very hiddenprotected void onDeleteFormula(XSSFCell cell)
XSSFCell.setCellFormula(String)public CalculationChain getCalculationChain()
The calculation chain object specifies the order in which the cells in a workbook were last calculated
CalculationChain object or null if not defined
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||