Java Code Examples for org.docx4j.wml.PPr#setSpacing()

The following examples show how to use org.docx4j.wml.PPr#setSpacing() . 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: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public void setParagraphSpacing(ObjectFactory factory, P p,  
        JcEnumeration jcEnumeration,String before,String after) {  
    PPr pPr = p.getPPr();  
    if (pPr == null) {  
        pPr = factory.createPPr();  
    }  
    Jc jc = pPr.getJc();  
    if (jc == null) {  
        jc = new Jc();  
    }  
    jc.setVal(jcEnumeration);  
    pPr.setJc(jc);  
      
    Spacing spacing=new Spacing();  
    spacing.setBefore(new BigInteger(before));  
    spacing.setAfter(new BigInteger(after));  
    spacing.setLineRule(STLineSpacingRule.AUTO);  
    pPr.setSpacing(spacing);  
    p.setPPr(pPr);  
}
 
Example 2
Source File: HtmlToDOCDemo.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public static void setWmlPprSetting(Object source, List<Object> targetList) {
	PPr sourcePpr = getWmlObjectPpr(source);
	if (sourcePpr != null) {
		for (int i = 0, iSize = targetList.size(); i < iSize; i++) {
			PPr ppr = getWmlObjectPpr(targetList.get(i));
			if (ppr != null) {
				ppr.setInd(sourcePpr.getInd());
				ppr.setSpacing(sourcePpr.getSpacing());
			}
		}
	}
	//sourcePpr.getSpacing()
}
 
Example 3
Source File: WmlElementUtils.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
/**
 * @param isSpace
 *            是否设置段前段后值
 * @param before
 *            段前磅数
 * @param after
 *            段后磅数
 * @param beforeLines
 *            段前行数
 * @param afterLines
 *            段后行数
 * @param isLine
 *            是否设置行距
 * @param lineValue
 *            行距值
 * @param sTLineSpacingRule
 *            自动auto 固定exact 最小 atLeast 1磅=20 1行=100 单倍行距=240
 */
public void setParagraphSpacing(P p, boolean isSpace, String before, String after, String beforeLines,
        String afterLines, boolean isLine, String lineValue, STLineSpacingRule sTLineSpacingRule) {
    PPr pPr = getPPr(p);
    Spacing spacing = pPr.getSpacing();
    if (spacing == null) {
        spacing = new Spacing();
        pPr.setSpacing(spacing);
    }
    if (isSpace) {
        if (StringUtils.isNotBlank(before)) {
            // 段前磅数
            spacing.setBefore(new BigInteger(before));
        }
        if (StringUtils.isNotBlank(after)) {
            // 段后磅数
            spacing.setAfter(new BigInteger(after));
        }
        if (StringUtils.isNotBlank(beforeLines)) {
            // 段前行数
            spacing.setBeforeLines(new BigInteger(beforeLines));
        }
        if (StringUtils.isNotBlank(afterLines)) {
            // 段后行数
            spacing.setAfterLines(new BigInteger(afterLines));
        }
    }
    if (isLine) {
        if (StringUtils.isNotBlank(lineValue)) {
            spacing.setLine(new BigInteger(lineValue));
        }
        if (sTLineSpacingRule != null) {
            spacing.setLineRule(sTLineSpacingRule);
        }
    }
}
 
Example 4
Source File: Docx4j_工具类_S3_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
/**
 * @param isSpace
 *            是否设置段前段后值
 * @param before
 *            段前磅数
 * @param after
 *            段后磅数
 * @param beforeLines
 *            段前行数
 * @param afterLines
 *            段后行数
 * @param isLine
 *            是否设置行距
 * @param lineValue
 *            行距值
 * @param sTLineSpacingRule
 *            自动auto 固定exact 最小 atLeast 1磅=20 1行=100 单倍行距=240
 */
public void setParagraphSpacing(P p, boolean isSpace, String before,
        String after, String beforeLines, String afterLines,
        boolean isLine, String lineValue,
        STLineSpacingRule sTLineSpacingRule) {
    PPr pPr = getPPr(p);
    Spacing spacing = pPr.getSpacing();
    if (spacing == null) {
        spacing = new Spacing();
        pPr.setSpacing(spacing);
    }
    if (isSpace) {
        if (StringUtils.isNotBlank(before)) {
            // 段前磅数
            spacing.setBefore(new BigInteger(before));
        }
        if (StringUtils.isNotBlank(after)) {
            // 段后磅数
            spacing.setAfter(new BigInteger(after));
        }
        if (StringUtils.isNotBlank(beforeLines)) {
            // 段前行数
            spacing.setBeforeLines(new BigInteger(beforeLines));
        }
        if (StringUtils.isNotBlank(afterLines)) {
            // 段后行数
            spacing.setAfterLines(new BigInteger(afterLines));
        }
    }
    if (isLine) {
        if (StringUtils.isNotBlank(lineValue)) {
            spacing.setLine(new BigInteger(lineValue));
        }
        if (sTLineSpacingRule != null) {
            spacing.setLineRule(sTLineSpacingRule);
        }
    }
}
 
Example 5
Source File: Docx4j_创建批注_S3_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void setParagraphSpacing(ObjectFactory factory, P p,  
        boolean isSpace, String before, String after, boolean isLines,  
        String beforeLines, String afterLines, boolean isLineRule,  
        String lineValue, STLineSpacingRule sTLineSpacingRule) {  
    PPr pPr = p.getPPr();  
    if (pPr == null) {  
        pPr = factory.createPPr();  
    }  
    Spacing spacing = new Spacing();  
    if (isSpace) {  
        if (before != null) {  
            // 段前磅数  
            spacing.setBefore(new BigInteger(before));  
        }  
        if (after != null) {  
            // 段后磅数  
            spacing.setAfter(new BigInteger(after));  
        }  
    }  
    if (isLines) {  
        if (beforeLines != null) {  
            // 段前行数  
            spacing.setBeforeLines(new BigInteger(beforeLines));  
        }  
        if (afterLines != null) {  
            // 段后行数  
            spacing.setAfterLines(new BigInteger(afterLines));  
        }  
    }  
    if (isLineRule) {  
        if (lineValue != null) {  
            spacing.setLine(new BigInteger(lineValue));  
        }  
        spacing.setLineRule(sTLineSpacingRule);  
    }  
    pPr.setSpacing(spacing);  
    p.setPPr(pPr);  
}
 
Example 6
Source File: FOPAreaTreeHelper.java    From docx4j-export-FO with Apache License 2.0 5 votes vote down vote up
private static P createFillerP() {

    	org.docx4j.wml.ObjectFactory wmlObjectFactory = Context.getWmlObjectFactory();

    	P p = wmlObjectFactory.createP(); 
    	    // Create object for pPr
    	    PPr ppr = wmlObjectFactory.createPPr(); 
    	    p.setPPr(ppr); 
    	        // Create object for rPr
    	        ParaRPr pararpr = wmlObjectFactory.createParaRPr(); 

    	        // Create object for spacing
    	        PPrBase.Spacing pprbasespacing = wmlObjectFactory.createPPrBaseSpacing(); 
    	        ppr.setSpacing(pprbasespacing); 
    	            pprbasespacing.setBefore( BigInteger.valueOf( 800) ); 
    	            pprbasespacing.setAfter( BigInteger.valueOf( 800) ); 
    	    // Create object for r
    	    R r = wmlObjectFactory.createR(); 
    	    p.getContent().add( r); 
    	        // Create object for rPr
    	        RPr rpr = wmlObjectFactory.createRPr(); 
    	        r.setRPr(rpr); 
    	            // Create object for sz
    	            HpsMeasure hpsmeasure3 = wmlObjectFactory.createHpsMeasure(); 
    	            rpr.setSz(hpsmeasure3); 
    	                hpsmeasure3.setVal( BigInteger.valueOf( 96) ); 

    	        // Create object for t (wrapped in JAXBElement) 
    	        Text text = wmlObjectFactory.createText(); 
    	        JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text); 
    	        r.getContent().add( textWrapped); 
    	            text.setValue( "BODY CONTENT"); 

    	return p;
    }
 
Example 7
Source File: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 4 votes vote down vote up
/**
 * @param jcEnumeration
 *            对齐方式
 * @param isSpace
 *            是否设置段前段后值
 * @param before
 *            段前磅数
 * @param after
 *            段后磅数
 * @param beforeLines
 *            段前行数
 * @param afterLines
 *            段后行数
 * @param isLine
 *            是否设置行距
 * @param lineValue
 *            行距值
 * @param sTLineSpacingRule
 *            自动auto 固定exact 最小 atLeast
 */
public void setParagraphSpacing(ObjectFactory factory, P p,
		JcEnumeration jcEnumeration, boolean isSpace, String before,
		String after, String beforeLines, String afterLines,
		boolean isLine, String lineValue,
		STLineSpacingRule sTLineSpacingRule) {
	PPr pPr = p.getPPr();
	if (pPr == null) {
		pPr = factory.createPPr();
	}
	Jc jc = pPr.getJc();
	if (jc == null) {
		jc = new Jc();
	}
	jc.setVal(jcEnumeration);
	pPr.setJc(jc);

	Spacing spacing = new Spacing();
	if (isSpace) {
		if (before != null) {
			// 段前磅数
			spacing.setBefore(new BigInteger(before));
		}
		if (after != null) {
			// 段后磅数
			spacing.setAfter(new BigInteger(after));
		}
		if (beforeLines != null) {
			// 段前行数
			spacing.setBeforeLines(new BigInteger(beforeLines));
		}
		if (afterLines != null) {
			// 段后行数
			spacing.setAfterLines(new BigInteger(afterLines));
		}
	}
	if (isLine) {
		if (lineValue != null) {
			spacing.setLine(new BigInteger(lineValue));
		}
		spacing.setLineRule(sTLineSpacingRule);
	}
	pPr.setSpacing(spacing);
	p.setPPr(pPr);
}
 
Example 8
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 4 votes vote down vote up
public void addTableCell(ObjectFactory factory,  
        WordprocessingMLPackage wordMLPackage, Tr tableRow, String content,  
        RPr rpr, JcEnumeration jcEnumeration, boolean hasBgColor,  
        String backgroudColor) {  
    Tc tableCell = factory.createTc();  
    P p = factory.createP();  
    setParagraphAlign(factory, p, jcEnumeration);  
    Text t = factory.createText();  
    t.setValue(content);  
    R run = factory.createR();  
    // 设置表格内容字体样式  
    run.setRPr(rpr);  
      
    TcPr tcPr = tableCell.getTcPr();  
    if (tcPr == null) {  
        tcPr = factory.createTcPr();  
    }  
      
    CTVerticalJc valign = factory.createCTVerticalJc();  
    valign.setVal(STVerticalJc.CENTER);  
    tcPr.setVAlign(valign);  
      
    run.getContent().add(t);  
    p.getContent().add(run);  
      
    PPr ppr=p.getPPr();  
    if(ppr==null){  
        ppr=factory.createPPr();  
    }  
    //设置段后距离  
    Spacing spacing=new Spacing();  
    spacing.setAfter(new BigInteger("0"));  
    spacing.setLineRule(STLineSpacingRule.AUTO);  
    ppr.setSpacing(spacing);  
    p.setPPr(ppr);  
      
    tableCell.getContent().add(p);  
    if (hasBgColor) {  
        CTShd shd = tcPr.getShd();  
        if (shd == null) {  
            shd = factory.createCTShd();  
        }  
        shd.setColor("auto");  
        shd.setFill(backgroudColor);  
        tcPr.setShd(shd);  
        tableCell.setTcPr(tcPr);  
    }  
    tableRow.getContent().add(tableCell);  
}