org.apache.poi.xwpf.usermodel.XWPFStyle Java Examples
The following examples show how to use
org.apache.poi.xwpf.usermodel.XWPFStyle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RawCopier.java From M2Doc with Eclipse Public License 1.0 | 6 votes |
/** * Copy Table Style. * * @param inputTable * input Table * @param outputDoc * outputDoc where copy style * @throws IOException * if the copy fails */ private static void copyTableStyle(XWPFTable inputTable, XWPFDocument outputDoc) throws IOException { @SuppressWarnings("resource") final XWPFDocument inputDoc = inputTable.getBody().getXWPFDocument(); final XWPFStyle style = inputDoc.getStyles().getStyle(inputTable.getStyleID()); if (outputDoc != null && style != null) { if (outputDoc.getStyles() == null) { outputDoc.createStyles(); } List<XWPFStyle> usedStyleList = inputDoc.getStyles().getUsedStyleList(style); for (XWPFStyle xwpfStyle : usedStyleList) { outputDoc.getStyles().addStyle(xwpfStyle); } } }
Example #2
Source File: NiceXWPFDocument.java From poi-tl with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private Map<String, String> mergeStyles(NiceXWPFDocument docMerge) { Map<String, String> styleIdsMap = new HashMap<String, String>(); XWPFStyles styles = this.getStyles(); if (null == styles) styles = createStyles(); XWPFStyles stylesMerge = docMerge.getStyles(); if (null == stylesMerge) return styleIdsMap; try { Field listStyleField = XWPFStyles.class.getDeclaredField("listStyle"); listStyleField.setAccessible(true); List<XWPFStyle> lists = (List<XWPFStyle>) listStyleField.get(stylesMerge); for (XWPFStyle xwpfStyle : lists) { if (styles.styleExist(xwpfStyle.getStyleId())) { String id = xwpfStyle.getStyleId(); xwpfStyle.setStyleId(UUID.randomUUID().toString()); styleIdsMap.put(id, xwpfStyle.getStyleId()); } styles.addStyle(xwpfStyle); } } catch (Exception e) { // throw exception? logger.error("merge style error", e); } return styleIdsMap; }
Example #3
Source File: PaginationServices.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
/** * Consturtor. * * @param uriConverter * the {@link URIConverter uri converter} to use. * @param templateURI * the template {@link URI} */ public PaginationServices(URIConverter uriConverter, URI templateURI) { try (XWPFDocument document = POIServices.getInstance().getXWPFDocument(uriConverter, templateURI);) { final List<XWPFStyle> styles = getStyles(document.getStyles()); for (XWPFStyle style : styles) { switch (style.getType().intValue()) { case STStyleType.INT_PARAGRAPH: textStyleIDs.put(style.getStyleId(), style.getName()); break; case STStyleType.INT_TABLE: tableStyleIDs.put(style.getStyleId(), style.getName()); break; default: break; } } if (document.getNumbering() != null) { final CTNumbering numbering = getCTNumbering(document.getNumbering()); for (CTAbstractNum num : numbering.getAbstractNumList()) { final BigInteger id = num.getAbstractNumId().add(BigInteger.valueOf(1)); final BigInteger maxLevel = BigInteger.valueOf(num.getLvlList().size()); numberingIDs.put(id, maxLevel); } } } catch (IOException e) { // nothing to do here } }