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

public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBody
Parent of XWPF headers and footers
  • Constructor Details

  • Method Details

    • _getHdrFtr

      @Internal public CTHdrFtr _getHdrFtr()
    • getBodyElements

      public List<IBodyElement> 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 interface IBody
    • getParagraphs

      public List<XWPFParagraph> 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 interface IBody
    • getTables

      public List<XWPFTable> getTables() throws ArrayIndexOutOfBoundsException
      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 interface IBody
      Throws:
      ArrayIndexOutOfBoundsException
    • getText

      public String getText()
      Returns the textual content of the header/footer, by flattening out the text of its paragraph(s)
    • setHeaderFooter

      public void setHeaderFooter(CTHdrFtr headerFooter)
      set a new headerFooter
    • getTable

      public XWPFTable getTable(CTTbl ctTable)
      if there is a corresponding XWPFTable of the parameter ctTable in the tableList of this header the method will return this table if there is no corresponding XWPFTable the method will return null
      Specified by:
      getTable in interface IBody
    • getParagraph

      public XWPFParagraph getParagraph(CTP p)
      Description copied from interface: IBody
      Returns the paragraph corresponding to the provided CTP.
      Specified by:
      getParagraph in interface IBody
      Parameters:
      p - is instance of CTP and is searching for an XWPFParagraph
      Returns:
      The paragraph corresponding to the CTP, or null if there is no corresponding paragraph in this body.
    • getParagraphArray

      public XWPFParagraph getParagraphArray(int pos)
      Returns the paragraph that holds the text of the header or footer.
      Specified by:
      getParagraphArray in interface IBody
    • getListParagraph

      public List<XWPFParagraph> getListParagraph()
      get a List of all Paragraphs
      Returns:
      a list of XWPFParagraph
    • getAllPictures

      public List<XWPFPictureData> getAllPictures()
    • getAllPackagePictures

      public List<XWPFPictureData> getAllPackagePictures()
      get all Pictures in this package
      Returns:
      all Pictures in this package
    • addPictureData

      public String addPictureData(byte[] pictureData, int format) throws InvalidFormatException
      Adds a picture to the document.
      Parameters:
      pictureData - The picture data
      format - 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.
      See Also:
    • addPictureData

      public String addPictureData(byte[] pictureData, PictureType pictureType) throws InvalidFormatException
      Adds a picture to the document.
      Parameters:
      pictureData - The picture data
      pictureType - The PictureType 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.
      Since:
      POI 5.2.3
    • addPictureData

      public String addPictureData(InputStream is, int format) throws InvalidFormatException, IOException
      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 - If the format of the picture is not known.
      IOException - If reading the picture-data from the stream fails.
      See Also:
    • addPictureData

      public String addPictureData(InputStream is, PictureType pictureType) throws InvalidFormatException, IOException
      Adds a picture to the document.
      Parameters:
      is - The stream to read image from
      pictureType - The PictureType 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.
      Since:
      POI 5.2.3
    • getPictureDataByID

      public XWPFPictureData getPictureDataByID(String blipID)
      returns the PictureData by blipID
      Returns:
      XWPFPictureData of a specificID
    • createParagraph

      public XWPFParagraph createParagraph()
      Adds a new paragraph at the end of the header or footer
      Returns:
      new XWPFParagraph object
    • createTable

      public XWPFTable createTable(int rows, int cols)
      Adds a new table at the end of the header or footer
      Parameters:
      rows - - number of rows in the table
      cols - - number of columns in the table
      Returns:
      new XWPFTable object
    • removeParagraph

      public void removeParagraph(XWPFParagraph paragraph)
      Removes a specific paragraph from this header / footer
      Parameters:
      paragraph - - XWPFParagraph object to remove
    • removeTable

      public void removeTable(XWPFTable table)
      Removes a specific table from this header / footer
      Parameters:
      table - - XWPFTable object to remove
    • clearHeaderFooter

      public void clearHeaderFooter()
      Clears all paragraphs and tables from this header / footer
    • insertNewParagraph

      public XWPFParagraph insertNewParagraph(XmlCursor cursor)
      add a new paragraph at position of the cursor
      Specified by:
      insertNewParagraph in interface IBody
      Returns:
      the inserted paragraph
    • insertNewTbl

      public XWPFTable insertNewTbl(XmlCursor cursor)
      Description copied from interface: IBody
      inserts a new Table at the cursor position.
      Specified by:
      insertNewTbl in interface IBody
      Returns:
      the inserted table
    • getOwner

      public POIXMLDocumentPart getOwner()
    • getTableArray

      public XWPFTable getTableArray(int pos)
      Returns the table at position pos
      Specified by:
      getTableArray in interface IBody
    • insertTable

      public void insertTable(int pos, XWPFTable table)
      inserts an existing XWPFTable to the arrays bodyElements and tables
      Specified by:
      insertTable in interface IBody
    • readHdrFtr

      public void readHdrFtr()
    • getTableCell

      public XWPFTableCell getTableCell(CTTc cell)
      get the TableCell which belongs to the TableCell
      Specified by:
      getTableCell in interface IBody
    • getXWPFDocument

      public XWPFDocument getXWPFDocument()
      Description copied from interface: IBody
      Return XWPFDocument
      Specified by:
      getXWPFDocument in interface IBody
    • setXWPFDocument

      public void setXWPFDocument(XWPFDocument doc)
    • getPart

      public POIXMLDocumentPart getPart()
      returns the Part, to which the body belongs, which you need for adding relationship to other parts
      Specified by:
      getPart in interface IBody
      Returns:
      the Part, to which the body belongs