Class POIXMLDocument

java.lang.Object
org.apache.poi.ooxml.POIXMLDocumentPart
org.apache.poi.ooxml.POIXMLDocument
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
XMLSlideShow, XmlVisioDocument, XSLFSlideShow, XSSFWorkbook, XWPFDocument

public abstract class POIXMLDocument extends POIXMLDocumentPart implements Closeable
This holds the common functionality for all POI OOXML Document classes.
  • Field Details

  • Method Details

    • openPackage

      public static OPCPackage openPackage(String path) throws IOException
      Wrapper to open a package, which works around shortcomings in java's this() constructor calls
      Parameters:
      path - the path to the document
      Returns:
      the new OPCPackage
      Throws:
      IOException - if there was a problem opening the document
    • getPackage

      public OPCPackage getPackage()
      Get the assigned OPCPackage
      Returns:
      the assigned OPCPackage
    • getProperties

      public POIXMLProperties getProperties()
      Get the document properties. This gives you access to the core ooxml properties, and the extended ooxml properties.
      Returns:
      the document properties
    • getAllEmbeddedParts

      public abstract List<PackagePart> getAllEmbeddedParts() throws OpenXML4JException
      Get the document's embedded files.
      Returns:
      the document's embedded files
      Throws:
      OpenXML4JException - if the embedded parts can't be determined
      Since:
      POI 4.0.0
    • close

      public void close() throws IOException
      Closes the underlying OPCPackage from which this document was read, if there is one

      Once this has been called, no further operations, updates or reads should be performed on the document.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - for writable packages, if an IO exception occur during the saving process.
    • write

      public final void write(OutputStream stream) throws IOException
      Write out this document to an OutputStream. Note - if the Document was opened from a File rather than an InputStream, you must write out to a different file, overwriting via an OutputStream isn't possible. If stream is a FileOutputStream on a networked drive or has a high cost/latency associated with each written byte, consider wrapping the OutputStream in a BufferedOutputStream to improve write performance.
      Parameters:
      stream - - the java OutputStream you wish to write the file to
      Throws:
      IOException - if anything can't be written.