/** * Specifies the fonts which shall be used to display the text contents of * this run. Specifies a font which shall be used to format all characters * in the ASCII range (0 - 127) within the parent run. * <p> * Also sets the other font ranges, if they haven't been set before * * @param fontFamily The font family to apply * @see FontCharRange */ public void setFontFamily(String fontFamily) { setFontFamily(fontFamily, null); }
/** * 增加一个段落 * * @param align 段落对齐方式{@link ParagraphAlignment} * @param font 字体信息{@link Font} * @param texts 段落中的文本,支持多个文本作为一个段落 * @return this */ public Word07Writer addText(ParagraphAlignment align, Font font, String... texts) { final XWPFParagraph p = this.doc.createParagraph(); if (null != align) { p.setAlignment(align); } if (ArrayUtil.isNotEmpty(texts)) { XWPFRun run; for (String text : texts) { run = p.createRun(); run.setText(text); if (null != font) { run.setFontFamily(font.getFamily()); run.setFontSize(font.getSize()); run.setBold(font.isBold()); run.setItalic(font.isItalic()); } } } return this; }
/** * 增加一个段落 * * @param align 段落对齐方式{@link ParagraphAlignment} * @param font 字体信息{@link Font} * @param texts 段落中的文本,支持多个文本作为一个段落 * @return this */ public Word07Writer addText(ParagraphAlignment align, Font font, String... texts) { final XWPFParagraph p = this.doc.createParagraph(); if (null != align) { p.setAlignment(align); } if (ArrayUtil.isNotEmpty(texts)) { XWPFRun run; for (String text : texts) { run = p.createRun(); run.setText(text); if (null != font) { run.setFontFamily(font.getFamily()); run.setFontSize(font.getSize()); run.setBold(font.isBold()); run.setItalic(font.isItalic()); } } } return this; }
/** * Specifies the fonts which shall be used to display the text contents of * this run. Specifies a font which shall be used to format all characters * in the ASCII range (0 - 127) within the parent run. * <p> * Also sets the other font ranges, if they haven't been set before * * @param fontFamily The font family to apply * @see FontCharRange */ public void setFontFamily(String fontFamily) { setFontFamily(fontFamily, null); }
/** * 重复样式 * * @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 (0 != fontSize) run.setFontSize(fontSize); if (StringUtils.isNotBlank(fontFamily)) { run.setFontFamily(fontFamily); CTRPr pr = run.getCTR().isSetRPr() ? run.getCTR().getRPr() : run.getCTR().addNewRPr(); CTFonts fonts = pr.isSetRFonts() ? pr.getRFonts() : pr.addNewRFonts();
run.setFontFamily(fontFamily);
List<XWPFRun> runs = par.getRuns(); for(int i = 0 ; i < runs.size() - 1 ; i++) { XWPFRun run = runs.get(i); int index=0; // a run contains many text so you want to parse them as well : String text = run.getText(index); while(text !=null ){ if(text.contains("occurencyYourLookingFor")) { run.setFontFamily("Arial"); } text = run.getText(++index); } }
XWPFRun run = doc.createParagraph().createRun(); run.setText("Привет"); run.setFontSize(14); run.setFontFamily("Calibri"); run.getCTR().getRPr().getRFonts().setHAnsi("Calibri");
for (XWPFTableCell cell : cells) { String cellTextString = cell.getText(); if (cellTextString != null && cellTextString.contains(placeholder)) { cellTextString = cellTextString.replace(placeholder,waterMarkText); cell.removeParagraph(0); XWPFParagraph addParagraph = cell.addParagraph(); XWPFRun run = addParagraph.createRun(); run.setFontFamily("Calibri"); run.setFontSize(10); run.setText(cellTextString); } }
XWPFTableRow rowOne = table.getRow(0); XWPFParagraph paragraph = rowOne.getCell(0).addParagraph(); setRun(paragraphRefTitle.createRun() , "Calibre LIght" , 10, "2b5079" , "Some string" , false, false); private static void setRun (XWPFRun run , String fontFamily , int fontSize , String colorRGB , String text , boolean bold , boolean addBreak) { run.setFontFamily(fontFamily); run.setFontSize(fontSize); run.setColor(colorRGB); run.setText(text); run.setBold(bold); if (addBreak) run.addBreak(); }
/** * 增加一个段落 * * @param align 段落对齐方式{@link ParagraphAlignment} * @param font 字体信息{@link Font} * @param texts 段落中的文本,支持多个文本作为一个段落 * @return this */ public Word07Writer addText(ParagraphAlignment align, Font font, String... texts) { final XWPFParagraph p = this.doc.createParagraph(); if (null != align) { p.setAlignment(align); } if (ArrayUtil.isNotEmpty(texts)) { XWPFRun run; for (String text : texts) { run = p.createRun(); run.setText(text); if (null != font) { run.setFontFamily(font.getFamily()); run.setFontSize(font.getSize()); run.setBold(font.isBold()); run.setItalic(font.isItalic()); } } } return this; }
newRun.setFontFamily( run.getFontFamily() ); newRun.setBold( run.isBold() ); newRun.setItalic( run.isItalic() );
tmpRun.setText("شهادة بالملك"); tmpRun.setFontSize(18); tmpRun.setFontFamily("Calibri (Corps)"); tmpRun.setBold(true); tmpRun.setColor("003894");
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); } } }
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.setFontFamily(getStylesDocument().getFontFamilyAscii(run));
run.setBold(refRun.isBold()); run.setItalic(refRun.isItalic()); run.setFontFamily(refRun.getFontFamily()); run.setColor(refRun.getColor()); if(refRun.getFontSize()>0){
run.setBold(refRun.isBold()); run.setItalic(refRun.isItalic()); run.setFontFamily(refRun.getFontFamily()); run.setColor(refRun.getColor()); run.setFontSize(refRun.getFontSize());
run.setBold(refRun.isBold()); run.setItalic(refRun.isItalic()); run.setFontFamily(refRun.getFontFamily()); run.setColor(refRun.getColor());