Package org.apache.poi.xwpf.usermodel
Class XWPFDocument
- java.lang.Object
-
- org.apache.poi.ooxml.POIXMLDocumentPart
-
- org.apache.poi.ooxml.POIXMLDocument
-
- org.apache.poi.xwpf.usermodel.XWPFDocument
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Document,IBody
public class XWPFDocument extends POIXMLDocument implements Document, IBody
High(ish) level class for working with .docx files.This class tries to hide some of the complexity of the underlying file format, but as it's not a mature and stable API yet, certain parts of the XML structure come through. You'll therefore almost certainly need to refer to the OOXML specifications from http://www.ecma-international.org/publications/standards/Ecma-376.htm at some point in your use.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
POIXMLDocumentPart.RelationPart
-
-
Field Summary
Fields Modifier and Type Field Description protected List<IBodyElement>bodyElementsprotected List<XWPFChart>chartsprotected List<XWPFSDT>contentControlsprotected XWPFEndnotesendnotesprotected List<XWPFFooter>footersprotected XWPFFootnotesfootnotesprotected List<XWPFHeader>headersprotected List<XWPFHyperlink>hyperlinksprotected XWPFNumberingnumberingprotected Map<Long,List<XWPFPictureData>>packagePicturesprotected List<XWPFParagraph>paragraphsprotected List<XWPFPictureData>picturesprotected XWPFStylesstylesprotected List<XWPFTable>tables-
Fields inherited from class org.apache.poi.ooxml.POIXMLDocument
DOCUMENT_CREATOR, OLE_OBJECT_REL_TYPE, PACK_OBJECT_REL_TYPE
-
Fields inherited from interface org.apache.poi.xwpf.usermodel.Document
PICTURE_TYPE_BMP, PICTURE_TYPE_DIB, PICTURE_TYPE_EMF, PICTURE_TYPE_EPS, PICTURE_TYPE_GIF, PICTURE_TYPE_JPEG, PICTURE_TYPE_PICT, PICTURE_TYPE_PNG, PICTURE_TYPE_TIFF, PICTURE_TYPE_WMF, PICTURE_TYPE_WPG
-
-
Constructor Summary
Constructors Constructor Description XWPFDocument()XWPFDocument(InputStream is)XWPFDocument(OPCPackage pkg)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description XWPFEndnoteaddEndnote(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn note)Add a CTFtnEdn endnote to the document.XWPFFootnoteaddFootnote(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn note)Add a CTFtnEdn footnote to the document.StringaddPictureData(byte[] pictureData, int format)Adds a picture to the document.StringaddPictureData(byte[] pictureData, PictureType pictureType)Adds a picture to the document.StringaddPictureData(InputStream is, int format)Adds a picture to the document.StringaddPictureData(InputStream is, PictureType pictureType)Adds a picture to the document.protected voidcommit()commit and saves the documentXWPFChartcreateChart()This method is used to create template for chart XML no need to read MS-Word file and modify chartsXWPFChartcreateChart(int width, int height)This method is used to create template for chart XML no need to read MS-Word file and modify chartsXWPFChartcreateChart(XWPFRun run, int width, int height)XWPFCommentscreateComments()Creates an empty comments for the document if one does not already existXWPFEndnotecreateEndnote()Create a new end note and add it to the document.XWPFEndnotescreateEndnotes()XWPFFootercreateFooter(HeaderFooterType type)Create a footer of the given typeXWPFFootnotecreateFootnote()Create a new footnote and add it to the document.XWPFFootnotescreateFootnotes()Creates an empty footnotes element for the document if one does not already existXWPFHeadercreateHeader(HeaderFooterType type)Create a header of the given typeXWPFHeaderFooterPolicycreateHeaderFooterPolicy()XWPFNumberingcreateNumbering()Creates an empty numbering if one does not already exist and sets the numbering memberXWPFParagraphcreateParagraph()Appends a new paragraph to this documentXWPFStylescreateStyles()Creates an empty styles for the document if one does not already existXWPFTablecreateTable()Create an empty table with one row and one column as default.XWPFTablecreateTable(int rows, int cols)Create an empty table with a number of rows and cols specifiedvoidcreateTOC()voidenforceCommentsProtection()Enforce the Comments protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to comments (w:edit="comments")
sample snippet from settings.xmlvoidenforceCommentsProtection(String password, HashAlgorithm hashAlgo)Enforce the Comments protection.
sample snippet from settings.xmlvoidenforceFillingFormsProtection()Enforce the Filling Forms protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to forms (w:edit="forms")
sample snippet from settings.xmlvoidenforceFillingFormsProtection(String password, HashAlgorithm hashAlgo)Enforce the Filling Forms protection.
sample snippet from settings.xmlvoidenforceReadonlyProtection()Enforces the readOnly protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to readOnly (w:edit="readOnly")
sample snippet from settings.xmlvoidenforceReadonlyProtection(String password, HashAlgorithm hashAlgo)Enforces the readOnly protection with a password.
sample snippet from settings.xmlvoidenforceTrackedChangesProtection()Enforce the Tracked Changes protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to trackedChanges (w:edit="trackedChanges")
sample snippet from settings.xmlvoidenforceTrackedChangesProtection(String password, HashAlgorithm hashAlgo)Enforce the Tracked Changes protection.
sample snippet from settings.xmlvoidenforceUpdateFields()Enforces fields update on document open (in Word).List<PackagePart>getAllEmbeddedParts()Get the document's embedded files.List<XWPFPictureData>getAllPackagePictures()List<XWPFPictureData>getAllPictures()Returns all Pictures, which are referenced from the document itself.List<IBodyElement>getBodyElements()returns an Iterator with paragraphs and tablesIterator<IBodyElement>getBodyElementsIterator()Spliterator<IBodyElement>getBodyElementsSpliterator()returns a Spliterator with paragraphs and tablesList<XWPFChart>getCharts()XWPFCommentgetCommentByID(String id)XWPFComment[]getComments()XWPFCommentsgetDocComments()Get Commentsorg.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1getDocument()Returns the low level document base objectXWPFEndnotegetEndnoteByID(int id)List<XWPFEndnote>getEndnotes()Gets the list of end notes for the document.booleangetEvenAndOddHeadings()Returns the even-and-odd-headings settingXWPFFootergetFooterArray(int pos)List<XWPFFooter>getFooterList()XWPFFootnotegetFootnoteByID(int id)List<XWPFFootnote>getFootnotes()XWPFHeadergetHeaderArray(int pos)XWPFHeaderFooterPolicygetHeaderFooterPolicy()Returns the policy on headers and footers, which also provides a way to get at them.List<XWPFHeader>getHeaderList()XWPFHyperlinkgetHyperlinkByID(String id)XWPFHyperlink[]getHyperlinks()XWPFParagraphgetLastParagraph()booleangetMirrorMargins()Returns the mirror margins settingintgetNextPicNameNumber(int format)get the next free ImageNumberintgetNextPicNameNumber(PictureType pictureType)get the next free ImageNumberXWPFNumberinggetNumbering()getNumberingXWPFParagraphgetParagraph(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP p)Returns the paragraph corresponding to the providedCTP.XWPFParagraphgetParagraphArray(int pos)Returns the paragraph that of position posintgetParagraphPos(int pos)Look up the paragraph at the specified position in the body elements list and return this paragraphs position in the paragraphs listList<XWPFParagraph>getParagraphs()Returns the paragraph(s) that holds the text of the header or footer.Iterator<XWPFParagraph>getParagraphsIterator()Spliterator<XWPFParagraph>getParagraphsSpliterator()POIXMLDocumentPartgetPart()returns the Part, to which the body belongs, which you need for adding relationship to other parts Actually it is needed of the class XWPFTableCell.PackagePartgetPartById(String id)Get the document part that's defined as the given relationship of the core document.BodyTypegetPartType()get the PartType of the body, for example DOCUMENT, HEADER, FOOTER, FOOTNOTE,XWPFPictureDatagetPictureDataByID(String blipID)returns the PictureData by blipIDintgetPosOfParagraph(XWPFParagraph p)Get the position of the paragraph, within the list of all the body elements.intgetPosOfTable(XWPFTable t)Get the position of the table, within the list of all the body elements.XWPFSettingsgetSettings()org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStylesgetStyle()Returns the styles object usedXWPFStylesgetStyles()get StylesXWPFTablegetTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl ctTbl)get a table by its CTTbl-ObjectXWPFTablegetTableArray(int pos)Returns the table at position posXWPFTableCellgetTableCell(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc cell)get the TableCell which belongs to the TableCellintgetTablePos(int pos)get with the position of a table in the bodyelement array list the position of this table in the table array listList<XWPFTable>getTables()Return the table(s) that holds the text of the IBodyPart, for complex cases where a paragraph isn't used.Iterator<XWPFTable>getTablesIterator()Spliterator<XWPFTable>getTablesSpliterator()StringgetTblStyle(XWPFTable table)XWPFDocumentgetXWPFDocument()Return XWPFDocumentlonggetZoomPercent()Returns the current zoom factor in percent values, i.e.XWPFParagraphinsertNewParagraph(XmlCursor cursor)Add a new paragraph at position of the cursor.XWPFTableinsertNewTbl(XmlCursor cursor)inserts a new Table at the cursor position.voidinsertTable(int pos, XWPFTable table)inserts an existing XWPFTable to the arrays bodyElements and tablesbooleanisEnforcedCommentsProtection()Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is comments (w:edit="comments")
sample snippet from settings.xmlbooleanisEnforcedFillingFormsProtection()Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is forms (w:edit="forms")
sample snippet from settings.xmlbooleanisEnforcedProtection()Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
sample snippet from settings.xmlbooleanisEnforcedReadonlyProtection()Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is readOnly (w:edit="readOnly")
sample snippet from settings.xmlbooleanisEnforcedTrackedChangesProtection()Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is trackedChanges (w:edit="trackedChanges")
sample snippet from settings.xmlbooleanisEnforcedUpdateFields()booleanisTrackRevisions()Check if revision tracking is turned on.protected static OPCPackagenewPackage()Create a new WordProcessingML package and setup the default minimal contentprotected voidonDocumentCreate()Create a new CTWorkbook with all values set to defaultprotected voidonDocumentRead()Fired when a package part is readbooleanremoveBodyElement(int pos)remove a BodyElement from bodyElements array listbooleanremoveEndnote(int pos)Remove the specified end note if present.booleanremoveFootnote(int pos)Remove the specified footnote if present.voidremoveProtectionEnforcement()Remove protection enforcement.
In the documentProtection tag inside settings.xml file
it sets the value of enforcement to "0" (w:enforcement="0")voidsetEvenAndOddHeadings(boolean enable)Sets the even-and-odd-headings settingvoidsetMirrorMargins(boolean enable)Sets the mirror margins settingvoidsetParagraph(XWPFParagraph paragraph, int pos)copies content of a paragraph to a existing paragraph in the list paragraphs at position posvoidsetTable(int pos, XWPFTable table)Replace content of table in array tables at position pos with avoidsetTrackRevisions(boolean enable)Enable or disable revision tracking.voidsetZoomPercent(long zoomPercent)Set the zoom setting as percent value, i.e.booleanvalidateProtectionPassword(String password)Validates the existing password-
Methods inherited from class org.apache.poi.ooxml.POIXMLDocument
close, getCorePart, getPackage, getProperties, getRelatedByType, load, openPackage, write
-
Methods inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
_invokeOnDocumentRead, addRelation, createRelationship, createRelationship, createRelationship, getNextPartNumber, getPackagePart, getParent, getRelationById, getRelationId, getRelationPartById, getRelationParts, getRelations, getTargetPart, isCommitted, onDocumentRemove, onSave, prepareForCommit, read, rebase, removeRelation, removeRelation, removeRelation, setCommitted, toString
-
-
-
-
Field Detail
-
footers
protected List<XWPFFooter> footers
-
headers
protected List<XWPFHeader> headers
-
hyperlinks
protected List<XWPFHyperlink> hyperlinks
-
paragraphs
protected List<XWPFParagraph> paragraphs
-
bodyElements
protected List<IBodyElement> bodyElements
-
pictures
protected List<XWPFPictureData> pictures
-
packagePictures
protected Map<Long,List<XWPFPictureData>> packagePictures
-
endnotes
protected XWPFEndnotes endnotes
-
numbering
protected XWPFNumbering numbering
-
styles
protected XWPFStyles styles
-
footnotes
protected XWPFFootnotes footnotes
-
-
Constructor Detail
-
XWPFDocument
public XWPFDocument(OPCPackage pkg) throws IOException
- Parameters:
pkg- OPC package- Throws:
IOException- If reading data from the package failsPOIXMLException- a RuntimeException that can be caused by invalid OOXML dataRuntimeException- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
XWPFDocument
public XWPFDocument(InputStream is) throws IOException
- Parameters:
is- The InputStream to read data from- Throws:
IOException- If reading data from the stream failsPOIXMLException- a RuntimeException that can be caused by invalid OOXML dataRuntimeException- a number of other runtime exceptions can be thrown, especially if there are problems with the input format
-
XWPFDocument
public XWPFDocument()
-
-
Method Detail
-
newPackage
protected static OPCPackage newPackage()
Create a new WordProcessingML package and setup the default minimal content
-
onDocumentRead
protected void onDocumentRead() throws IOExceptionDescription copied from class:POIXMLDocumentPartFired when a package part is read- Overrides:
onDocumentReadin classPOIXMLDocumentPart- Throws:
IOException- a subclass may throw an IOException when a document is read
-
onDocumentCreate
protected void onDocumentCreate()
Create a new CTWorkbook with all values set to default- Overrides:
onDocumentCreatein classPOIXMLDocumentPart
-
getDocument
@Internal public org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1 getDocument()
Returns the low level document base object
-
getBodyElements
public List<IBodyElement> getBodyElements()
returns an Iterator with paragraphs and tables- Specified by:
getBodyElementsin interfaceIBody
-
getBodyElementsIterator
public Iterator<IBodyElement> getBodyElementsIterator()
-
getBodyElementsSpliterator
public Spliterator<IBodyElement> getBodyElementsSpliterator()
returns a Spliterator with paragraphs and tables- Since:
- POI 5.2.0
-
getParagraphs
public List<XWPFParagraph> getParagraphs()
Description copied from interface:IBodyReturns the paragraph(s) that holds the text of the header or footer.- Specified by:
getParagraphsin interfaceIBody
-
getTables
public List<XWPFTable> getTables()
Description copied from interface:IBodyReturn the table(s) that holds the text of the IBodyPart, for complex cases where a paragraph isn't used.
-
getTableArray
public XWPFTable getTableArray(int pos)
Description copied from interface:IBodyReturns the table at position pos- Specified by:
getTableArrayin interfaceIBody
-
getFooterList
public List<XWPFFooter> getFooterList()
- Returns:
- the list of footers
-
getFooterArray
public XWPFFooter getFooterArray(int pos)
-
getHeaderList
public List<XWPFHeader> getHeaderList()
- Returns:
- the list of headers
-
getHeaderArray
public XWPFHeader getHeaderArray(int pos)
-
getHyperlinkByID
public XWPFHyperlink getHyperlinkByID(String id)
-
getFootnoteByID
public XWPFFootnote getFootnoteByID(int id)
-
getEndnoteByID
public XWPFEndnote getEndnoteByID(int id)
-
getFootnotes
public List<XWPFFootnote> getFootnotes()
-
getHyperlinks
public XWPFHyperlink[] getHyperlinks()
-
getDocComments
public XWPFComments getDocComments()
Get Comments- Returns:
- comments
-
getCommentByID
public XWPFComment getCommentByID(String id)
-
getComments
public XWPFComment[] getComments()
-
getPartById
public PackagePart getPartById(String id)
Get the document part that's defined as the given relationship of the core document.
-
getHeaderFooterPolicy
public XWPFHeaderFooterPolicy getHeaderFooterPolicy()
Returns the policy on headers and footers, which also provides a way to get at them.
-
createHeaderFooterPolicy
public XWPFHeaderFooterPolicy createHeaderFooterPolicy()
-
createHeader
public XWPFHeader createHeader(HeaderFooterType type)
Create a header of the given type- Parameters:
type-HeaderFooterTypeenum- Returns:
- object of type
XWPFHeader
-
createFooter
public XWPFFooter createFooter(HeaderFooterType type)
Create a footer of the given type- Parameters:
type-HeaderFooterTypeenum- Returns:
- object of type
XWPFFooter
-
getStyle
@Internal public org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles getStyle() throws XmlException, IOException
Returns the styles object used- Throws:
XmlExceptionIOException
-
getAllEmbeddedParts
public List<PackagePart> getAllEmbeddedParts() throws OpenXML4JException
Get the document's embedded files.- Specified by:
getAllEmbeddedPartsin classPOIXMLDocument- Returns:
- the document's embedded files
- Throws:
OpenXML4JException- if the embedded parts can't be determined
-
getParagraphPos
public int getParagraphPos(int pos)
Look up the paragraph at the specified position in the body elements list and return this paragraphs position in the paragraphs list- Parameters:
pos- The position of the relevant paragraph in the body elements list- Returns:
- the position of the paragraph in the paragraphs list, if there is a paragraph at the position in the bodyelements list. Else it will return -1
-
getTablePos
public int getTablePos(int pos)
get with the position of a table in the bodyelement array list the position of this table in the table array list- Parameters:
pos- position of the table in the bodyelement array list- Returns:
- if there is a table at the position in the bodyelement array list, else it will return null.
-
insertNewParagraph
public XWPFParagraph insertNewParagraph(XmlCursor cursor)
Add a new paragraph at position of the cursor. The cursor must be on theXmlCursor.TokenType.STARTtag of an subelement of the documents body. When this method is done, the cursor passed as parameter points to theXmlCursor.TokenType.ENDof the newly inserted paragraph.- Specified by:
insertNewParagraphin interfaceIBody- Parameters:
cursor- The cursor-position where the new paragraph should be added.- Returns:
- the
XWPFParagraphobject representing the newly inserted CTP object
-
insertNewTbl
public XWPFTable insertNewTbl(XmlCursor cursor)
Description copied from interface:IBodyinserts a new Table at the cursor position.- Specified by:
insertNewTblin interfaceIBody
-
getPosOfParagraph
public int getPosOfParagraph(XWPFParagraph p)
Get the position of the paragraph, within the list of all the body elements.- Parameters:
p- The paragraph to find- Returns:
- The location, or -1 if the paragraph couldn't be found
-
getPosOfTable
public int getPosOfTable(XWPFTable t)
Get the position of the table, within the list of all the body elements.- Parameters:
t- The table to find- Returns:
- The location, or -1 if the table couldn't be found
-
commit
protected void commit() throws IOExceptioncommit and saves the document- Overrides:
commitin classPOIXMLDocumentPart- Throws:
IOException- a subclass may throw an IOException if the changes can't be committed
-
createParagraph
public XWPFParagraph createParagraph()
Appends a new paragraph to this document- Returns:
- a new paragraph
-
createComments
public XWPFComments createComments()
Creates an empty comments for the document if one does not already exist- Returns:
- comments
-
createNumbering
public XWPFNumbering createNumbering()
Creates an empty numbering if one does not already exist and sets the numbering member- Returns:
- numbering
-
createStyles
public XWPFStyles createStyles()
Creates an empty styles for the document if one does not already exist- Returns:
- styles
-
createFootnotes
public XWPFFootnotes createFootnotes()
Creates an empty footnotes element for the document if one does not already exist- Returns:
- footnotes
-
addFootnote
@Internal public XWPFFootnote addFootnote(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn note)
Add a CTFtnEdn footnote to the document.- Parameters:
note- CTFtnEnd to be added.- Returns:
- New
XWPFFootnote
-
addEndnote
@Internal public XWPFEndnote addEndnote(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn note)
Add a CTFtnEdn endnote to the document.- Parameters:
note- CTFtnEnd to be added.- Returns:
- New
XWPFEndnote
-
removeBodyElement
public boolean removeBodyElement(int pos)
remove a BodyElement from bodyElements array list- Returns:
- true if removing was successfully, else return false
-
setParagraph
public void setParagraph(XWPFParagraph paragraph, int pos)
copies content of a paragraph to a existing paragraph in the list paragraphs at position pos
-
getLastParagraph
public XWPFParagraph getLastParagraph()
- Returns:
- the LastParagraph of the document
-
createTable
public XWPFTable createTable()
Create an empty table with one row and one column as default.- Returns:
- a new table
-
createTable
public XWPFTable createTable(int rows, int cols)
Create an empty table with a number of rows and cols specified
-
createTOC
public void createTOC()
-
setTable
public void setTable(int pos, XWPFTable table)Replace content of table in array tables at position pos with a
-
isEnforcedProtection
public boolean isEnforcedProtection()
Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
sample snippet from settings.xml<w:settings ... > <w:documentProtection w:edit="readOnly" w:enforcement="1"/>- Returns:
- true if documentProtection is enforced with option any
-
isEnforcedReadonlyProtection
public boolean isEnforcedReadonlyProtection()
Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is readOnly (w:edit="readOnly")
sample snippet from settings.xml<w:settings ... > <w:documentProtection w:edit="readOnly" w:enforcement="1"/>- Returns:
- true if documentProtection is enforced with option readOnly
-
isEnforcedFillingFormsProtection
public boolean isEnforcedFillingFormsProtection()
Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is forms (w:edit="forms")
sample snippet from settings.xml<w:settings ... > <w:documentProtection w:edit="forms" w:enforcement="1"/>- Returns:
- true if documentProtection is enforced with option forms
-
isEnforcedCommentsProtection
public boolean isEnforcedCommentsProtection()
Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is comments (w:edit="comments")
sample snippet from settings.xml<w:settings ... > <w:documentProtection w:edit="comments" w:enforcement="1"/>- Returns:
- true if documentProtection is enforced with option comments
-
isEnforcedTrackedChangesProtection
public boolean isEnforcedTrackedChangesProtection()
Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is trackedChanges (w:edit="trackedChanges")
sample snippet from settings.xml<w:settings ... > <w:documentProtection w:edit="trackedChanges" w:enforcement="1"/>- Returns:
- true if documentProtection is enforced with option trackedChanges
-
isEnforcedUpdateFields
public boolean isEnforcedUpdateFields()
-
enforceReadonlyProtection
public void enforceReadonlyProtection()
Enforces the readOnly protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to readOnly (w:edit="readOnly")
sample snippet from settings.xml<w:settings ... > <w:documentProtection w:edit="readOnly" w:enforcement="1"/>
-
enforceReadonlyProtection
public void enforceReadonlyProtection(String password, HashAlgorithm hashAlgo)
Enforces the readOnly protection with a password.
sample snippet from settings.xml<w:documentProtection w:edit="readOnly" w:enforcement="1" w:cryptProviderType="rsaAES" w:cryptAlgorithmClass="hash" w:cryptAlgorithmType="typeAny" w:cryptAlgorithmSid="14" w:cryptSpinCount="100000" w:hash="..." w:salt="...." />- Parameters:
password- the plaintext password, if null no password will be appliedhashAlgo- the hash algorithm - only md2, m5, sha1, sha256, sha384 and sha512 are supported. if null, it will default default to sha1
-
enforceFillingFormsProtection
public void enforceFillingFormsProtection()
Enforce the Filling Forms protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to forms (w:edit="forms")
sample snippet from settings.xml<w:settings ... > <w:documentProtection w:edit="forms" w:enforcement="1"/>
-
enforceFillingFormsProtection
public void enforceFillingFormsProtection(String password, HashAlgorithm hashAlgo)
Enforce the Filling Forms protection.
sample snippet from settings.xml<w:documentProtection w:edit="forms" w:enforcement="1" w:cryptProviderType="rsaAES" w:cryptAlgorithmClass="hash" w:cryptAlgorithmType="typeAny" w:cryptAlgorithmSid="14" w:cryptSpinCount="100000" w:hash="..." w:salt="...." />- Parameters:
password- the plaintext password, if null no password will be appliedhashAlgo- the hash algorithm - only md2, m5, sha1, sha256, sha384 and sha512 are supported. if null, it will default default to sha1
-
enforceCommentsProtection
public void enforceCommentsProtection()
Enforce the Comments protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to comments (w:edit="comments")
sample snippet from settings.xml<w:settings ... > <w:documentProtection w:edit="comments" w:enforcement="1"/>
-
enforceCommentsProtection
public void enforceCommentsProtection(String password, HashAlgorithm hashAlgo)
Enforce the Comments protection.
sample snippet from settings.xml<w:documentProtection w:edit="comments" w:enforcement="1" w:cryptProviderType="rsaAES" w:cryptAlgorithmClass="hash" w:cryptAlgorithmType="typeAny" w:cryptAlgorithmSid="14" w:cryptSpinCount="100000" w:hash="..." w:salt="...." />- Parameters:
password- the plaintext password, if null no password will be appliedhashAlgo- the hash algorithm - only md2, m5, sha1, sha256, sha384 and sha512 are supported. if null, it will default default to sha1
-
enforceTrackedChangesProtection
public void enforceTrackedChangesProtection()
Enforce the Tracked Changes protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to trackedChanges (w:edit="trackedChanges")
sample snippet from settings.xml<w:settings ... > <w:documentProtection w:edit="trackedChanges" w:enforcement="1"/>
-
enforceTrackedChangesProtection
public void enforceTrackedChangesProtection(String password, HashAlgorithm hashAlgo)
Enforce the Tracked Changes protection.
sample snippet from settings.xml<w:documentProtection w:edit="trackedChanges" w:enforcement="1" w:cryptProviderType="rsaAES" w:cryptAlgorithmClass="hash" w:cryptAlgorithmType="typeAny" w:cryptAlgorithmSid="14" w:cryptSpinCount="100000" w:hash="..." w:salt="...." />- Parameters:
password- the plaintext password, if null no password will be appliedhashAlgo- the hash algorithm - only md2, m5, sha1, sha256, sha384 and sha512 are supported. if null, it will default default to sha1
-
validateProtectionPassword
public boolean validateProtectionPassword(String password)
Validates the existing password- Returns:
- true, only if password was set and equals, false otherwise
-
removeProtectionEnforcement
public void removeProtectionEnforcement()
Remove protection enforcement.
In the documentProtection tag inside settings.xml file
it sets the value of enforcement to "0" (w:enforcement="0")
-
enforceUpdateFields
public void enforceUpdateFields()
Enforces fields update on document open (in Word). In the settings.xml file
sets the updateSettings value to true (w:updateSettings w:val="true")NOTICES:
- Causing Word to ask on open: "This document contains fields that may refer to other files. Do you want to update the fields in this document?" (if "Update automatic links at open" is enabled)
- Flag is removed after saving with changes in Word
-
isTrackRevisions
public boolean isTrackRevisions()
Check if revision tracking is turned on.- Returns:
trueif revision tracking is turned on
-
setTrackRevisions
public void setTrackRevisions(boolean enable)
Enable or disable revision tracking.- Parameters:
enable-trueto turn on revision tracking,falseto turn off revision tracking
-
getZoomPercent
public long getZoomPercent()
Returns the current zoom factor in percent values, i.e. 100 is normal zoom.- Returns:
- A percent value denoting the current zoom setting of this document.
-
setZoomPercent
public void setZoomPercent(long zoomPercent)
Set the zoom setting as percent value, i.e. 100 is normal zoom.- Parameters:
zoomPercent- A percent value denoting the zoom setting for this document.
-
getEvenAndOddHeadings
public boolean getEvenAndOddHeadings()
Returns the even-and-odd-headings setting- Returns:
- True or false indicating whether or not separate even and odd headings is turned on.
-
setEvenAndOddHeadings
public void setEvenAndOddHeadings(boolean enable)
Sets the even-and-odd-headings setting- Parameters:
enable- Set to true to turn on separate even and odd headings.
-
getMirrorMargins
public boolean getMirrorMargins()
Returns the mirror margins setting- Returns:
- True or false indicating whether or not mirror margins is turned on.
-
setMirrorMargins
public void setMirrorMargins(boolean enable)
Sets the mirror margins setting- Parameters:
enable- Set to true to turn on mirror margins.
-
insertTable
public void insertTable(int pos, XWPFTable table)inserts an existing XWPFTable to the arrays bodyElements and tables- Specified by:
insertTablein interfaceIBody
-
getAllPictures
public List<XWPFPictureData> getAllPictures()
Returns all Pictures, which are referenced from the document itself.- Returns:
- a
ListofXWPFPictureData. The returnedListis unmodifiable. Use #a
-
getAllPackagePictures
public List<XWPFPictureData> getAllPackagePictures()
- Returns:
- all Pictures in this package
-
getSettings
public XWPFSettings getSettings()
- Returns:
- document level settings
- Since:
- POI 5.2.1
-
addPictureData
public String addPictureData(byte[] pictureData, int format) throws InvalidFormatException
Adds a picture to the document.- Parameters:
pictureData- The picture dataformat- the format of the picture, see constants inDocument- Returns:
- the index to this picture (0 based), the added picture can be
obtained from
getAllPictures(). - Throws:
InvalidFormatException- if the format is not known- See Also:
addPictureData(byte[], PictureType)
-
addPictureData
public String addPictureData(byte[] pictureData, PictureType pictureType) throws InvalidFormatException
Adds a picture to the document.- Parameters:
pictureData- The picture datapictureType- thePictureType- Returns:
- the index to this picture (0 based), the added picture can be
obtained from
getAllPictures(). - Throws:
InvalidFormatException- if the format is not known- Since:
- POI 5.2.3
-
addPictureData
public String addPictureData(InputStream is, int format) throws InvalidFormatException
Adds a picture to the document.- Parameters:
is- The picture dataformat- the format of the picture, see constants inDocument- Returns:
- the index to this picture (0 based), the added picture can be
obtained from
getAllPictures(). - Throws:
InvalidFormatException- if the format is not known- See Also:
addPictureData(InputStream, PictureType)
-
addPictureData
public String addPictureData(InputStream is, PictureType pictureType) throws InvalidFormatException
Adds a picture to the document.- Parameters:
is- The picture datapictureType- thePictureType- Returns:
- the index to this picture (0 based), the added picture can be
obtained from
getAllPictures(). - Throws:
InvalidFormatException- if the pictureType is not known- Since:
- POI 5.2.3
-
getNextPicNameNumber
public int getNextPicNameNumber(int format) throws InvalidFormatExceptionget the next free ImageNumber- Parameters:
format- the format of the picture, see constants inDocument- Returns:
- the next free ImageNumber
- Throws:
InvalidFormatException- If the format of the picture is not known.- See Also:
getNextPicNameNumber(PictureType)
-
getNextPicNameNumber
public int getNextPicNameNumber(PictureType pictureType) throws InvalidFormatException
get the next free ImageNumber- Parameters:
pictureType- thePictureType- Returns:
- the next free ImageNumber
- Throws:
InvalidFormatException- If the pictureType of the picture is not known.- Since:
- POI 5.2.3
-
getPictureDataByID
public XWPFPictureData getPictureDataByID(String blipID)
returns the PictureData by blipID- Returns:
- XWPFPictureData of a specificID
-
getNumbering
public XWPFNumbering getNumbering()
getNumbering- Returns:
- numbering
-
getStyles
public XWPFStyles getStyles()
get Styles- Returns:
- styles for this document
-
getParagraph
public XWPFParagraph getParagraph(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP p)
Description copied from interface:IBodyReturns the paragraph corresponding to the providedCTP.- Specified by:
getParagraphin interfaceIBody- Parameters:
p- is instance of CTP and is searching for an XWPFParagraph- Returns:
- The paragraph corresponding to the
CTP, ornullif there is no corresponding paragraph in this body.
-
getTable
public XWPFTable getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl ctTbl)
get a table by its CTTbl-Object
-
getTablesSpliterator
public Spliterator<XWPFTable> getTablesSpliterator()
- Since:
- POI 5.2.0
-
getParagraphsIterator
public Iterator<XWPFParagraph> getParagraphsIterator()
-
getParagraphsSpliterator
public Spliterator<XWPFParagraph> getParagraphsSpliterator()
- Since:
- POI 5.2.0
-
getParagraphArray
public XWPFParagraph getParagraphArray(int pos)
Returns the paragraph that of position pos- Specified by:
getParagraphArrayin interfaceIBody
-
getPart
public POIXMLDocumentPart getPart()
returns the Part, to which the body belongs, which you need for adding relationship to other parts Actually it is needed of the class XWPFTableCell. Because you have to know to which part the tableCell belongs.
-
getPartType
public BodyType getPartType()
get the PartType of the body, for example DOCUMENT, HEADER, FOOTER, FOOTNOTE,- Specified by:
getPartTypein interfaceIBody- Returns:
- the PartType of the body
-
getTableCell
public XWPFTableCell getTableCell(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc cell)
get the TableCell which belongs to the TableCell- Specified by:
getTableCellin interfaceIBody
-
getXWPFDocument
public XWPFDocument getXWPFDocument()
Description copied from interface:IBodyReturn XWPFDocument- Specified by:
getXWPFDocumentin interfaceIBody
-
createChart
public XWPFChart createChart() throws InvalidFormatException, IOException
This method is used to create template for chart XML no need to read MS-Word file and modify charts- Returns:
- This method return object of XWPFChart Object with default height and width
- Throws:
InvalidFormatExceptionIOException- Since:
- POI 4.0.0
-
createChart
public XWPFChart createChart(int width, int height) throws InvalidFormatException, IOException
This method is used to create template for chart XML no need to read MS-Word file and modify charts- Parameters:
width- width of chart in documentheight- height of chart in document- Returns:
- This method return object of XWPFChart
- Throws:
InvalidFormatExceptionIOException- Since:
- POI 4.0.0
-
createChart
public XWPFChart createChart(XWPFRun run, int width, int height) throws InvalidFormatException, IOException
- Parameters:
run- in which the chart will be attached.width- in EMU.height- in EMU.- Returns:
- the new chart.
- Throws:
InvalidFormatExceptionIOException- Since:
- POI 4.1.2
-
createFootnote
public XWPFFootnote createFootnote()
Create a new footnote and add it to the document.- Returns:
- New XWPFFootnote.
- Since:
- 4.0.0
-
removeFootnote
public boolean removeFootnote(int pos)
Remove the specified footnote if present.- Parameters:
pos- Array position of the footnote to be removed.- Returns:
- True if the footnote was removed.
- Since:
- 4.0.0
-
createEndnote
public XWPFEndnote createEndnote()
Create a new end note and add it to the document.- Returns:
- New
XWPFEndnote. - Since:
- 4.0.0
-
createEndnotes
public XWPFEndnotes createEndnotes()
-
getEndnotes
public List<XWPFEndnote> getEndnotes()
Gets the list of end notes for the document.- Returns:
- List, possibly empty, of
XWPFEndnotes.
-
removeEndnote
public boolean removeEndnote(int pos)
Remove the specified end note if present.- Parameters:
pos- Array position of the end note to be removed.- Returns:
- True if the end note was removed.
- Since:
- 4.0.0
-
-