当前位置: 首页>>代码示例>>Java>>正文


Java P类代码示例

本文整理汇总了Java中org.docx4j.wml.P的典型用法代码示例。如果您正苦于以下问题:Java P类的具体用法?Java P怎么用?Java P使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


P类属于org.docx4j.wml包,在下文中一共展示了P类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addStyling

import org.docx4j.wml.P; //导入依赖的package包/类
/** 
 *  这里我们添加实际的样式信息, 首先创建一个段落, 然后创建以单元格内容作为值的文本对象;  
 *  第三步, 创建一个被称为运行块的对象, 它是一块或多块拥有共同属性的文本的容器, 并将文本对象添加 
 *  到其中. 随后我们将运行块R添加到段落内容中. 
 *  直到现在我们所做的还没有添加任何样式, 为了达到目标, 我们创建运行块属性对象并给它添加各种样式. 
 *  这些运行块的属性随后被添加到运行块. 最后段落被添加到表格的单元格中. 
 */  
public void addStyling(Tc tableCell, String content, boolean bold, String fontSize) {  
    P paragraph = factory.createP();  
   
    Text text = factory.createText();  
    text.setValue(content);  
   
    R run = factory.createR();  
    run.getContent().add(text);  
   
    paragraph.getContent().add(run);  
   
    RPr runProperties = factory.createRPr();  
    if (bold) {  
        addBoldStyle(runProperties);  
    }  
   
    if (fontSize != null && !fontSize.isEmpty()) {  
        setFontSize(runProperties, fontSize);  
    }  
   
    run.setRPr(runProperties);  
   
    tableCell.getContent().add(paragraph);  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:32,代码来源:WordprocessingMLPackageRender.java

示例2: main

import org.docx4j.wml.P; //导入依赖的package包/类
/**
 *  首先我们创建包和对象工厂, 因此在类的随处我们都可以使用它们. 然后我们创建一个表格并添加
 *  边框. 接下来我们创建一个表格行并在第一个域添加一些文本.
 *  对于第二个域, 我们用与前面一样的图片创建一个段落并添加进去. 最后把行添加到表格中, 并将
 *  表格添加到包中, 然后保存这个包.
 */
public static void main (String[] args) throws Exception {
    wordMLPackage = WordprocessingMLPackage.createPackage();
    factory = Context.getWmlObjectFactory();
 
    Tbl table = factory.createTbl();
    addBorders(table);
 
    Tr tr = factory.createTr();
 
    P paragraphOfText = wordMLPackage.getMainDocumentPart().createParagraphOfText("Field 1");
    addTableCell(tr, paragraphOfText);
 
    File file = new File("src/main/resources/iProfsLogo.png");
    P paragraphWithImage = addInlineImageToParagraph(createInlineImage(file));
    addTableCell(tr, paragraphWithImage);
 
    table.getContent().add(tr);
 
    wordMLPackage.getMainDocumentPart().addObject(table);
    wordMLPackage.save(new java.io.File("src/main/files/HelloWord8.docx"));
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:28,代码来源:AddingAnInlineImageToTable.java

示例3: writeImage

import org.docx4j.wml.P; //导入依赖的package包/类
@Override
public void writeImage(final BufferedImage image) {
	final P imageParagraph = this.wmlObjectFactory.createP();

	final R imageRun = this.wmlObjectFactory.createR();
	imageParagraph.getContent().add(imageRun);

	final Drawing drawing = this.wmlObjectFactory.createDrawing();
	imageRun.getContent().add(drawing);

	try {
		final ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
		ImageIO.write(image, "PNG", byteOutputStream);
		final BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(this.extractedDocument.getDocumentPackage(),
				byteOutputStream.toByteArray());
		final Inline imageInline = imagePart.createImageInline("Filename", "An image", nextUniqueImageId(), nextUniqueImageId(), false);

		drawing.getAnchorOrInline().add(imageInline);
	} catch (final Exception e) {
		throw new RuntimeException(e);
	}

	addParagraph(imageParagraph);
}
 
开发者ID:mizitch,项目名称:story-inspector,代码行数:25,代码来源:DocXReportSummaryWriter.java

示例4: setTcHidden

import org.docx4j.wml.P; //导入依赖的package包/类
/**
 * @Description: 隐藏单元格内容
 */
public void setTcHidden(Tc tc, boolean hidden) {
    List<P> pList = getTcAllP(tc);
    for (P p : pList) {
        PPr ppr = getPPr(p);
        List<Object> objRList = getAllElementFromObject(p, R.class);
        if (objRList == null) {
            continue;
        }
        for (Object objR : objRList) {
            if (objR instanceof R) {
                R r = (R) objR;
                RPr rpr = getRPr(r);
                setRPrVanishStyle(rpr, hidden);
            }
        }
        setParaVanish(ppr, hidden);
    }
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:22,代码来源:Docx4j_工具类_S3_Test.java

示例5: removeParaByIndex

import org.docx4j.wml.P; //导入依赖的package包/类
/**
 * @Description: 只删除单独的段落,不包括表格内或其他内的段落
 */
public boolean removeParaByIndex(WordprocessingMLPackage wordMLPackage,
        int index) {
    boolean flag = false;
    if (index < 0) {
        return flag;
    }
    List<Object> objList = wordMLPackage.getMainDocumentPart().getContent();
    if (objList == null) {
        return flag;
    }
    int k = -1;
    for (int i = 0, len = objList.size(); i < len; i++) {
        if (objList.get(i) instanceof P) {
            k++;
            if (k == index) {
                wordMLPackage.getMainDocumentPart().getContent().remove(i);
                flag = true;
                break;
            }
        }
    }
    return flag;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:27,代码来源:Docx4j_工具类_S3_Test.java

示例6: setParagraghBorders

import org.docx4j.wml.P; //导入依赖的package包/类
/**
 * @Description: 设置段落边框样式
 */
public void setParagraghBorders(P p, CTBorder topBorder,
        CTBorder bottomBorder, CTBorder leftBorder, CTBorder rightBorder) {
    PPr ppr = getPPr(p);
    PBdr pBdr = new PBdr();
    if (topBorder != null) {
        pBdr.setTop(topBorder);
    }
    if (bottomBorder != null) {
        pBdr.setBottom(bottomBorder);
    }
    if (leftBorder != null) {
        pBdr.setLeft(leftBorder);
    }
    if (rightBorder != null) {
        pBdr.setRight(rightBorder);
    }
    ppr.setPBdr(pBdr);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:22,代码来源:Docx4j_工具类_S3_Test.java

示例7: setNewTcContent

import org.docx4j.wml.P; //导入依赖的package包/类
/** 
 * 设置单元格内容 
 *  
 * @param tc 
 * @param content 
 */  
public static void setNewTcContent(Tc tc, String content) {  
    P p = factory.createP();  
    tc.getContent().add(p);  
    R run = factory.createR();  
    p.getContent().add(run);  
    if (content != null) {  
        String[] contentArr = content.split("\n");  
        Text text = factory.createText();  
        text.setSpace("preserve");  
        text.setValue(contentArr[0]);  
        run.getContent().add(text);  
  
        for (int i = 1, len = contentArr.length; i < len; i++) {  
            Br br = factory.createBr();  
            run.getContent().add(br);// 换行  
            text = factory.createText();  
            text.setSpace("preserve");  
            text.setValue(contentArr[i]);  
            run.getContent().add(text);  
        }  
    }  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:29,代码来源:Docx4j_替换模板.java

示例8: createCommentRound

import org.docx4j.wml.P; //导入依赖的package包/类
public void createCommentRound(ObjectFactory factory, P p, String pContent,  
        String commentContent, RPr fontRPr, RPr commentRPr,  
        BigInteger commentId, Comments comments) throws Exception {  
    CommentRangeStart startComment = factory.createCommentRangeStart();  
    startComment.setId(commentId);  
    p.getContent().add(startComment);  
    R run = factory.createR();  
    Text txt = factory.createText();  
    txt.setValue(pContent);  
    run.getContent().add(txt);  
    run.setRPr(fontRPr);  
    p.getContent().add(run);  
    CommentRangeEnd endComment = factory.createCommentRangeEnd();  
    endComment.setId(commentId);  
    p.getContent().add(endComment);  
    Comment commentOne = createComment(factory, commentId, "系统管理员",  
            new Date(), commentContent, commentRPr);  
    comments.getComment().add(commentOne);  
    p.getContent().add(createRunCommentReference(factory, commentId));  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:21,代码来源:Docx4j_创建批注_S3_Test.java

示例9: createComment

import org.docx4j.wml.P; //导入依赖的package包/类
public Comments.Comment createComment(ObjectFactory factory,  
        BigInteger commentId, String author, Date date,  
        String commentContent, RPr commentRPr) throws Exception {  
    Comments.Comment comment = factory.createCommentsComment();  
    comment.setId(commentId);  
    if (author != null) {  
        comment.setAuthor(author);  
    }  
    if (date != null) {  
        comment.setDate(toXMLCalendar(date));  
    }  
    P commentP = factory.createP();  
    comment.getEGBlockLevelElts().add(commentP);  
    R commentR = factory.createR();  
    commentP.getContent().add(commentR);  
    Text commentText = factory.createText();  
    commentR.getContent().add(commentText);  
    commentR.setRPr(commentRPr);  
    commentText.setValue(commentContent);  
    return comment;  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:22,代码来源:Docx4j_创建批注_S3_Test.java

示例10: createFooterWithPageNr

import org.docx4j.wml.P; //导入依赖的package包/类
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;  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:25,代码来源:Docx4J_简单例子2.java

示例11: addStyling

import org.docx4j.wml.P; //导入依赖的package包/类
/**
 *  这里我们添加实际的样式信息, 首先创建一个段落, 然后创建以单元格内容作为值的文本对象; 
 *  第三步, 创建一个被称为运行块的对象, 它是一块或多块拥有共同属性的文本的容器, 并将文本对象添加
 *  到其中. 随后我们将运行块R添加到段落内容中.
 *  直到现在我们所做的还没有添加任何样式, 为了达到目标, 我们创建运行块属性对象并给它添加各种样式.
 *  这些运行块的属性随后被添加到运行块. 最后段落被添加到表格的单元格中.
 */
private static void addStyling(Tc tableCell, String content, boolean bold, String fontSize) {
    P paragraph = factory.createP();
 
    Text text = factory.createText();
    text.setValue(content);
 
    R run = factory.createR();
    run.getContent().add(text);
 
    paragraph.getContent().add(run);
 
    RPr runProperties = factory.createRPr();
    if (bold) {
        addBoldStyle(runProperties);
    }
 
    if (fontSize != null && !fontSize.isEmpty()) {
        setFontSize(runProperties, fontSize);
    }
 
    run.setRPr(runProperties);
 
    tableCell.getContent().add(paragraph);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:32,代码来源:TableWithStyledContent.java

示例12: newImage

import org.docx4j.wml.P; //导入依赖的package包/类
public P newImage(WordprocessingMLPackage wordMLPackage,  
        ObjectFactory factory, byte[] bytes, String filenameHint,  
        String altText, int id1, int id2, long cx) throws Exception {  
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage  
            .createImagePart(wordMLPackage, bytes);  
    Inline inline = imagePart.createImageInline(filenameHint, altText, id1,  
            id2, cx, false);  
    // Now add the inline in w:p/w:r/w:drawing  
    P p = factory.createP();  
    R run = factory.createR();  
    p.getContent().add(run);  
    Drawing drawing = factory.createDrawing();  
    run.getContent().add(drawing);  
    drawing.getAnchorOrInline().add(inline);  
    return p;  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:17,代码来源:Docx4j_创建表格_S5_Test.java

示例13: createFooterWithPageNr

import org.docx4j.wml.P; //导入依赖的package包/类
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;
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:25,代码来源:Docx4J_简单例子.java

示例14: addParagraph

import org.docx4j.wml.P; //导入依赖的package包/类
private static void addParagraph(String mdName, String mdValue, MainDocumentPart mdp, String style) {
		
		if (mdValue != null && !mdValue.equals("")){
			org.docx4j.wml.P  p = mdp.createStyledParagraphOfText(style, mdName + mdValue);
			
			mdp.addObject(p);
			
//			org.docx4j.wml.Text  t = factory.createText();
//			t.setValue(mdName + mdValue);
//			t.setSpace("preserve");
//					
//			org.docx4j.wml.R  run = factory.createR();
//			p.getContent().add(run);
//			run.getContent().add(t);
//			
//		    org.docx4j.wml.PPr  pPr = factory.createPPr();
//	        p.setPPr(pPr);
//	        		
//		    org.docx4j.wml.PPrBase.PStyle pStyle = factory.createPPrBasePStyle();
//		    pPr.setPStyle(pStyle);
//		    pStyle.setVal(style);
		}
		
	}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:25,代码来源:DocxBuilder.java

示例15: getFormattedTextForLineElement

import org.docx4j.wml.P; //导入依赖的package包/类
private static void getFormattedTextForLineElement(List<WordType> lines, P p, MainDocumentPart mdp) throws Exception{
	
	int wordCount = 0;
	int nrWords = lines.size();
	
	for (WordType word : lines){
		getFormattedTextForShapeElement((ITrpShapeType) word, p, mdp);
		//add empty space after each word
		if (wordCount < nrWords-1){
			org.docx4j.wml.Text  t = factory.createText();
			t.setValue(" ");
			t.setSpace("preserve");
			
			org.docx4j.wml.R  run = factory.createR();
			p.getContent().add(run);
			run.getContent().add(t);
		}
		wordCount++;
	}

}
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:22,代码来源:DocxBuilder.java


注:本文中的org.docx4j.wml.P类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。