/** * get the styles which are related to parameter style * * @param style * @return all Styles of the parameterList */ private List<XWPFStyle> getUsedStyleList(XWPFStyle style, List<XWPFStyle> usedStyleList) { String basisStyleID = style.getBasisStyleID(); XWPFStyle basisStyle = getStyle(basisStyleID); if ((basisStyle != null) && (!usedStyleList.contains(basisStyle))) { usedStyleList.add(basisStyle); getUsedStyleList(basisStyle, usedStyleList); } String linkStyleID = style.getLinkStyleID(); XWPFStyle linkStyle = getStyle(linkStyleID); if ((linkStyle != null) && (!usedStyleList.contains(linkStyle))) { usedStyleList.add(linkStyle); getUsedStyleList(linkStyle, usedStyleList); } String nextStyleID = style.getNextStyleID(); XWPFStyle nextStyle = getStyle(nextStyleID); if ((nextStyle != null) && (!usedStyleList.contains(nextStyle))) { usedStyleList.add(linkStyle); getUsedStyleList(linkStyle, usedStyleList); } return usedStyleList; }
/** * Read document */ @Override protected void onDocumentRead() throws IOException { StylesDocument stylesDoc; InputStream is = getPackagePart().getInputStream(); try { stylesDoc = StylesDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); setStyles(stylesDoc.getStyles()); latentStyles = new XWPFLatentStyles(ctStyles.getLatentStyles(), this); } catch (XmlException e) { throw new POIXMLException("Unable to read styles", e); } finally { is.close(); } }
/** * Get the default paragraph style which applies to the document */ public XWPFDefaultParagraphStyle getDefaultParagraphStyle() { ensureDocDefaults(); return defaultParaStyle; }
protected XWPFStyle getXWPFStyle( String styleID ) { if ( styleID == null ) return null; else return document.getStyles().getStyle( styleID ); }
/** * Creates an empty styles for the document if one does not already exist * * @return styles */ public XWPFStyles createStyles() { if (styles == null) { StylesDocument stylesDoc = StylesDocument.Factory.newInstance(); XWPFRelation relation = XWPFRelation.STYLES; int i = getRelationIndex(relation); XWPFStyles wrapper = (XWPFStyles) createRelationship(relation, XWPFFactory.getInstance(), i); wrapper.setStyles(stylesDoc.addNewStyles()); styles = wrapper; } return styles; }
@Override protected void commit() throws IOException { if (ctStyles == null) { throw new IllegalStateException("Unable to write out styles that were never read in!"); } XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTStyles.type.getName().getNamespaceURI(), "styles")); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); ctStyles.save(out, xmlOptions); out.close(); }
/** * 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 * * @param style * @return a list of all styles which were used by this method */ public List<XWPFStyle> getUsedStyleList(XWPFStyle style) { List<XWPFStyle> usedStyleList = new ArrayList<>(); usedStyleList.add(style); return getUsedStyleList(style, usedStyleList); }
if (relation.equals(XWPFRelation.STYLES.getRelation())) { this.styles = (XWPFStyles) p; this.styles.onDocumentRead(); } else if (relation.equals(XWPFRelation.NUMBERING.getRelation())) { this.numbering = (XWPFNumbering) p;
protected XWPFStyle getXWPFStyle( String styleID ) { if ( styleID == null ) return null; else return document.getStyles().getStyle( styleID ); }
XWPFDocument document = new XWPFDocument(); XWPFDocument template = new XWPFDocument(new FileInputStream(new File("Template.dotx"))); XWPFStyles newStyles = document.createStyles(); newStyles.setStyles(template.getStyle());
@Override protected void commit() throws IOException { if (ctStyles == null) { throw new IllegalStateException("Unable to write out styles that were never read in!"); } XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTStyles.type.getName().getNamespaceURI(), "styles")); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); ctStyles.save(out, xmlOptions); out.close(); }
/** * 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 * * @param style * @return a list of all styles which were used by this method */ public List<XWPFStyle> getUsedStyleList(XWPFStyle style) { List<XWPFStyle> usedStyleList = new ArrayList<>(); usedStyleList.add(style); return getUsedStyleList(style, usedStyleList); }
if (relation.equals(XWPFRelation.STYLES.getRelation())) { this.styles = (XWPFStyles) p; this.styles.onDocumentRead(); } else if (relation.equals(XWPFRelation.NUMBERING.getRelation())) { this.numbering = (XWPFNumbering) p;
protected XWPFStyle getXWPFStyle( String styleID ) { if ( styleID == null ) return null; else return document.getStyles().getStyle( styleID ); }
/** * get the styles which are related to parameter style * * @param style * @return all Styles of the parameterList */ private List<XWPFStyle> getUsedStyleList(XWPFStyle style, List<XWPFStyle> usedStyleList) { String basisStyleID = style.getBasisStyleID(); XWPFStyle basisStyle = getStyle(basisStyleID); if ((basisStyle != null) && (!usedStyleList.contains(basisStyle))) { usedStyleList.add(basisStyle); getUsedStyleList(basisStyle, usedStyleList); } String linkStyleID = style.getLinkStyleID(); XWPFStyle linkStyle = getStyle(linkStyleID); if ((linkStyle != null) && (!usedStyleList.contains(linkStyle))) { usedStyleList.add(linkStyle); getUsedStyleList(linkStyle, usedStyleList); } String nextStyleID = style.getNextStyleID(); XWPFStyle nextStyle = getStyle(nextStyleID); if ((nextStyle != null) && (!usedStyleList.contains(nextStyle))) { usedStyleList.add(linkStyle); getUsedStyleList(linkStyle, usedStyleList); } return usedStyleList; }
/** * Read document */ @Override protected void onDocumentRead() throws IOException { StylesDocument stylesDoc; InputStream is = getPackagePart().getInputStream(); try { stylesDoc = StylesDocument.Factory.parse(is, DEFAULT_XML_OPTIONS); setStyles(stylesDoc.getStyles()); latentStyles = new XWPFLatentStyles(ctStyles.getLatentStyles(), this); } catch (XmlException e) { throw new POIXMLException("Unable to read styles", e); } finally { is.close(); } }
XWPFDocument template = new XWPFDocument(new FileInputStream(new File("Template.dotx"))); XWPFDocument doc = new XWPFDocument(); // let's copy styles from template to new doc XWPFStyles newStyles = doc.createStyles(); newStyles.setStyles(template.getStyle()); XWPFParagraph para = doc.createParagraph(); para.setStyle("Heading1"); XWPFRun run = para.createRun(); run.setText("Heading 1"); return doc;
@Override protected void commit() throws IOException { if (ctStyles == null) { throw new IllegalStateException("Unable to write out styles that were never read in!"); } XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS); xmlOptions.setSaveSyntheticDocumentElement(new QName(CTStyles.type.getName().getNamespaceURI(), "styles")); Map<String,String> map = new HashMap<String,String>(); map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r"); map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w"); xmlOptions.setSaveSuggestedPrefixes(map); PackagePart part = getPackagePart(); OutputStream out = part.getOutputStream(); ctStyles.save(out, xmlOptions); out.close(); }
/** * Get the default style which applies text runs in the document */ public XWPFDefaultRunStyle getDefaultRunStyle() { ensureDocDefaults(); return defaultRunStyle; }
/** * 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 * @param style * @return a list of all styles which were used by this method */ public List<XWPFStyle> getUsedStyleList(XWPFStyle style){ List<XWPFStyle> usedStyleList = new ArrayList<XWPFStyle>(); usedStyleList.add(style); return getUsedStyleList(style, usedStyleList); }