Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.poi.xwpf.usermodel
Class XWPFDocument

    java.lang.Object
      org.apache.poi.POIXMLDocumentPart
          org.apache.poi.POIXMLDocument
              org.apache.poi.xwpf.usermodel.XWPFDocument

All Implemented Interfaces:
  Document, IBody

    public class XWPFDocument

extends POIXMLDocument
implements Document, IBody

Experimental class to do low level processing of docx files. If you're using these low level classes, then you will almost certainly need to refer to the OOXML specifications from http://www.ecma-international.org/publications/standards/Ecma-376.htm WARNING - APIs expected to change rapidly

Field Summary

Fields inherited from class org.apache.poi.POIXMLDocument
`DOCUMENT_CREATOR, 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.xwpf.usermodel.Document
`PICTURE_TYPE_DIB, PICTURE_TYPE_EMF, PICTURE_TYPE_JPEG, PICTURE_TYPE_PICT, PICTURE_TYPE_PNG, PICTURE_TYPE_WMF`

Constructor Summary
`XWPFDocument()`
`XWPFDocument(java.io.InputStream is)`
`XWPFDocument(OPCPackage pkg)`

Method Summary
`int` | `addPicture(byte[] pictureData, int format)` Adds a picture to the document.
`int` | `addPicture(java.io.InputStream is, int format)` Adds a picture to the document.
`XWPFParagraph` | `createParagraph()` Appends a new paragraph to this document
`XWPFTable` | `createTable()` Create an empty table with one row and one column as default.
`XWPFTable` | `createTable(int rows, int cols)` Create an empty table with a number of rows and cols specified
`void` | `createTOC()`
`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
`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
`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
`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
`java.util.List` | `getAllEmbedds()` Get the document's embedded files.
`java.util.List` | `getAllPackagePictures()`
`java.util.List` | `getAllPictures()`
`java.util.List` | `getBodyElements()` returns an Iterator with paragraphs and tables
`XWPFComment` | `getCommentByID(java.lang.String id)`
`XWPFComment[]` | `getComments()`
`org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1` | `getDocument()` Returns the low level document base object
`XWPFFootnote` | `getEndnoteByID(int id)`
`XWPFFooter` | `getFooterArray(int pos)`
`java.util.List` | `getFooterList()`
`XWPFFootnote` | `getFootnoteByID(int id)`
`java.util.Collection` | `getFootnotes()`
`XWPFHeader` | `getHeaderArray(int pos)`
`XWPFHeaderFooterPolicy` | `getHeaderFooterPolicy()` Returns the policy on headers and footers, which also provides a way to get at them.
`java.util.List` | `getHeaderList()`
`XWPFHyperlink` | `getHyperlinkByID(java.lang.String id)`
`XWPFHyperlink[]` | `getHyperlinks()`
`XWPFParagraph` | `getLastParagraph()`
`int` | `getNextPicNameNumber(int format)` get the next free ImageNumber
`XWPFNumbering` | `getNumbering()` getNumbering
`XWPFParagraph` | `getParagraph(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP p)` get the paragraph with the CTP class p
`XWPFParagraph` | `getParagraphArray(int pos)` Returns the paragraph that of position pos
`int` | `getParagraphPos(int pos)` get with the position of a Paragraph in the bodyelement array list the position of this paragraph in the paragraph array list
`java.util.List` | `getParagraphs()` Returns the paragraph(s) that holds the text of the header or footer.
`java.util.Iterator` | `getParagraphsIterator()`
`IBody` | `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.
`PackagePart` | `getPartById(java.lang.String id)` Get the document part that's defined as the given relationship of the core document.
`BodyType` | `getPartType()` get the PartType of the body, for example DOCUMENT, HEADER, FOOTER, FOOTNOTE,
`XWPFPictureData` | `getPictureDataByID(java.lang.String blipID)` returns the PictureData by blipID
`java.lang.Integer` | `getPosOfParagraph(XWPFParagraph p)` get position of the paragraph
`java.lang.Integer` | `getPosOfTable(XWPFTable t)`
`org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles` | `getStyle()` Returns the styles object used
`XWPFStyles` | `getStyles()` get Styles
`XWPFTable` | `getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl ctTbl)` get a table by its CTTbl-Object
`XWPFTable` | `getTableArray(int pos)` Returns the table at position pos
`XWPFTableCell` | `getTableCell(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc cell)` get the TableCell which belongs to the TableCell
`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
`java.util.List` | `getTables()` Return the table(s) that holds the text of the IBodyPart, for complex cases where a paragraph isn't used.
`java.util.Iterator` | `getTablesIterator()`
`java.lang.String` | `getTblStyle(XWPFTable table)`
`XWPFParagraph` | `insertNewParagraph(org.apache.xmlbeans.XmlCursor cursor)` add a new paragraph at position of the cursor
`XWPFTable` | `insertNewTbl(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 tables
`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
`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
`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
`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
`boolean` | `removeBodyElement(int pos)` remove a BodyElement from bodyElements array list
`void` | `removeProtectionEnforcement()` Remove protection enforcement. In the documentProtection tag inside settings.xml file it sets the value of enforcement to "0" (w:enforcement="0")
`void` | `setParagraph(XWPFParagraph paragraph, int pos)` copies content of a paragraph to a existing paragraph in the list paragraphs at position pos
`void` | `setTable(int pos, XWPFTable table)` Replace content of table in array tables at position pos with a

Methods inherited from class org.apache.poi.POIXMLDocument
`getPackage, getProperties, hasOOXMLHeader, openPackage, write`

Methods inherited from class org.apache.poi.POIXMLDocumentPart
`createRelationship, createRelationship, getPackagePart, getPackageRelationship, getParent, getRelations, removeRelation, toString`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### XWPFDocument

    public XWPFDocument(OPCPackage pkg)
                 throws java.io.IOException

Throws:
  `java.io.IOException`

### XWPFDocument

    public XWPFDocument(java.io.InputStream is)
                 throws java.io.IOException

Throws:
  `java.io.IOException`

### XWPFDocument

    public XWPFDocument()

Method Detail

### getDocument

    public org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1 getDocument()

  Returns the low level document base object

### getBodyElements

    public java.util.List getBodyElements()

  returns an Iterator with paragraphs and tables

  Specified by:
    `getBodyElements` in interface `IBody`
  See Also:
    `IBody.getBodyElements()`

### getParagraphs

    public java.util.List getParagraphs()

  Description copied from interface: `IBody`
  Returns the paragraph(s) that holds the text of the header or footer.

  Specified by:
    `getParagraphs` in interface `IBody`
  See Also:
    `IBody.getParagraphs()`

### getTables

    public java.util.List getTables()

  Description copied from interface: `IBody`
  Return the table(s) that holds the text of the IBodyPart, for complex cases where a paragraph isn't used.

  Specified by:
    `getTables` in interface `IBody`
  See Also:
    `IBody.getTables()`

### getTableArray

    public XWPFTable getTableArray(int pos)

  Description copied from interface: `IBody`
  Returns the table at position pos

  Specified by:
    `getTableArray` in interface `IBody`
  See Also:
    `IBody.getTableArray(int)`

### getFooterList

    public java.util.List getFooterList()

  Returns:
    the list of footers

### getFooterArray

    public XWPFFooter getFooterArray(int pos)

### getHeaderList

    public java.util.List getHeaderList()

  Returns:
    the list of headers

### getHeaderArray

    public XWPFHeader getHeaderArray(int pos)

### getTblStyle

    public java.lang.String getTblStyle(XWPFTable table)

### getHyperlinkByID

    public XWPFHyperlink getHyperlinkByID(java.lang.String id)

### getFootnoteByID

    public XWPFFootnote getFootnoteByID(int id)

### getEndnoteByID

    public XWPFFootnote getEndnoteByID(int id)

### getFootnotes

    public java.util.Collection getFootnotes()

### getHyperlinks

    public XWPFHyperlink[] getHyperlinks()

### getCommentByID

    public XWPFComment getCommentByID(java.lang.String id)

### getComments

    public XWPFComment[] getComments()

### getPartById

    public PackagePart getPartById(java.lang.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.

### getStyle

    public org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles getStyle()
                                                                             throws org.apache.xmlbeans.XmlException,
                                                                                    java.io.IOException

  Returns the styles object used

  Throws:
    `org.apache.xmlbeans.XmlException`
    `java.io.IOException`

### getAllEmbedds

    public java.util.List getAllEmbedds()
                                 throws OpenXML4JException

  Get the document's embedded files.

  Specified by:
    `getAllEmbedds` in class `POIXMLDocument`
  Throws:
    `OpenXML4JException`

### getParagraphPos

    public int getParagraphPos(int pos)

  get with the position of a Paragraph in the bodyelement array list the position of this paragraph in the paragraph array list

  Parameters:
    `pos` - position of the paragraph in the bodyelement array list
  Returns:
    if there is a paragraph at the position in the bodyelement array 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(org.apache.xmlbeans.XmlCursor cursor)

  add a new paragraph at position of the cursor

  Specified by:
    `insertNewParagraph` in interface `IBody`
  Parameters:
    `cursor` -

### insertNewTbl

    public XWPFTable insertNewTbl(org.apache.xmlbeans.XmlCursor cursor)

  Description copied from interface: `IBody`
  inserts a new Table at the cursor position.

  Specified by:
    `insertNewTbl` in interface `IBody`

### getPosOfParagraph

    public java.lang.Integer getPosOfParagraph(XWPFParagraph p)

  get position of the paragraph

  Parameters:
    `p` -

### getPosOfTable

    public java.lang.Integer getPosOfTable(XWPFTable t)

### createParagraph

    public XWPFParagraph createParagraph()

  Appends a new paragraph to this document

  Returns:
    a new paragraph

### removeBodyElement

    public boolean removeBodyElement(int pos)

  remove a BodyElement from bodyElements array list

  Parameters:
    `pos` -
  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

  Parameters:
    `paragraph` -
    `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

  Parameters:
    `rows` -
    `cols` -
  Returns:
    table

### createTOC

    public void createTOC()

### setTable

    public void setTable(int pos,
                         XWPFTable table)

  Replace content of table in array tables at position pos with a

  Parameters:
    `pos` -
    `table` -

### 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

### 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"/>

### 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"/>

### 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"/>

### 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"/>

### 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")

### insertTable

    public void insertTable(int pos,
                            XWPFTable table)

  inserts an existing XWPFTable to the arrays bodyElements and tables

  Specified by:
    `insertTable` in interface `IBody`
  Parameters:
    `pos` -
    `table` -

### getAllPictures

    public java.util.List getAllPictures()

### getAllPackagePictures

    public java.util.List getAllPackagePictures()

  Returns:
    all Pictures in this package

### addPicture

    public int addPicture(java.io.InputStream is,
                          int format)
                   throws java.io.IOException,
                          InvalidFormatException

  Adds a picture to the document.

  Parameters:
    `is` - The stream to read image from
    `format` - The format of the picture.
  Returns:
    the index to this picture (0 based), the added picture can be obtained from `getAllPictures()` .
  Throws:
    `InvalidFormatException`
    `java.io.IOException`

### addPicture

    public int addPicture(byte[] pictureData,
                          int format)
                   throws InvalidFormatException

  Adds a picture to the document.

  Parameters:
    `pictureData` - The bytes to read image from
    `format` - The format of the picture.
  Returns:
    the index to this picture (0 based), the added picture can be obtained from `getAllPictures()` .
  Throws:
    `InvalidFormatException`

### getNextPicNameNumber

    public int getNextPicNameNumber(int format)
                             throws InvalidFormatException

  get the next free ImageNumber

  Parameters:
    `format` -
  Returns:
    the next free ImageNumber
  Throws:
    `InvalidFormatException`

### getPictureDataByID

    public XWPFPictureData getPictureDataByID(java.lang.String blipID)

  returns the PictureData by blipID

  Parameters:
    `blipID` -
  Returns:
    XWPFPictureData of a specificID
  Throws:
    `java.lang.Exception`

### 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)

  get the paragraph with the CTP class p

  Specified by:
    `getParagraph` in interface `IBody`
  Parameters:
    `p` -
  Returns:
    the paragraph with the CTP class p

### getTable

    public XWPFTable getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl ctTbl)

  get a table by its CTTbl-Object

  Specified by:
    `getTable` in interface `IBody`
  Parameters:
    `ctTbl` -
  Returns:
    a table by its CTTbl-Object or null
  See Also:
    `IBody.getTable(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl)`

### getTablesIterator

    public java.util.Iterator getTablesIterator()

### getParagraphsIterator

    public java.util.Iterator getParagraphsIterator()

### getParagraphArray

    public XWPFParagraph getParagraphArray(int pos)

  Returns the paragraph that of position pos

  Specified by:
    `getParagraphArray` in interface `IBody`
  See Also:
    `IBody.getParagraphArray(int)`

### getPart

    public IBody 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.

  Specified by:
    `getPart` in interface `IBody`
  Returns:
    the Part, to which the body belongs
  See Also:
    `IBody.getPart()`

### getPartType

    public BodyType getPartType()

  get the PartType of the body, for example DOCUMENT, HEADER, FOOTER, FOOTNOTE,

  Specified by:
    `getPartType` in interface `IBody`
  Returns:
    the PartType of the body
  See Also:
    `IBody.getPartType()`

### getTableCell

    public XWPFTableCell getTableCell(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc cell)

  get the TableCell which belongs to the TableCell

  Specified by:
    `getTableCell` in interface `IBody`
  Parameters:
    `cell` -

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD