Package org.apache.poi.xwpf.usermodel
Class XWPFStyles
java.lang.Object
org.apache.poi.ooxml.POIXMLDocumentPart
org.apache.poi.xwpf.usermodel.XWPFStyles
Holds details of built-in, default and user styles, which
apply to tables / paragraphs / lists etc.
Text within one of those with custom stylings has the style
information stored in the
XWPFRun
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
POIXMLDocumentPart.RelationPart
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct XWPFStyles from scratch for a new document.XWPFStyles
(PackagePart part) Construct XWPFStyles from a package part -
Method Summary
Modifier and TypeMethodDescriptionvoid
add a style to the documentprotected void
commit()
Save the content in the underlying package part.protected void
protected org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLanguage
Get the default paragraph style which applies to the documentGet the default style which applies text runs in the documentGet the definition of all the Latent Stylesint
Get style by a styleIDgetStyleWithName
(String styleName) Get the style with the specified name, if any.getStyleWithSameName
(XWPFStyle style) get the style with the same name if this style is not existing, return nullgetUsedStyleList
(XWPFStyle style) get the styles which are related to the parameter style and their relatives this method can be used to copy all styles from one document to another documentprotected void
Read documentvoid
setDefaultFonts
(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts fonts) Sets the default font on ctStyles DocDefaults parameter TODO Replace this with specific setters for each type, possibly on XWPFDefaultRunStylevoid
setEastAsia
(String strEastAsia) Sets the default East Asia spelling language on ctStyles DocDefaults parametervoid
setSpellingLanguage
(String strSpellingLanguage) Sets the default spelling language on ctStyles DocDefaults parametervoid
setStyles
(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles styles) Sets the ctStylesboolean
styleExist
(String styleID) checks whether style with styleID existMethods inherited from class org.apache.poi.ooxml.POIXMLDocumentPart
_invokeOnDocumentRead, addRelation, createRelationship, createRelationship, createRelationship, getNextPartNumber, getPackagePart, getParent, getRelationById, getRelationId, getRelationPartById, getRelationParts, getRelations, getTargetPart, isCommited, onDocumentCreate, onDocumentRemove, onSave, prepareForCommit, read, rebase, removeRelation, removeRelation, removeRelation, setCommited, toString
-
Constructor Details
-
XWPFStyles
Construct XWPFStyles from a package part- Parameters:
part
- the package part holding the data of the styles,- Throws:
IOException
OpenXML4JException
- Since:
- POI 3.14-Beta1
-
XWPFStyles
public XWPFStyles()Construct XWPFStyles from scratch for a new document.
-
-
Method Details
-
onDocumentRead
Read document- Overrides:
onDocumentRead
in classPOIXMLDocumentPart
- Throws:
IOException
- a subclass may throw an IOException when a document is read
-
commit
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(); OutputStream out = part.getOutputStream(); XmlObject bean = getXmlBean(); //the "model" which holds changes in memory bean.save(out, DEFAULT_XML_OPTIONS); out.close(); }
- Overrides:
commit
in classPOIXMLDocumentPart
- Throws:
IOException
- a subclass may throw an IOException if the changes can't be committed
-
ensureDocDefaults
protected void ensureDocDefaults() -
setStyles
public void setStyles(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles styles) Sets the ctStyles- Parameters:
styles
-
-
styleExist
checks whether style with styleID exist- Parameters:
styleID
- styleID of the Style in the style-Document- Returns:
- true if style exist, false if style not exist
-
addStyle
add a style to the document- Parameters:
style
-- Throws:
IOException
-
getStyle
Get style by a styleID- Parameters:
styleID
- styleID of the searched style- Returns:
- style
-
getNumberOfStyles
public int getNumberOfStyles() -
getUsedStyleList
get the styles which are related to the parameter style and their relatives this method can be used to copy all styles from one document to another document- Parameters:
style
-- Returns:
- a list of all styles which were used by this method
-
getCTLanguage
protected org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLanguage getCTLanguage() -
setSpellingLanguage
Sets the default spelling language on ctStyles DocDefaults parameter- Parameters:
strSpellingLanguage
-
-
setEastAsia
Sets the default East Asia spelling language on ctStyles DocDefaults parameter- Parameters:
strEastAsia
-
-
setDefaultFonts
public void setDefaultFonts(org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts fonts) Sets the default font on ctStyles DocDefaults parameter TODO Replace this with specific setters for each type, possibly on XWPFDefaultRunStyle -
getStyleWithSameName
get the style with the same name if this style is not existing, return null -
getDefaultRunStyle
Get the default style which applies text runs in the document -
getDefaultParagraphStyle
Get the default paragraph style which applies to the document -
getLatentStyles
Get the definition of all the Latent Styles -
getStyleWithName
Get the style with the specified name, if any.- Parameters:
styleName
- The name of the style to get, e.g., "Heading 1"- Returns:
XWPFStyle
with the specified name, or null if not found.
-