/** * return the XWPFRun-Element which owns the CTR run-Element * * @param r */ public XWPFRun getRun(CTR r) { for (int i = 0; i < getRuns().size(); i++) { if (getRuns().get(i).getCTR() == r) { return getRuns().get(i); } } return null; }
/** * Return the textual content of the paragraph, including text from pictures * and sdt elements in it. */ public String getText() { StringBuilder out = new StringBuilder(64); for (IRunElement run : iruns) { if (run instanceof XWPFRun) { XWPFRun xRun = (XWPFRun) run; // don't include the text if reviewing is enabled and this is a deleted run if (xRun.getCTR().getDelTextArray().length == 0) { out.append(xRun); } } else if (run instanceof XWPFSDT) { out.append(((XWPFSDT) run).getContent().getText()); } else { out.append(run); } } out.append(footnoteText); return out.toString(); }
/** * Set the style ID for the run. * * @param styleId ID (not name) of the style to set for the run, e.g. "BoldItalic" (not "Bold Italic"). */ public void setStyle(String styleId) { CTRPr pr = getCTR().getRPr(); if (null == pr) { pr = getCTR().addNewRPr(); } CTString style = pr.getRStyle() != null ? pr.getRStyle() : pr.addNewRStyle(); style.setVal(styleId); }
CTR r = run.getCTR();
r = p.createRun(); CTR ctr = r.getCTR(); boolean foundRef = false; for (CTFtnEdnRef ref : ctr.getEndnoteReferenceList()) {
r = p.createRun(); CTR ctr = r.getCTR(); boolean foundRef = false; for (CTFtnEdnRef ref : ctr.getFootnoteReferenceList()) {
/** * Add a new run with a reference to the specified footnote. * The footnote reference run will have the style name "FootnoteReference". * * @param footnote Footnote to which to add a reference. * @since 4.0.0 */ public void addFootnoteReference(XWPFAbstractFootnoteEndnote footnote) { XWPFRun run = createRun(); CTR ctRun = run.getCTR(); ctRun.addNewRPr().addNewRStyle().setVal("FootnoteReference"); if (footnote instanceof XWPFEndnote) { ctRun.addNewEndnoteReference().setId(footnote.getId()); } else { ctRun.addNewFootnoteReference().setId(footnote.getId()); } } }
/** * 重复样式 * * @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()); }
for (XWPFRun run : runs) { CTR ctr = run.getCTR(); List<CTDrawing> lst = ctr.getDrawingList(); for (int i = 0; i < lst.size(); i++) { ctr.removeDrawing(i); } }
if(text.equals("$[PAGE]")){ r1 = para.createRun(); CTFldChar fldChar = r1.getCTR().addNewFldChar(); fldChar.setFldCharType(STFldCharType.Enum.forString("begin")); CTText ctText = r1.getCTR().addNewInstrText(); ctText.setStringValue("PAGE \\* MERGEFORMAT"); ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve")); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); fldChar = r1.getCTR().addNewFldChar(); fldChar.setFldCharType(STFldCharType.Enum.forString("end")); }else if(text.equals("$[PAGES]")){ r1 = para.createRun(); CTFldChar fldChar = r1.getCTR().addNewFldChar(); fldChar.setFldCharType(STFldCharType.Enum.forString("begin")); CTText ctText = r1.getCTR().addNewInstrText(); ctText.setStringValue("NUMPAGES \\* MERGEFORMAT "); ctText.setSpace(SpaceAttribute.Space.Enum.forString("preserve")); CTRPr rpr = r1.getCTR().isSetRPr() ? r1.getCTR().getRPr() : r1.getCTR().addNewRPr(); CTFonts fonts = rpr.isSetRFonts() ? rpr.getRFonts() : rpr.addNewRFonts(); String fontName=hf.getFontFamily(); fldChar = r1.getCTR().addNewFldChar(); fldChar.setFldCharType(STFldCharType.Enum.forString("end")); }else if(text.equals("$[DATE]")){
//p is the XWPFParagraph for (XWPFRun pRun : p.getRuns()) { CTRPr ctrpr = pRun.getCTR().getRPr(); if (ctrpr != null && ctrpr.isSetHighlight()) { //This is highlighted } }
CTInline inline = run.getCTR().addNewDrawing().addNewInline();
public CTRPr getRPr( XWPFRun run ) { return run.getCTR().getRPr(); }
public CTRPr getRPr( XWPFRun run ) { return run.getCTR().getRPr(); }
XmlCursor c = run.getCTR().newCursor(); c.selectPath("./*"); while (c.toNextSelection()) {
/** * return the XWPFRun-Element which owns the CTR run-Element * * @param r */ public XWPFRun getRun(CTR r) { for (int i = 0; i < getRuns().size(); i++) { if (getRuns().get(i).getCTR() == r) { return getRuns().get(i); } } return null; }
XWPFRun run = doc.createParagraph().createRun(); run.setText("Привет"); run.setFontSize(14); run.setFontFamily("Calibri"); run.getCTR().getRPr().getRFonts().setHAnsi("Calibri");
/** * Set the style ID for the run. * * @param styleId ID (not name) of the style to set for the run, e.g. "BoldItalic" (not "Bold Italic"). */ public void setStyle(String styleId) { CTRPr pr = getCTR().getRPr(); if (null == pr) { pr = getCTR().addNewRPr(); } CTString style = pr.getRStyle() != null ? pr.getRStyle() : pr.addNewRStyle(); style.setVal(styleId); }