org.docx4j.wml.JcEnumeration Java Examples

The following examples show how to use org.docx4j.wml.JcEnumeration. 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 10 votes vote down vote up
public Ftr getFtr(WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, Part sourcePart, boolean isUnderLine,
		String underLineSz) throws Exception {
	Ftr ftr = factory.createFtr();
	File file = new File("f:/saveFile/tmp/xxt.jpg");
	java.io.InputStream is = new java.io.FileInputStream(file);
	ftr.getContent().add(
			newImage(wordprocessingMLPackage, factory, sourcePart,
					BufferUtil.getBytesFromInputStream(is), "filename",
					"这是页脚", 1, 2, isUnderLine, underLineSz,
					JcEnumeration.CENTER));
	if (isUnderLine) {
		ftr.getContent().add(
				createHeaderBlankP(wordprocessingMLPackage, factory,
						underLineSz, JcEnumeration.CENTER));
	}
	return ftr;
}
 
Example #2
Source File: Docx4j_创建批注_S3_Test.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public void setParagraphAlign(ObjectFactory factory, P p,  
        JcEnumeration jcEnumeration, TextAlignment textAlign) {  
    PPr pPr = p.getPPr();  
    if (pPr == null) {  
        pPr = factory.createPPr();  
    }  
    if (jcEnumeration != null) {  
        Jc jc = pPr.getJc();  
        if (jc == null) {  
            jc = new Jc();  
        }  
        jc.setVal(jcEnumeration);  
        pPr.setJc(jc);  
    }  
    if (textAlign != null) {  
        pPr.setTextAlignment(textAlign);  
    }  
    p.setPPr(pPr);  
}
 
Example #3
Source File: Docx4J_简单例子2.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 #4
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 #5
Source File: Docx4J_例子2.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public Hdr getHdr(WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, Part sourcePart, boolean isUnderLine,
		String underLineSize) throws Exception {
	Hdr hdr = factory.createHdr();
	File file = new File("f:/saveFile/tmp/xxt.jpg");
	java.io.InputStream is = new java.io.FileInputStream(file);
	hdr.getContent().add(
			newImage(wordprocessingMLPackage, factory, sourcePart,
					BufferUtil.getBytesFromInputStream(is), "filename",
					"这是页眉部分", 1, 2, isUnderLine, underLineSize,
					JcEnumeration.CENTER));
	if (isUnderLine) {
		hdr.getContent().add(
				createHeaderBlankP(wordprocessingMLPackage, factory,
						underLineSize, JcEnumeration.CENTER));
	}
	return hdr;
}
 
Example #6
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 #7
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 #8
Source File: Docx4J_简单例子.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 #9
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 #10
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {  
    Docx4J_简单例子 t = new Docx4J_简单例子();  
    WordprocessingMLPackage wordMLPackage = t  
            .createWordprocessingMLPackage();  
    MainDocumentPart mp = wordMLPackage.getMainDocumentPart();  
    ObjectFactory factory = Context.getWmlObjectFactory();  
    //图片页眉  
    //Relationship relationship =t.createHeaderPart(wordMLPackage, mp, factory);  
    //文字页眉  
    Relationship relationship =t.createTextHeaderPart(wordMLPackage, mp, factory, "我是页眉,多创造,少抄袭", JcEnumeration.CENTER);  
    t.createHeaderReference(wordMLPackage, mp, factory, relationship);  
      
    t.addParagraphTest(wordMLPackage, mp, factory);  
    t.addPageBreak(wordMLPackage, factory);  
      
    t.createNormalTableTest(wordMLPackage, mp, factory);  
    //页脚  
    relationship =t.createFooterPageNumPart(wordMLPackage, mp, factory);  
    t.createFooterReference(wordMLPackage, mp, factory, relationship);  
      
    t.saveWordPackage(wordMLPackage, new File(  
            "f:/saveFile/temp/s5_simple.docx"));  
}
 
Example #11
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void createNormalTableTest(WordprocessingMLPackage wordMLPackage,
		MainDocumentPart t, ObjectFactory factory) throws Exception {
	RPr titleRpr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA,
			true, false, false, false);
	RPr contentRpr = getRPr(factory, "宋体", "000000", "22",
			STHint.EAST_ASIA, false, false, false, false);
	Tbl table = factory.createTbl();
	addBorders(table, "2");
	Tr titleRow = factory.createTr();
	addTableCell(factory, wordMLPackage, titleRow, "序号", titleRpr,
			JcEnumeration.CENTER, true, "C6D9F1");
	addTableCell(factory, wordMLPackage, titleRow, "姓甚", titleRpr,
			JcEnumeration.CENTER, true, "C6D9F1");
	addTableCell(factory, wordMLPackage, titleRow, "名谁", titleRpr,
			JcEnumeration.CENTER, true, "C6D9F1");
	addTableCell(factory, wordMLPackage, titleRow, "籍贯", titleRpr,
			JcEnumeration.CENTER, true, "C6D9F1");
	addTableCell(factory, wordMLPackage, titleRow, "营生", titleRpr,
			JcEnumeration.CENTER, true, "C6D9F1");
	table.getContent().add(titleRow);
	for (int i = 0; i < 10; i++) {
		Tr contentRow = factory.createTr();
		addTableCell(factory, wordMLPackage, contentRow, i + "",
				contentRpr, JcEnumeration.CENTER, false, null);
		addTableCell(factory, wordMLPackage, contentRow, "无名氏", contentRpr,
				JcEnumeration.CENTER, false, null);
		addTableCell(factory, wordMLPackage, contentRow, "佚名", contentRpr,
				JcEnumeration.CENTER, false, null);
		addTableCell(factory, wordMLPackage, contentRow, "武林", contentRpr,
				JcEnumeration.CENTER, false, null);
		addTableCell(factory, wordMLPackage, contentRow, "吟诗赋曲",
				contentRpr, JcEnumeration.CENTER, false, null);
		table.getContent().add(contentRow);
	}
	setTableAlign(factory, table, JcEnumeration.CENTER);
	t.addObject(table);
}
 
Example #12
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Ftr getFtr(WordprocessingMLPackage wordprocessingMLPackage,  
        ObjectFactory factory, Part sourcePart) throws Exception {  
    Ftr ftr = factory.createFtr();  
    File file = new File("f:/saveFile/tmp/xxt.jpg");  
    java.io.InputStream is = new java.io.FileInputStream(file);  
    ftr.getContent().add(  
            newImage(wordprocessingMLPackage, factory, sourcePart,  
                    BufferUtil.getBytesFromInputStream(is), "filename",  
                    "这是页脚", 1, 2, JcEnumeration.CENTER));  
    return ftr;  
}
 
Example #13
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 #14
Source File: WmlElementUtils.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
/**
 * @Description: 设置表格水平对齐方式(仅对表格起作用,单元格不一定水平对齐)
 */
public void setTblJcAlign(Tbl tbl, JcEnumeration jcType) {
    if (jcType != null) {
        TblPr tblPr = getTblPr(tbl);
        Jc jc = tblPr.getJc();
        if (jc == null) {
            jc = new Jc();
            tblPr.setJc(jc);
        }
        jc.setVal(jcType);
    }
}
 
Example #15
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public P createImageParagraph(WordprocessingMLPackage wordMLPackage,  
        ObjectFactory factory,P p,String fileName, String content,byte[] bytes,  
        JcEnumeration jcEnumeration) throws Exception {  
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage  
            .createImagePart(wordMLPackage, bytes);  
    Inline inline = imagePart.createImageInline(fileName, "这是图片", 1,  
            2, false);  
    Text text = factory.createText();  
    text.setValue(content);  
    text.setSpace("preserve");  
    R run = factory.createR();  
    p.getContent().add(run);  
    run.getContent().add(text);  
    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);  
    setParagraphSpacing(factory, p, jcEnumeration, "0", "0");  
    return p;  
}
 
Example #16
Source File: Docx4j_创建表格_S5_Test.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void setHorizontalAlignment(P paragraph, JcEnumeration hAlign) {  
    if (hAlign != null) {  
        PPr pprop = new PPr();  
        Jc align = new Jc();  
        align.setVal(hAlign);  
        pprop.setJc(align);  
        paragraph.setPPr(pprop);  
    }  
}
 
Example #17
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 #18
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Relationship createTextHeaderPart(
		WordprocessingMLPackage wordprocessingMLPackage,
		MainDocumentPart t, ObjectFactory factory, String content,
		JcEnumeration jcEnumeration) throws Exception {
	HeaderPart headerPart = new HeaderPart();
	Relationship rel = t.addTargetPart(headerPart);
	headerPart.setJaxbElement(getTextHdr(wordprocessingMLPackage, factory,
			headerPart, content, jcEnumeration));
	return rel;
}
 
Example #19
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Relationship createTextFooterPart(
		WordprocessingMLPackage wordprocessingMLPackage,
		MainDocumentPart t, ObjectFactory factory, String content,
		JcEnumeration jcEnumeration) throws Exception {
	FooterPart footerPart = new FooterPart();
	Relationship rel = t.addTargetPart(footerPart);
	footerPart.setJaxbElement(getTextFtr(wordprocessingMLPackage, factory,
			footerPart, content, jcEnumeration));
	return rel;
}
 
Example #20
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Hdr getHdr(WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, Part sourcePart) throws Exception {
	Hdr hdr = factory.createHdr();
	File file = new File("f:/saveFile/tmp/xxt.jpg");
	java.io.InputStream is = new java.io.FileInputStream(file);
	hdr.getContent().add(
			newImage(wordprocessingMLPackage, factory, sourcePart,
					BufferUtil.getBytesFromInputStream(is), "filename",
					"这是页眉部分", 1, 2, JcEnumeration.CENTER));
	return hdr;
}
 
Example #21
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Ftr getFtr(WordprocessingMLPackage wordprocessingMLPackage,
		ObjectFactory factory, Part sourcePart) throws Exception {
	Ftr ftr = factory.createFtr();
	File file = new File("f:/saveFile/tmp/xxt.jpg");
	java.io.InputStream is = new java.io.FileInputStream(file);
	ftr.getContent().add(
			newImage(wordprocessingMLPackage, factory, sourcePart,
					BufferUtil.getBytesFromInputStream(is), "filename",
					"这是页脚", 1, 2, JcEnumeration.CENTER));
	return ftr;
}
 
Example #22
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public P newImage(WordprocessingMLPackage wordMLPackage,
		ObjectFactory factory, Part sourcePart, byte[] bytes,
		String filenameHint, String altText, int id1, int id2,
		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);
	return p;
}
 
Example #23
Source File: Docx4J_简单例子.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void setTableAlign(ObjectFactory factory, Tbl table,
		JcEnumeration jcEnumeration) {
	TblPr tablePr = table.getTblPr();
	if (tablePr == null) {
		tablePr = factory.createTblPr();
	}
	Jc jc = tablePr.getJc();
	if (jc == null) {
		jc = new Jc();
	}
	jc.setVal(jcEnumeration);
	tablePr.setJc(jc);
	table.setTblPr(tablePr);
}
 
Example #24
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Hdr getHdr(WordprocessingMLPackage wordprocessingMLPackage,  
        ObjectFactory factory, Part sourcePart) throws Exception {  
    Hdr hdr = factory.createHdr();  
    File file = new File("f:/saveFile/tmp/xxt.jpg");  
    java.io.InputStream is = new java.io.FileInputStream(file);  
    hdr.getContent().add(  
            newImage(wordprocessingMLPackage, factory, sourcePart,  
                    BufferUtil.getBytesFromInputStream(is), "filename",  
                    "这是页眉部分", 1, 2, JcEnumeration.CENTER));  
    hdr.getContent().add(createHeaderBlankP(wordprocessingMLPackage, factory,JcEnumeration.CENTER));  
    return hdr;  
}
 
Example #25
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public P newImage(WordprocessingMLPackage wordMLPackage,  
        ObjectFactory factory, Part sourcePart, byte[] bytes,  
        String filenameHint, String altText, int id1, int id2,  
        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);  
      
    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);  
    setParagraphSpacing(factory, p, jcEnumeration, "0", "0");  
    return p;  
}
 
Example #26
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 #27
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void setParagraphAlign(ObjectFactory factory, P p,  
        JcEnumeration jcEnumeration) {  
    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);  
}
 
Example #28
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Relationship createTextFooterPart(  
        WordprocessingMLPackage wordprocessingMLPackage,  
        MainDocumentPart t, ObjectFactory factory, String content,  
        JcEnumeration jcEnumeration) throws Exception {  
    FooterPart footerPart = new FooterPart();  
    Relationship rel = t.addTargetPart(footerPart);  
    footerPart.setJaxbElement(getTextFtr(wordprocessingMLPackage, factory,  
            footerPart, content, jcEnumeration));  
    return rel;  
}
 
Example #29
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public Relationship createTextHeaderPart(  
        WordprocessingMLPackage wordprocessingMLPackage,  
        MainDocumentPart t, ObjectFactory factory, String content,  
        JcEnumeration jcEnumeration) throws Exception {  
    HeaderPart headerPart = new HeaderPart();  
    Relationship rel = t.addTargetPart(headerPart);  
    headerPart.setJaxbElement(getTextHdr(wordprocessingMLPackage, factory,  
            headerPart, content, jcEnumeration));  
    return rel;  
}
 
Example #30
Source File: Docx4J_简单例子2.java    From docx4j-template with Apache License 2.0 5 votes vote down vote up
public void setTableAlign(ObjectFactory factory, Tbl table,  
        JcEnumeration jcEnumeration) {  
    TblPr tablePr = table.getTblPr();  
    if (tablePr == null) {  
        tablePr = factory.createTblPr();  
    }  
    Jc jc = tablePr.getJc();  
    if (jc == null) {  
        jc = new Jc();  
    }  
    jc.setVal(jcEnumeration);  
    tablePr.setJc(jc);  
    table.setTblPr(tablePr);  
}