org.apache.poi.xwpf.usermodel.UnderlinePatterns Java Examples
The following examples show how to use
org.apache.poi.xwpf.usermodel.UnderlinePatterns.
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: M2DocEvaluator.java From M2Doc with Eclipse Public License 1.0 | 5 votes |
/** * Apply the given style to the given run. Background color is not taken into account here since it does not apply to runs. * * @param run * The run to style * @param style * The style to apply, can be <code>null</code> */ private void applyMStyle(XWPFRun run, MStyle style) { if (style.getFontSize() != -1) { run.setFontSize(style.getFontSize()); } if (style.getFontName() != null) { run.setFontFamily(style.getFontName()); } if (style.getFontModifiers() != -1) { run.setBold((style.getFontModifiers() & MStyle.FONT_BOLD) != 0); run.setItalic((style.getFontModifiers() & MStyle.FONT_ITALIC) != 0); if ((style.getFontModifiers() & MStyle.FONT_UNDERLINE) != 0) { run.setUnderline(UnderlinePatterns.SINGLE); } run.setStrikeThrough((style.getFontModifiers() & MStyle.FONT_STRIKE_THROUGH) != 0); } if (style.getForegroundColor() != null) { run.setColor(hexColor(style.getForegroundColor())); } if (style.getBackgroundColor() != null) { final CTRPr ctrpr; if (run.getCTR().getRPr() != null) { ctrpr = run.getCTR().getRPr(); } else { ctrpr = run.getCTR().addNewRPr(); } final CTShd ctshd; if (ctrpr.getShd() != null) { ctshd = ctrpr.getShd(); } else { ctshd = ctrpr.addNewShd(); } ctshd.setVal(STShd.CLEAR); ctshd.setColor("auto"); ctshd.setFill(hexColor(style.getBackgroundColor())); } }
Example #2
Source File: SimpleTable.java From poi-tl with Apache License 2.0 | 5 votes |
public static void createSimpleTable() throws Exception { @SuppressWarnings("resource") XWPFDocument doc = new XWPFDocument(); XWPFTable table = doc.createTable(3, 3); table.getRow(1).getCell(1).setText("EXAMPLE OF TABLE"); // table cells have a list of paragraphs; there is an initial // paragraph created when the cell is created. If you create a // paragraph in the document to put in the cell, it will also // appear in the document following the table, which is probably // not the desired result. XWPFParagraph p1 = table.getRow(0).getCell(0).getParagraphs().get(0); XWPFRun r1 = p1.createRun(); r1.setBold(true); r1.setText("The quick brown fox"); r1.setItalic(true); r1.setFontFamily("Courier"); r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH); r1.setTextPosition(100); table.getRow(2).getCell(2).setText("only text"); FileOutputStream out = new FileOutputStream("simpleTable.docx"); doc.write(out); out.close(); }
Example #3
Source File: StyleUtils.java From poi-tl with Apache License 2.0 | 4 votes |
/** * 设置run的样式 * * @param run * @param style */ public static void styleRun(XWPFRun run, Style style) { if (null == run || null == style) return; String color = style.getColor(); String fontFamily = style.getFontFamily(); int fontSize = style.getFontSize(); Boolean bold = style.isBold(); Boolean italic = style.isItalic(); Boolean strike = style.isStrike(); Boolean underLine = style.isUnderLine(); Enum highlightColor = style.getHighlightColor(); int twips = style.getCharacterSpacing(); String vertAlign = style.getVertAlign(); CTRPr pr = run.getCTR().isSetRPr() ? run.getCTR().getRPr() : run.getCTR().addNewRPr(); if (StringUtils.isNotBlank(color)) { // run.setColor(color); // issue 326 CTColor ctColor = pr.isSetColor() ? pr.getColor() : pr.addNewColor(); ctColor.setVal(color); if (ctColor.isSetThemeColor()) ctColor.unsetThemeColor(); } if (0 != fontSize) run.setFontSize(fontSize); if (StringUtils.isNotBlank(fontFamily)) { run.setFontFamily(fontFamily); CTFonts fonts = pr.isSetRFonts() ? pr.getRFonts() : pr.addNewRFonts(); fonts.setAscii(fontFamily); fonts.setHAnsi(fontFamily); fonts.setCs(fontFamily); fonts.setEastAsia(fontFamily); } if (null != highlightColor) { CTHighlight highlight = pr.isSetHighlight() ? pr.getHighlight() : pr.addNewHighlight(); STHighlightColor hColor = highlight.xgetVal(); if (hColor == null) { hColor = STHighlightColor.Factory.newInstance(); } STHighlightColor.Enum val = STHighlightColor.Enum.forString(highlightColor.toString()); if (val != null) { hColor.setStringValue(val.toString()); highlight.xsetVal(hColor); } } if (null != bold) run.setBold(bold); if (null != italic) run.setItalic(italic); if (null != strike) run.setStrikeThrough(strike); if (Boolean.TRUE.equals(underLine)) { run.setUnderline(UnderlinePatterns.SINGLE); } // in twentieths of a point if (0 != twips) run.setCharacterSpacing(20*twips); if (StringUtils.isNotBlank(vertAlign)) { run.setVerticalAlignment(vertAlign); } }