• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Text类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: addStyling

import org.docx4j.wml.Text; //导入依赖的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: getTable

import org.docx4j.wml.Text; //导入依赖的package包/类
/**
 * 该方法找到表格,获取第一行并且遍历提供的map向表格添加新行,在将其返回之前删除模版行。这个方法用到了两个助手方法:addRowToTable 和 getTemplateTable。我们首先看一下后面的那个: 
 */
public static Tbl getTable(List<Tbl> tables, String placeholder) throws Docx4JException {  
       for (Iterator<Tbl> iterator = tables.iterator(); iterator.hasNext();) {  
       	Tbl tbl = iterator.next();
       	//查找当前table下面的text对象
           List<Text> textElements = getTargetElements(tbl, Text.class);  
           for (Text text : textElements) {
               Text textElement = (Text) text;
               //
               if (textElement.getValue() != null && textElement.getValue().equals(placeholder))  {
                   return (Tbl) tbl;  
               }
           }  
       }  
       return null;  
   }
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:19,代码来源:WMLPackageUtils.java


示例3: setNewTcContent

import org.docx4j.wml.Text; //导入依赖的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


示例4: createCommentRound

import org.docx4j.wml.Text; //导入依赖的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


示例5: createComment

import org.docx4j.wml.Text; //导入依赖的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


示例6: addStyling

import org.docx4j.wml.Text; //导入依赖的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


示例7: getFormattedTextForLineElement

import org.docx4j.wml.Text; //导入依赖的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


示例8: createComment

import org.docx4j.wml.Text; //导入依赖的package包/类
private static org.docx4j.wml.Comments.Comment createComment(java.math.BigInteger commentId,
    		String author, Calendar date, String message) {

		org.docx4j.wml.Comments.Comment comment = factory.createCommentsComment();
		comment.setId( commentId );
		if (author!=null) {
			comment.setAuthor(author);
		}
		if (date!=null) {
//			String dateString = RFC3339_FORMAT.format(date.getTime()) ;	
//			comment.setDate(value)
			// TODO - at present this is XMLGregorianCalendar
		}
		org.docx4j.wml.P commentP = factory.createP();
		comment.getEGBlockLevelElts().add(commentP);
		org.docx4j.wml.R commentR = factory.createR();
		commentP.getContent().add(commentR);
		org.docx4j.wml.Text commentText = factory.createText();
		commentR.getContent().add(commentText);
		
		commentText.setValue(message);
    	
    	return comment;
    }
 
开发者ID:Transkribus,项目名称:TranskribusCore,代码行数:25,代码来源:DocxBuilder.java


示例9: extractTextFromParagraph

import org.docx4j.wml.Text; //导入依赖的package包/类
/**
 * Extract text from the paragraph and append it to the provided {@link StringBuilder}.
 *
 * @param stringBuilder
 *            The {@link StringBuilder} to append text to.
 * @param formattingData
 *            Formatting data map to update with ranges of paragraph that are formatted.
 * @param paragraph
 *            The docx4j paragraph object
 * @param paragraphProperties
 *            The docx4j paragraph properties
 * @param styleMap
 *            The extracted styles from the main document
 * @param mainDoc
 *            The main document object
 */
private void extractTextFromParagraph(final StringBuilder stringBuilder, final Map<FormattingType, Set<TextRange>> formattingData,
		final P paragraph, final PPr paragraphProperties, final Map<String, Style> styleMap, final MainDocumentPart mainDoc) {
	for (final Object paragraphChild : paragraph.getContent()) {
		if (paragraphChild instanceof R) {
			final R run = (R) paragraphChild;
			for (final Object runChild : run.getContent()) {
				if (runChild instanceof JAXBElement && ((JAXBElement<?>) runChild).getDeclaredType() == Text.class) {
					final String childText = ((Text) ((JAXBElement<?>) runChild).getValue()).getValue();
					final TextRange childRange = new TextRange(stringBuilder.length(), stringBuilder.length() + childText.length());

					stringBuilder.append(childText);
					extractFormattingData(run, childRange, formattingData, paragraphProperties, styleMap, mainDoc);
				}
			}
		}
	}
}
 
开发者ID:mizitch,项目名称:story-inspector,代码行数:34,代码来源:DocXDocumentExtractor.java


示例10: createRun

import org.docx4j.wml.Text; //导入依赖的package包/类
private R createRun(final String styleId, final String text) {
	final R r = this.wmlObjectFactory.createR();

	final RPr rpr = this.wmlObjectFactory.createRPr();
	r.setRPr(rpr);

	if (styleId != null) {
		final RStyle rstyle = this.wmlObjectFactory.createRStyle();
		rstyle.setVal(styleId);
		rpr.setRStyle(rstyle);
	}

	final Text textElement = this.wmlObjectFactory.createText();
	textElement.setValue(text);
	final JAXBElement<Text> wrappedText = this.wmlObjectFactory.createRT(textElement);
	r.getContent().add(wrappedText);

	return r;
}
 
开发者ID:mizitch,项目名称:story-inspector,代码行数:20,代码来源:DocXReportSummaryWriter.java


示例11: addHeaderParagraphOfText

import org.docx4j.wml.Text; //导入依赖的package包/类
/**
 *
 * @param mainDocumentPart
 * @param workItemID
 * @param simpleText
 * @param styleId
 * @return
 */
private static P addHeaderParagraphOfText(MainDocumentPart mainDocumentPart, Integer workItemID, String simpleText, String styleId) {
	ObjectFactory factory = Context.getWmlObjectFactory();
	P p = factory.createP();
	if (simpleText!=null) {
		Text t = factory.createText();
		t.setValue(simpleText);
		R run = factory.createR();
		run.getContent().add(t);
		p.getContent().add(run);
		BookmarkAdd.bookmarkRun(p, run, ITEM_BOOKMARK_PREFIX+workItemID, workItemID);
	}
	if (mainDocumentPart.getPropertyResolver().activateStyle(styleId)) {
		// Style is available
		org.docx4j.wml.PPr  pPr = factory.createPPr();
		p.setPPr(pPr);
		org.docx4j.wml.PPrBase.PStyle pStyle = factory.createPPrBasePStyle();
		pPr.setPStyle(pStyle);
		pStyle.setVal(styleId);
	} else {
		LOGGER.debug("StyleID " + styleId + " not available");
	}
	return p;
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:32,代码来源:AssembleWordprocessingMLPackage.java


示例12: mergeMatchedTexts

import org.docx4j.wml.Text; //导入依赖的package包/类
public Set<Text> mergeMatchedTexts() {
    for (Object paragraphContentObject : paragraph.getContent()) {
        if (paragraphContentObject instanceof R) {
            R currentRun = (R) paragraphContentObject;
            for (Object runContentObject : currentRun.getContent()) {
                Object unwrappedRunContentObject = XmlUtils.unwrap(runContentObject);
                if (unwrappedRunContentObject instanceof Text) {
                    handleText((Text) unwrappedRunContentObject);
                }
            }
        }
    }

    removeUnnecessaryTexts();

    return resultingTexts;
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:18,代码来源:TextMerger.java


示例13: handleMatchedText

import org.docx4j.wml.Text; //导入依赖的package包/类
protected void handleMatchedText() {
    resultingTexts.add(startText);
    startText.setValue(mergedTextsString.toString());
    for (Text mergedText : mergedTexts) {
        if (mergedText != startText) {
            mergedText.setValue("");
            textsToRemove.add(mergedText);
        }
    }

    if (!containsStartOfRegexp(startText.getValue().replaceAll(regexp, ""))) {
        startText = null;
        mergedTexts = null;
        mergedTextsString = null;
    } else {
        mergedTexts = new HashSet<Text>();
        mergedTexts.add(startText);
        mergedTextsString = new StringBuilder(startText.getValue());
    }
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:21,代码来源:TextMerger.java


示例14: findNameForCurrentTable

import org.docx4j.wml.Text; //导入依赖的package包/类
protected void findNameForCurrentTable(final TableManager currentTable) {
    new TraversalUtil(currentTable.firstRow,
            new RegexpFinder<P>(docxFormatter, AbstractFormatter.BAND_NAME_DECLARATION_PATTERN, P.class) {
                @Override
                protected void onFind(P paragraph, Matcher matcher) {
                    if (currentTable.bandName == null) {
                        super.onFind(paragraph, matcher);
                        currentTable.bandName = matcher.group(1);
                        String bandNameDeclaration = matcher.group();
                        Set<Text> mergedTexts = new TextMerger(paragraph, bandNameDeclaration).mergeMatchedTexts();
                        for (Text text : mergedTexts) {
                            text.setValue(text.getValue().replace(bandNameDeclaration, ""));
                        }
                    }
                }
            });
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:18,代码来源:TableCollector.java


示例15: inlineToDocx

import org.docx4j.wml.Text; //导入依赖的package包/类
@Override
public void inlineToDocx(WordprocessingMLPackage wordPackage, Text text, Object paramValue, Matcher paramsMatcher) {
    try {
        Image image = new Image(paramValue, paramsMatcher);
        if (image.isValid()) {
            BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordPackage, resolveTextPartForDOCX(text, wordPackage),
                    image.imageContent);
            Inline inline = imagePart.createImageInline("", "", docxUniqueId1++, docxUniqueId2++, false);
            ImageSize oldSize = imagePart.getImageInfo().getSize();
            double widthExtent = (double) image.width / oldSize.getWidthPx();
            double heightExtent = (double) image.height / oldSize.getHeightPx();
            inline.getExtent().setCx((long) (inline.getExtent().getCx() * widthExtent));
            inline.getExtent().setCy((long) (inline.getExtent().getCy() * heightExtent));
            org.docx4j.wml.Drawing drawing = new org.docx4j.wml.ObjectFactory().createDrawing();
            R run = (R) text.getParent();
            run.getContent().add(drawing);
            drawing.getAnchorOrInline().add(inline);
            text.setValue("");
        }
    } catch (Exception e) {
        throw new ReportFormattingException("An error occurred while inserting bitmap to docx file", e);
    }
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:24,代码来源:AbstractInliner.java


示例16: resolveTextPartForDOCX

import org.docx4j.wml.Text; //导入依赖的package包/类
protected Part resolveTextPartForDOCX(Text text, WordprocessingMLPackage wordPackage) {
    java.util.List<SectionWrapper> sectionWrappers = wordPackage.getDocumentModel().getSections();
    for (SectionWrapper sw : sectionWrappers) {
        HeaderFooterPolicy hfp = sw.getHeaderFooterPolicy();
        List<Part> parts = Arrays.<Part>asList(hfp.getFirstHeader(), hfp.getDefaultHeader(), hfp.getEvenHeader(),
                hfp.getFirstFooter(), hfp.getDefaultFooter(), hfp.getEvenFooter());
        for (Part part : parts) {
            TextMatchCallback callback = new TextMatchCallback(text);
            new TraversalUtil(part, callback);
            if (callback.matched) {
                return part;
            }
        }
    }
    return wordPackage.getMainDocumentPart();
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:17,代码来源:AbstractInliner.java


示例17: getTextOfObject

import org.docx4j.wml.Text; //导入依赖的package包/类
/**
 * @param object
 *
 * @return
 */
private String getTextOfObject(Object object) {
    // object can be org.docx4j.wml.P, org.docx4j.wml.R etc
    List<Object> texts = getAllElementFromObject(object, Text.class);
    String result = "";
    for (Object o : texts) {
        Text t = (Text) o;
        result += t.getValue();
    }
    return result;
}
 
开发者ID:tokgozmusa,项目名称:docx4j-word-data-extractor,代码行数:16,代码来源:DocxExtractor.java


示例18: replacePlaceholder

import org.docx4j.wml.Text; //导入依赖的package包/类
/**
 * 例如你动态设置一个文档的标题。首先,在前面创建的模版文档中添加一个自定义占位符,我使用SJ_EX1作为占位符,我们将要用name参数来替换这个值。
 * 在docx4j中基本的文本元素用org.docx4j.wml.Text类来表示,替换这个简单的占位符我们需要做的就是调用这个方法: 
 */
public static void replacePlaceholder(WordprocessingMLPackage template, String name, String placeholder ) { 
	//获取文档对象中所有的Text类型对象
    List<Text> texts = getTargetElements(template.getMainDocumentPart(), Text.class);  
   //循环Text类型对象集合
    for (Text text : texts) {  
        Text textElement = (Text) text;  
        if (textElement.getValue().equals(placeholder)) {  
            textElement.setValue(name);  
        }  
    }  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:16,代码来源:WMLPackageUtils.java


示例19: addRowToTable

import org.docx4j.wml.Text; //导入依赖的package包/类
public static void addRowToTable(Tbl reviewtable, Tr templateRow, Map<String, String> replacements) {  
    Tr workingRow = (Tr) XmlUtils.deepCopy(templateRow);  
    List<?> textElements = getTargetElements(workingRow, Text.class);  
    for (Object object : textElements) {  
        Text text = (Text) object;  
        String replacementValue = (String) replacements.get(text.getValue());  
        if (replacementValue != null)  
            text.setValue(replacementValue);  
    }  
  
    reviewtable.getContent().add(workingRow);  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:13,代码来源:WMLPackageUtils.java


示例20: createFooter

import org.docx4j.wml.Text; //导入依赖的package包/类
/**
    *  First we create a footer, a paragraph, a run and a text. We add the given
    *  given content to the text and add that to the run. The run is then added to
    *  the paragraph, which is in turn added to the footer. Finally we return the
    *  footer.
    *  @param content
    *  @return
    */
public static Ftr createFooter(String content) {
       Ftr footer = factory.createFtr();
       P paragraph = factory.createP();
       R run = factory.createR();
       Text text = new Text();
       text.setValue(content);
       run.getContent().add(text);
       paragraph.getContent().add(run);
       footer.getContent().add(paragraph);
       return footer;
   }
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:20,代码来源:WmlElementUtils.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CannotWriteException类代码示例发布时间:2022-05-21
下一篇:
Java EditorTextField类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap