/** * 重复样式 * * @param destRun 新建的run * @param srcRun 原始run */ public static void styleRun(XWPFRun destRun, XWPFRun srcRun) { if (null == destRun || null == srcRun) return; CTR ctr = srcRun.getCTR(); if (ctr.isSetRPr() && ctr.getRPr().isSetRStyle()){ String val = ctr.getRPr().getRStyle().getVal(); if (StringUtils.isNotBlank(val)) { CTRPr pr = destRun.getCTR().isSetRPr() ? destRun.getCTR().getRPr() : destRun.getCTR().addNewRPr(); CTString rStyle = pr.isSetRStyle() ? pr.getRStyle() : pr.addNewRStyle(); rStyle.setVal(val); } } if (Boolean.TRUE.equals(srcRun.isBold())) destRun.setBold(srcRun.isBold()); destRun.setColor(srcRun.getColor()); // destRun.setCharacterSpacing(srcRun.getCharacterSpacing()); if (StringUtils.isNotBlank(srcRun.getFontFamily())) destRun.setFontFamily(srcRun.getFontFamily()); int fontSize = srcRun.getFontSize(); if (-1 != fontSize) destRun.setFontSize(fontSize); if (Boolean.TRUE.equals(srcRun.isItalic())) destRun.setItalic(srcRun.isItalic()); if (Boolean.TRUE.equals(srcRun.isStrikeThrough())) destRun.setStrikeThrough(srcRun.isStrikeThrough()); destRun.setUnderline(srcRun.getUnderline()); }
if (null != strike) run.setStrikeThrough(strike); if (Boolean.TRUE.equals(underLine)){ run.setUnderline(UnderlinePatterns.SINGLE);
run.setUnderline(UnderlinePatterns.SINGLE);
newRun.setStrikeThrough(run.isStrikeThrough()); newRun.setSubscript(run.getSubscript()); newRun.setUnderline(run.getUnderline());
tmpRun.setColor("003894"); tmpParagraph.setAlignment(ParagraphAlignment.CENTER); tmpRun.setUnderline(UnderlinePatterns.SINGLE); tmpParagraph.setSpacingAfter(300); setOrientation(tmpParagraph, TextOrientation.RTL);
r1.setItalic(true); r1.setFontFamily("Courier"); r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH); r1.setTextPosition(100);
public static void createSimpleTable() throws Exception { try (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"); try (OutputStream out = new FileOutputStream("simpleTable.docx")) { doc.write(out); } } }
XWPFRun paragraphFourRunOne = paragraphFour.createRun(); paragraphFourRunOne.setBold(true); paragraphFourRunOne.setUnderline(UnderlinePatterns.SINGLE); paragraphFourRunOne.setFontSize(10); paragraphFourRunOne.setFontFamily("Verdana"); paragraphFiveRunOne.addBreak(); paragraphFourRunOne.setBold(true); paragraphFourRunOne.setUnderline(UnderlinePatterns.SINGLE); paragraphFourRunOne.setFontSize(10); paragraphFourRunOne.setFontFamily("Verdana");
XWPFDocument doc = new XWPFDocument(); XWPFParagraph p1 = doc.createParagraph(); p1.setAlignment(ParagraphAlignment.CENTER); p1.setBorderBottom(Borders.DOUBLE); p1.setBorderTop(Borders.DOUBLE); p1.setBorderRight(Borders.DOUBLE); p1.setBorderLeft(Borders.DOUBLE); p1.setBorderBetween(Borders.SINGLE); p1.setVerticalAlignment(TextAlignment.TOP); XWPFRun r1 = p1.createRun(); r1.setBold(true); r1.setText("The quick brown fox"); r1.setBold(true); r1.setFontFamily("Courier"); r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH); r1.setTextPosition(100);
run.setUnderline(UnderlinePatterns.SINGLE);
run.setUnderline(UnderlinePatterns.WORDS); run.setText("Hall Name: " + hallName); run.addBreak();
run.setUnderline(refRun.getUnderline());
run.setFontSize(refRun.getFontSize()); run.setStrike(refRun.isStrike()); run.setUnderline(refRun.getUnderline());
run.setFontFamily(style.getFontFamily()); if (style.getUnderline() != null) run.setUnderline(UnderlinePatterns.valueOf(style.getUnderline().name())); if (style.getTextColor() != null) ctshd.setFill(style.getBgColor());
run.setFontFamily(style.getFontFamily()); if (style.getUnderline() != null) run.setUnderline(UnderlinePatterns.valueOf(style.getUnderline().name())); if (style.getTextColor() != null) ctshd.setFill(style.getBgColor());
run.setUnderline(refRun.getUnderline());
r1.setBold(true); r1.setFontFamily("Courier"); r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH); r1.setTextPosition(100);
if(style.getTextPosition()>0)run.setTextPosition(run.getTextPosition()); if(style.getFontFamily()!=null)run.setFontFamily(style.getFontFamily()); if(style.getUnderline()!=null)run.setUnderline(UnderlinePatterns.valueOf(style.getUnderline().name())); if(style.getTextColor()!=null)ctshd.setFill(style.getBgColor()); if(style.getBgColor()!=null)run.setColor(style.getTextColor());
cellR.setItalic(tmpR.isItalic()); cellR.setStrike(tmpR.isStrike()); cellR.setUnderline(tmpR.getUnderline()); cellR.setColor(tmpR.getColor()); cellR.setTextPosition(tmpR.getTextPosition());