Class XWPFTheme

java.lang.Object
org.apache.poi.ooxml.POIXMLDocumentPart
org.apache.poi.xwpf.usermodel.XWPFTheme

public class XWPFTheme extends POIXMLDocumentPart
A shared style sheet in a .docx document
Since:
5.2.4
  • Constructor Details

    • XWPFTheme

      public XWPFTheme(PackagePart part)
      Construct XWPFStyles from a package part
      Parameters:
      part - the package part holding the data of the styles
    • XWPFTheme

      public XWPFTheme()
      Construct XWPFStyles from scratch for a new document.
  • Method Details

    • importTheme

      public void importTheme(XSLFTheme theme)
    • getCTOfficeStyleSheet

      public org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeStyleSheet getCTOfficeStyleSheet()
      Returns:
      the underlying CTOfficeStyleSheet instance.
      Since:
      6.0.0
    • getName

      public String getName()
      Returns:
      name of this theme, e.g. "Office Theme"
    • setName

      public void setName(String name)
      Set name of this theme
      Parameters:
      name - name of this theme
    • getCTColor

      @Internal public org.openxmlformats.schemas.drawingml.x2006.main.CTColor getCTColor(String name)
      Get a color from the theme's color scheme by name
      Returns:
      a theme color or null if not found
    • getMajorFont

      public String getMajorFont()
      Returns:
      typeface of the major font to use in a document (possibly null). Typically, the major font is used for heading areas of a document.
    • getMinorFont

      public String getMinorFont()
      Returns:
      typeface of the minor font to use in a document (possibly null). Typically, the minor font is used for normal text or paragraph areas.
    • getMajorFontForScript

      public String getMajorFontForScript(String script)
      Parameters:
      script - a 4-letter script code, e.g. "Latn", "Jpan"
      Returns:
      typeface of the major font for the given script (possibly null)
      Since:
      6.0.0
    • getMinorFontForScript

      public String getMinorFontForScript(String script)
      Parameters:
      script - a 4-letter script code, e.g. "Latn", "Jpan"
      Returns:
      typeface of the minor font for the given script (possibly null)
      Since:
      6.0.0
    • onDocumentRead

      protected void onDocumentRead() throws IOException
      Read document
      Overrides:
      onDocumentRead in class POIXMLDocumentPart
      Throws:
      IOException - a subclass may throw an IOException when a document is read
    • commit

      protected void commit() throws IOException
      Description copied from class: POIXMLDocumentPart
      Save the content in the underlying package part. Default implementation is empty meaning that the package part is left unmodified.

      Sub-classes should override and add logic to marshal the "model" into Ooxml4J.

      For example, the code saving a generic XML entry may look as follows:

       protected void commit() throws IOException {
         PackagePart part = getPackagePart();
         try (OutputStream out = part.getOutputStream()) {
           XmlObject bean = getXmlBean(); //the "model" which holds changes in memory
           bean.save(out, DEFAULT_XML_OPTIONS);
         }
       }
       
      Overrides:
      commit in class POIXMLDocumentPart
      Throws:
      IOException - a subclass may throw an IOException if the changes can't be committed
    • setTheme

      public void setTheme(org.openxmlformats.schemas.drawingml.x2006.main.CTOfficeStyleSheet theme)