/** * 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); }
/** * 重复样式 * * @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()); }
public static CTString getRStyle( XWPFRun run ) { if ( run == null ) { return null; } CTR ctr = run.getCTR(); if ( ctr == null ) { return null; } CTRPr rpr = ctr.getRPr(); if ( rpr == null ) { return null; } return rpr.getRStyle(); } }
@Override protected String[] getStyleID( XWPFRun run ) { XWPFParagraph paragraph = run.getParagraph(); List<String> styleIDs = StylesHelper.getStyleIDs( paragraph ); CTRPr rPr = getRPr( run ); if ( rPr != null ) { CTString style = rPr.getRStyle(); if ( style != null ) { if ( styleIDs == null ) { styleIDs = new ArrayList<String>(); } styleIDs.add( 0, style.getVal() ); } } if ( styleIDs != null ) { return styleIDs.toArray( StringUtils.EMPTY_STRING_ARRAY ); } return null; }
/** * 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); }
@Override protected String[] getStyleID( XWPFRun run ) { XWPFParagraph paragraph = run.getParagraph(); List<String> styleIDs = StylesHelper.getStyleIDs( paragraph ); CTRPr rPr = getRPr( run ); if ( rPr != null ) { CTString style = rPr.getRStyle(); if ( style != null ) { if ( styleIDs == null ) { styleIDs = new ArrayList<String>(); } styleIDs.add( 0, style.getVal() ); } } if ( styleIDs != null ) { return styleIDs.toArray( StringUtils.EMPTY_STRING_ARRAY ); } return null; }
value = getValueFromStyle( rPr.getRStyle(), document ); if ( value != null )
value = getValueFromStyle( rPr.getRStyle(), document ); if ( value != null )