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

The following examples show how to use org.docx4j.wml.ObjectFactory#createP() . 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_简单例子.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public Hdr getTextHdr(WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, Part sourcePart, String content,
		JcEnumeration jcEnumeration) throws Exception {
	Hdr hdr = factory.createHdr();
	P headP = factory.createP();
	Text text = factory.createText();
	text.setValue(content);
	R run = factory.createR();
	run.getContent().add(text);
	headP.getContent().add(run);

	PPr pPr = headP.getPPr();
	if (pPr == null) {
		pPr = factory.createPPr();
	}
	Jc jc = pPr.getJc();
	if (jc == null) {
		jc = new Jc();
	}
	jc.setVal(jcEnumeration);
	pPr.setJc(jc);
	headP.setPPr(pPr);
	hdr.getContent().add(headP);
	return hdr;
}
 
Example 2
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, Part sourcePart, String content,
		JcEnumeration jcEnumeration) throws Exception {
	Ftr ftr = factory.createFtr();
	P footerP = factory.createP();
	Text text = factory.createText();
	text.setValue(content);
	R run = factory.createR();
	run.getContent().add(text);
	footerP.getContent().add(run);

	PPr pPr = footerP.getPPr();
	if (pPr == null) {
		pPr = factory.createPPr();
	}
	Jc jc = pPr.getJc();
	if (jc == null) {
		jc = new Jc();
	}
	jc.setVal(jcEnumeration);
	pPr.setJc(jc);
	footerP.setPPr(pPr);
	ftr.getContent().add(footerP);
	return ftr;
}
 
Example 3
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public Ftr createFooterWithPageNr(ObjectFactory factory) {  
    Ftr ftr = factory.createFtr();  
    P paragraph = factory.createP();  
    RPr fontRPr = getRPr(factory, "宋体", "000000", "20", STHint.EAST_ASIA,  
            false, false, false, false);  
    R run = factory.createR();  
    run.setRPr(fontRPr);  
    paragraph.getContent().add(run);  
  
    addPageTextField(factory, paragraph, "第");  
    addFieldBegin(factory, paragraph);  
    addPageNumberField(factory, paragraph);  
    addFieldEnd(factory, paragraph);  
    addPageTextField(factory, paragraph, "页");  
  
    addPageTextField(factory, paragraph, " 总共");  
    addFieldBegin(factory, paragraph);  
    addTotalPageNumberField(factory, paragraph);  
    addFieldEnd(factory, paragraph);  
    addPageTextField(factory, paragraph, "页");  
    setParagraphAlign(factory, paragraph, JcEnumeration.CENTER);  
    ftr.getContent().add(paragraph);  
    return ftr;  
}
 
Example 4
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void addPageBreak(WordprocessingMLPackage wordMLPackage,  
        ObjectFactory factory) {  
    MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();  
    Br breakObj = new Br();  
    breakObj.setType(STBrType.PAGE);  
    P paragraph = factory.createP();  
    paragraph.getContent().add(breakObj);  
    documentPart.addObject(paragraph);  
}
 
Example 5
Source File: Docx4j_创建表格_S5_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void addCellStyle(ObjectFactory factory, Tc tableCell,  
        String content, Docx4jStyle_S3 style) {  
    if (style != null) {  
        P paragraph = factory.createP();  
        Text text = factory.createText();  
        text.setValue(content);  
        R run = factory.createR();  
        run.getContent().add(text);  
        paragraph.getContent().add(run);  
        setHorizontalAlignment(paragraph, style.getHorizAlignment());  
        RPr runProperties = factory.createRPr();  
        if (style.isBold()) {  
            addBoldStyle(runProperties);  
        }  
        if (style.isItalic()) {  
            addItalicStyle(runProperties);  
        }  
        if (style.isUnderline()) {  
            addUnderlineStyle(runProperties);  
        }  
        setFontSize(runProperties, style.getFontSize());  
        setFontColor(runProperties, style.getFontColor());  
        setFontFamily(runProperties, style.getCnFontFamily(),style.getEnFontFamily());  
        setCellMargins(tableCell, style.getTop(), style.getRight(),  
                style.getBottom(), style.getLeft());  
        setCellColor(tableCell, style.getBackground());  
        setVerticalAlignment(tableCell, style.getVerticalAlignment());  
        setCellBorders(tableCell, style.isBorderTop(),  
                style.isBorderRight(), style.isBorderBottom(),  
                style.isBorderLeft());  
        run.setRPr(runProperties);  
        tableCell.getContent().add(paragraph);  
    }  
}
 
Example 6
Source File: AddingAnInlineImageToTable.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
/**
 *  向新的段落中添加内联图片并返回这个段落.
 *  这个方法与前面例子中的方法没有区别.
 * @param inline
 * @return
 */
private static P addInlineImageToParagraph(Inline inline) {
    // Now add the in-line image to a paragraph
    ObjectFactory factory = new ObjectFactory();
    P paragraph = factory.createP();
    R run = factory.createR();
    paragraph.getContent().add(run);
    Drawing drawing = factory.createDrawing();
    run.getContent().add(drawing);
    drawing.getAnchorOrInline().add(inline);
    return paragraph;
}
 
Example 7
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public P createHeaderBlankP(WordprocessingMLPackage wordMLPackage,  
        ObjectFactory factory,  
        JcEnumeration jcEnumeration) throws Exception{  
    P p = factory.createP();  
    R run = factory.createR();  
    p.getContent().add(run);  
    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);  
      
    PBdr pBdr=pPr.getPBdr();  
    if(pBdr==null){  
        pBdr=factory.createPPrBasePBdr();  
    }  
    CTBorder value=new CTBorder();  
    value.setVal(STBorder.SINGLE);  
    value.setColor("000000");  
    value.setSpace(new BigInteger("0"));  
    value.setSz(new BigInteger("3"));  
    pBdr.setBetween(value);  
    pPr.setPBdr(pBdr);  
    p.setPPr(pPr);  
    setParagraphSpacing(factory, p, jcEnumeration, "0", "0");  
    return p;  
}
 
Example 8
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void addPageBreak(WordprocessingMLPackage wordMLPackage,
		ObjectFactory factory) {
	MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
	Br breakObj = new Br();
	breakObj.setType(STBrType.PAGE);
	P paragraph = factory.createP();
	paragraph.getContent().add(breakObj);
	documentPart.addObject(paragraph);
}
 
Example 9
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 10
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Hdr getTextHdr(WordprocessingMLPackage wordprocessingMLPackage,  
        ObjectFactory factory, Part sourcePart, String content,  
        JcEnumeration jcEnumeration) throws Exception {  
    Hdr hdr = factory.createHdr();  
    P headP = factory.createP();  
    Text text = factory.createText();  
    text.setValue(content);  
    R run = factory.createR();  
    run.getContent().add(text);  
    headP.getContent().add(run);  
  
    PPr pPr = headP.getPPr();  
    if (pPr == null) {  
        pPr = factory.createPPr();  
    }  
    Jc jc = pPr.getJc();  
    if (jc == null) {  
        jc = new Jc();  
    }  
    jc.setVal(jcEnumeration);  
    pPr.setJc(jc);  
      
    PBdr pBdr=pPr.getPBdr();  
    if(pBdr==null){  
        pBdr=factory.createPPrBasePBdr();  
    }  
      
    CTBorder value=new CTBorder();  
    value.setVal(STBorder.SINGLE);  
    value.setColor("000000");  
    value.setSpace(new BigInteger("0"));  
    value.setSz(new BigInteger("3"));  
    pBdr.setBetween(value);  
    pPr.setPBdr(pBdr);  
    headP.setPPr(pPr);  
    setParagraphSpacing(factory, headP, jcEnumeration, "0", "0");  
    hdr.getContent().add(headP);  
    hdr.getContent().add(createHeaderBlankP(wordprocessingMLPackage, factory, jcEnumeration));  
    return hdr;  
}
 
Example 11
Source File: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	Docx4J_例子2 t = new Docx4J_例子2();
	WordprocessingMLPackage wordMLPackage = t
			.createWordprocessingMLPackage();
	MainDocumentPart mp = wordMLPackage.getMainDocumentPart();
	ObjectFactory factory = Context.getWmlObjectFactory();

	Relationship relationship = t.createHeaderPart(wordMLPackage, mp,
			factory, false, "3");
	relationship = t.createTextHeaderPart(wordMLPackage, mp, factory,
			"我是页眉,独乐乐不如众乐乐", true, "3", JcEnumeration.CENTER);
	t.addParagraphTest(wordMLPackage, mp, factory);
	t.addPageBreak(wordMLPackage, factory, STBrType.PAGE);
	t.createHeaderReference(wordMLPackage, mp, factory, relationship);
	t.createNormalTableTest(wordMLPackage, mp, factory);
	t.addPageBreak(wordMLPackage, factory, STBrType.TEXT_WRAPPING);
	t.createTableTest(wordMLPackage, mp, factory);
	t.addPageBreak(wordMLPackage, factory, STBrType.TEXT_WRAPPING);
	P paragraph=factory.createP();
	CTBorder topBorder=new CTBorder() ;
	topBorder.setSpace(new BigInteger("1"));
	topBorder.setSz(new BigInteger("2"));
	topBorder.setVal(STBorder.WAVE);
	t.createParagraghLine(wordMLPackage, mp, factory, paragraph, topBorder, topBorder, topBorder, topBorder);
	mp.addObject(paragraph);
	t.createHyperlink(wordMLPackage, mp, factory,paragraph,
			"mailto:[email protected]?subject=docx4j测试", "联系我","微软雅黑","24",JcEnumeration.CENTER);
	
	// 页脚
	// relationship = t.createFooterPart(wordMLPackage, mp, factory,
	// false,"3");
	// relationship = t.createTextFooterPart(wordMLPackage, mp,
	// factory,"我是页脚", true, "3", JcEnumeration.CENTER);
	relationship = t.createFooterPageNumPart(wordMLPackage, mp, factory,
			false, "3", JcEnumeration.CENTER);
	t.createFooterReference(wordMLPackage, mp, factory, relationship);
	t.saveWordPackage(wordMLPackage, new File(
			"f:/saveFile/temp/s7_simple.docx"));
}
 
Example 12
Source File: Docx4j_创建批注_S3_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void testCreateComment(WordprocessingMLPackage wordMLPackage,  
        MainDocumentPart t, ObjectFactory factory) throws Exception {  
    P p = factory.createP();  
    setParagraphSpacing(factory, p, true, "0",  
            "0",true, null, "100", true, "240", STLineSpacingRule.AUTO);  
    t.addObject(p);  
    RPr fontRPr = getRPrStyle(factory, "微软雅黑", "000000", "20",  
            STHint.EAST_ASIA, false, false, false, true, UnderlineEnumeration.SINGLE,  "B61CD2",  
            true, "darkYellow", false, null, null, null);  
    RPr commentRPr = getRPrStyle(factory, "微软雅黑", "41A62D", "18",  
            STHint.EAST_ASIA, true, true, false, false, null, null, false,  
            null, false, null, null, null);  
    Comments comments = addDocumentCommentsPart(wordMLPackage, factory);  
    BigInteger commentId = BigInteger.valueOf(1);  
      
    createCommentEnd(factory, p, "测试", "这是官网Demo", fontRPr, commentRPr, commentId, comments);  
    commentId = commentId.add(BigInteger.ONE);  
  
    createCommentRound(factory, p, "批注", "这是批注comment", fontRPr, commentRPr, commentId, comments);  
    commentId = commentId.add(BigInteger.ONE);  
      
    p = factory.createP();  
    setParagraphSpacing(factory, p, true, "0",  
            "0",true, null, "100", true, "240", STLineSpacingRule.AUTO);  
    t.addObject(p);  
    createCommentRound(factory, p, "批注2", "这是批注comment2", fontRPr, commentRPr, commentId, comments);  
    commentId = commentId.add(BigInteger.ONE);  
      
    createCommentEnd(factory, p, "测试2", "这是官网Demo", fontRPr, commentRPr, commentId, comments);  
    commentId = commentId.add(BigInteger.ONE);  
}
 
Example 13
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 14
Source File: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void addPageBreak(WordprocessingMLPackage wordMLPackage,
		ObjectFactory factory, STBrType sTBrType) {
	MainDocumentPart documentPart = wordMLPackage.getMainDocumentPart();
	Br breakObj = new Br();
	breakObj.setType(sTBrType);
	P paragraph = factory.createP();
	paragraph.getContent().add(breakObj);
	documentPart.addObject(paragraph);
}
 
Example 15
Source File: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public P createHeaderBlankP(WordprocessingMLPackage wordMLPackage,
		ObjectFactory factory, String underLineSz,
		JcEnumeration jcEnumeration) throws Exception {
	P p = factory.createP();
	R run = factory.createR();
	p.getContent().add(run);
	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);

	PBdr pBdr = pPr.getPBdr();
	if (pBdr == null) {
		pBdr = factory.createPPrBasePBdr();
	}
	CTBorder value = new CTBorder();
	value.setVal(STBorder.SINGLE);
	value.setColor("000000");
	value.setSpace(new BigInteger("0"));
	value.setSz(new BigInteger(underLineSz));
	pBdr.setBetween(value);
	pPr.setPBdr(pBdr);
	p.setPPr(pPr);
	setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null,
			null, true, "240", STLineSpacingRule.AUTO);
	return p;
}
 
Example 16
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);  
}
 
Example 17
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 4 votes vote down vote up
public void addParagraphTest(WordprocessingMLPackage wordMLPackage,
		MainDocumentPart t, ObjectFactory factory) throws Exception {
	RPr titleRPr = getRPr(factory, "黑体", "000000", "28", STHint.EAST_ASIA,
			true, false, false, false);
	RPr boldRPr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA,
			true, false, false, false);
	RPr fontRPr = getRPr(factory, "宋体", "000000", "20", STHint.EAST_ASIA,
			false, false, false, false);
	P paragraph = factory.createP();
	setParagraphAlign(factory, paragraph, JcEnumeration.CENTER);
	Text txt = factory.createText();
	txt.setValue("七年级上册Unit2 This is just a test. sectionA测试卷答题卡");
	R run = factory.createR();
	run.getContent().add(txt);
	run.setRPr(titleRPr);
	paragraph.getContent().add(run);
	t.addObject(paragraph);

	paragraph = factory.createP();
	setParagraphAlign(factory, paragraph, JcEnumeration.CENTER);
	txt = factory.createText();
	txt.setValue("班级:________    姓名:________");
	run = factory.createR();
	run.getContent().add(txt);
	run.setRPr(fontRPr);
	paragraph.getContent().add(run);
	t.addObject(paragraph);

	paragraph = factory.createP();
	txt = factory.createText();
	txt.setValue("一、单选题");
	run = factory.createR();
	run.getContent().add(txt);
	run.setRPr(boldRPr);
	paragraph.getContent().add(run);
	t.addObject(paragraph);

	paragraph = factory.createP();
	txt = factory.createText();
	txt.setValue("1.下列有关仪器用途的说法错误的是(    )");
	run = factory.createR();
	run.getContent().add(txt);
	run.setRPr(fontRPr);
	paragraph.getContent().add(run);
	t.addObject(paragraph);

	paragraph = factory.createP();
	txt = factory.createText();
	txt.setValue("A.烧杯用于较多量试剂的反应容器");
	run = factory.createR();
	run.getContent().add(txt);
	run.setRPr(fontRPr);
	paragraph.getContent().add(run);
	t.addObject(paragraph);

	paragraph = factory.createP();
	txt = factory.createText();
	txt.setValue("B.烧杯用于较多量试剂的反应容器");
	run = factory.createR();
	run.getContent().add(txt);
	run.setRPr(fontRPr);
	paragraph.getContent().add(run);
	t.addObject(paragraph);

	paragraph = factory.createP();
	txt = factory.createText();
	txt.setValue("C.烧杯用于较多量试剂的反应容器");
	run = factory.createR();
	run.getContent().add(txt);
	run.setRPr(fontRPr);
	paragraph.getContent().add(run);
	t.addObject(paragraph);

	paragraph = factory.createP();
	txt = factory.createText();
	txt.setValue("D.烧杯用于较多量试剂的反应容器");
	run = factory.createR();
	run.getContent().add(txt);
	run.setRPr(fontRPr);
	paragraph.getContent().add(run);
	t.addObject(paragraph);
}
 
Example 18
Source File: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 4 votes vote down vote up
public P newImage(WordprocessingMLPackage wordMLPackage,
		ObjectFactory factory, Part sourcePart, byte[] bytes,
		String filenameHint, String altText, int id1, int id2,
		boolean isUnderLine, String underLineSize,
		JcEnumeration jcEnumeration) throws Exception {
	BinaryPartAbstractImage imagePart = BinaryPartAbstractImage
			.createImagePart(wordMLPackage, sourcePart, bytes);
	Inline inline = imagePart.createImageInline(filenameHint, altText, id1,
			id2, false);
	P p = factory.createP();
	R run = factory.createR();
	p.getContent().add(run);
	Drawing drawing = factory.createDrawing();
	run.getContent().add(drawing);
	drawing.getAnchorOrInline().add(inline);
	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);
	p.setPPr(pPr);

	if (isUnderLine) {
		PBdr pBdr = pPr.getPBdr();
		if (pBdr == null) {
			pBdr = factory.createPPrBasePBdr();
		}
		CTBorder value = new CTBorder();
		value.setVal(STBorder.SINGLE);
		value.setColor("000000");
		value.setSpace(new BigInteger("0"));
		value.setSz(new BigInteger(underLineSize));
		pBdr.setBetween(value);
		pPr.setPBdr(pBdr);
	}
	setParagraphSpacing(factory, p, jcEnumeration, true, "0", "0", null,
			null, true, "240", STLineSpacingRule.AUTO);
	return p;
}
 
Example 19
Source File: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 4 votes vote down vote up
public Ftr getTextFtr(WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, Part sourcePart, String content,
		boolean isUnderLine, String underLineSz, JcEnumeration jcEnumeration)
		throws Exception {
	Ftr ftr = factory.createFtr();
	P footerP = factory.createP();
	Text text = factory.createText();
	text.setValue(content);
	R run = factory.createR();
	run.getContent().add(text);
	footerP.getContent().add(run);

	PPr pPr = footerP.getPPr();
	if (pPr == null) {
		pPr = factory.createPPr();
	}
	Jc jc = pPr.getJc();
	if (jc == null) {
		jc = new Jc();
	}
	jc.setVal(jcEnumeration);
	pPr.setJc(jc);
	footerP.setPPr(pPr);
	setParagraphSpacing(factory, footerP, jcEnumeration, true, "0", "0",
			null, null, true, "240", STLineSpacingRule.AUTO);
	if (isUnderLine) {
		PBdr pBdr = pPr.getPBdr();
		if (pBdr == null) {
			pBdr = factory.createPPrBasePBdr();
		}
		CTBorder value = new CTBorder();
		value.setVal(STBorder.SINGLE);
		value.setColor("000000");
		value.setSpace(new BigInteger("0"));
		value.setSz(new BigInteger(underLineSz));
		pBdr.setBetween(value);
		pPr.setPBdr(pBdr);
		footerP.setPPr(pPr);
	}
	ftr.getContent().add(footerP);
	if (isUnderLine) {
		ftr.getContent().add(
				createHeaderBlankP(wordprocessingMLPackage, factory,
						underLineSz, jcEnumeration));
	}
	return ftr;
}
 
Example 20
Source File: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 4 votes vote down vote up
public Ftr createFooterWithPageNr(
		WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, boolean isUnderLine, String underLineSz,
		JcEnumeration jcEnumeration) throws Exception {
	Ftr ftr = factory.createFtr();
	P paragraph = factory.createP();
	RPr fontRPr = getRPr(factory, "宋体", "000000", "20", STHint.EAST_ASIA,
			false, false, false, false);
	R run = factory.createR();
	run.setRPr(fontRPr);
	paragraph.getContent().add(run);

	addPageTextField(factory, paragraph, "第");
	addFieldBegin(factory, paragraph);
	addPageNumberField(factory, paragraph);
	addFieldEnd(factory, paragraph);
	addPageTextField(factory, paragraph, "页");

	addPageTextField(factory, paragraph, " 总共");
	addFieldBegin(factory, paragraph);
	addTotalPageNumberField(factory, paragraph);
	addFieldEnd(factory, paragraph);
	addPageTextField(factory, paragraph, "页");
	setParagraphSpacing(factory, paragraph, jcEnumeration, true, "0", "0",
			null, null, true, "240", STLineSpacingRule.AUTO);
	PPr pPr = paragraph.getPPr();
	if (pPr == null) {
		pPr = factory.createPPr();
	}
	Jc jc = pPr.getJc();
	if (jc == null) {
		jc = new Jc();
	}
	jc.setVal(jcEnumeration);
	pPr.setJc(jc);
	if (isUnderLine) {
		PBdr pBdr = pPr.getPBdr();
		if (pBdr == null) {
			pBdr = factory.createPPrBasePBdr();
		}
		CTBorder value = new CTBorder();
		value.setVal(STBorder.SINGLE);
		value.setColor("000000");
		value.setSpace(new BigInteger("0"));
		value.setSz(new BigInteger(underLineSz));
		pBdr.setBetween(value);
		pPr.setPBdr(pBdr);
		paragraph.setPPr(pPr);
	}
	ftr.getContent().add(paragraph);
	if (isUnderLine) {
		ftr.getContent().add(
				createHeaderBlankP(wordprocessingMLPackage, factory,
						underLineSz, jcEnumeration));
	}
	return ftr;
}