Java Code Examples for org.docx4j.wml.ObjectFactory#createTcPr()

The following examples show how to use org.docx4j.wml.ObjectFactory#createTcPr() . 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 5 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();
	setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null,
			null, true, "240", STLineSpacingRule.AUTO);
	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);
	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);
}
 
Example 2
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 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);
	run.getContent().add(t);
	p.getContent().add(run);
	tableCell.getContent().add(p);

	if (hasBgColor) {
		TcPr tcPr = tableCell.getTcPr();
		if (tcPr == null) {
			tcPr = factory.createTcPr();
		}
		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);
}
 
Example 3
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);  
}