Package org.apache.poi.xwpf.usermodel
Class XWPFHeaderFooter
java.lang.Object
org.apache.poi.ooxml.POIXMLDocumentPart
org.apache.poi.xwpf.usermodel.XWPFHeaderFooter
- All Implemented Interfaces:
IBody
- Direct Known Subclasses:
XWPFFooter
,XWPFHeader
Parent of XWPF headers and footers
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
POIXMLDocumentPart.RelationPart
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
XWPFHeaderFooter
(POIXMLDocumentPart parent, PackagePart part) -
Method Summary
Modifier and TypeMethodDescriptionorg.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr
addPictureData
(byte[] pictureData, int format) Adds a picture to the document.addPictureData
(InputStream is, int format) Adds a picture to the document.void
Clears all paragraphs and tables from this header / footerAdds a new paragraph at the end of the header or footercreateTable
(int rows, int cols) Adds a new table at the end of the header or footerget all Pictures in this packageReturns an Iterator with paragraphs and tables, in the order that they occur in the text.get a List of all ParagraphsgetOwner()
getParagraph
(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP p) if there is a correspondingXWPFParagraph
of the parameter ctTable in the paragraphList of this header or footer the method will return this paragraph if there is no correspondingXWPFParagraph
the method will return nullgetParagraphArray
(int pos) Returns the paragraph that holds the text of the header or footer.Returns the paragraph(s) that holds the text of the header or footer.getPart()
returns the Part, to which the body belongs, which you need for adding relationship to other partsgetPictureDataByID
(String blipID) returns the PictureData by blipIDgetTable
(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl ctTable) getTableArray
(int pos) Returns the table at position posgetTableCell
(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc cell) get the TableCell which belongs to the TableCellReturn the table(s) that holds the text of the header or footer, for complex cases where a paragraph isn't used.getText()
Returns the textual content of the header/footer, by flattening out the text of its paragraph(s)Return XWPFDocumentinsertNewParagraph
(org.apache.xmlbeans.XmlCursor cursor) add a new paragraph at position of the cursorinsertNewTbl
(org.apache.xmlbeans.XmlCursor cursor) inserts a new Table at the cursor position.void
insertTable
(int pos, XWPFTable table) inserts an existing XWPFTable to the arrays bodyElements and tablesprotected void
Fired when a package part is readprotected void
Ensure that a memory based package part does not have lingering data from previous commit() calls.void
void
removeParagraph
(XWPFParagraph paragraph) Removes a specific paragraph from this header / footervoid
removeTable
(XWPFTable table) Removes a specific table from this header / footervoid
setHeaderFooter
(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHdrFtr headerFooter) set a new headerFootervoid
Methods inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
_invokeOnDocumentRead, addRelation, commit, createRelationship, createRelationship, createRelationship, getNextPartNumber, getPackagePart, getParent, getRelationById, getRelationId, getRelationPartById, getRelationParts, getRelations, getTargetPart, isCommited, onDocumentCreate, onDocumentRemove, onSave, read, rebase, removeRelation, removeRelation, removeRelation, setCommited, 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.xwpf.usermodel.IBody
getPartType
-
Constructor Details
-
XWPFHeaderFooter
protected XWPFHeaderFooter() -
XWPFHeaderFooter
- Throws:
IOException
- Since:
- by POI 3.14-Beta1
-
-
Method Details
-
onDocumentRead
Description copied from class:POIXMLDocumentPart
Fired when a package part is read- Overrides:
onDocumentRead
in classPOIXMLDocumentPart
- Throws:
IOException
- a subclass may throw an IOException when a document is read
-
_getHdrFtr
-
getBodyElements
Description copied from interface:IBody
Returns an Iterator with paragraphs and tables, in the order that they occur in the text.- Specified by:
getBodyElements
in interfaceIBody
-
getParagraphs
Returns the paragraph(s) that holds the text of the header or footer. Normally there is only the one paragraph, but there could be more in certain cases, or a table.- Specified by:
getParagraphs
in interfaceIBody
-
getTables
Return the table(s) that holds the text of the header or footer, for complex cases where a paragraph isn't used. Normally there's just one paragraph, but some complex headers/footers have a table or two in addition.- Specified by:
getTables
in interfaceIBody
- Throws:
ArrayIndexOutOfBoundsException
-
getText
Returns the textual content of the header/footer, by flattening out the text of its paragraph(s) -
getTable
-
getParagraph
if there is a correspondingXWPFParagraph
of the parameter ctTable in the paragraphList of this header or footer the method will return this paragraph if there is no correspondingXWPFParagraph
the method will return null- Specified by:
getParagraph
in interfaceIBody
- Parameters:
p
- is instance of CTP and is searching for an XWPFParagraph- Returns:
- null if there is no XWPFParagraph with an corresponding CTPparagraph in the paragraphList of this header or footer XWPFParagraph with the correspondig CTP p
-
getParagraphArray
Returns the paragraph that holds the text of the header or footer.- Specified by:
getParagraphArray
in interfaceIBody
-
getListParagraph
get a List of all Paragraphs- Returns:
- a list of
XWPFParagraph
-
getAllPictures
-
getAllPackagePictures
get all Pictures in this package- Returns:
- all Pictures in this package
-
addPictureData
Adds a picture to the document.- Parameters:
pictureData
- The picture dataformat
- The format of the picture.- Returns:
- the index to this picture (0 based), the added picture can be obtained from
getAllPictures()
. - Throws:
InvalidFormatException
- If the format of the picture is not known.
-
addPictureData
Adds a picture to the document.- Parameters:
is
- The stream to read image fromformat
- The format of the picture.- Returns:
- the index to this picture (0 based), the added picture can be obtained from
getAllPictures()
. - Throws:
InvalidFormatException
- If the format of the picture is not known.IOException
- If reading the picture-data from the stream fails.
-
getPictureDataByID
returns the PictureData by blipID- Parameters:
blipID
-- Returns:
- XWPFPictureData of a specificID
- Throws:
Exception
-
createParagraph
Adds a new paragraph at the end of the header or footer- Returns:
- new
XWPFParagraph
object
-
createTable
Adds a new table at the end of the header or footer- Parameters:
rows
- - number of rows in the tablecols
- - number of columns in the table- Returns:
- new
XWPFTable
object
-
removeParagraph
Removes a specific paragraph from this header / footer- Parameters:
paragraph
- -XWPFParagraph
object to remove
-
removeTable
Removes a specific table from this header / footer- Parameters:
table
- -XWPFTable
object to remove
-
insertNewParagraph
add a new paragraph at position of the cursor- Specified by:
insertNewParagraph
in interfaceIBody
- Parameters:
cursor
-- Returns:
- the inserted paragraph
-
insertNewTbl
Description copied from interface:IBody
inserts a new Table at the cursor position.- Specified by:
insertNewTbl
in interfaceIBody
- Parameters:
cursor
-- Returns:
- the inserted table
-
getOwner
-
getTableArray
Returns the table at position pos- Specified by:
getTableArray
in interfaceIBody
- See Also:
-
insertTable
inserts an existing XWPFTable to the arrays bodyElements and tables- Specified by:
insertTable
in interfaceIBody
- Parameters:
pos
-table
-
-
readHdrFtr
public void readHdrFtr() -
getTableCell
get the TableCell which belongs to the TableCell- Specified by:
getTableCell
in interfaceIBody
- Parameters:
cell
-
-
getXWPFDocument
Description copied from interface:IBody
Return XWPFDocument- Specified by:
getXWPFDocument
in interfaceIBody
-
setXWPFDocument
-
getPart
returns the Part, to which the body belongs, which you need for adding relationship to other parts -
prepareForCommit
protected void prepareForCommit()Description copied from class:POIXMLDocumentPart
Ensure that a memory based package part does not have lingering data from previous commit() calls.Note: This is overwritten for some objects, as *PictureData seem to store the actual content in the part directly without keeping a copy like all others therefore we need to handle them differently.
- Overrides:
prepareForCommit
in classPOIXMLDocumentPart
-