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


Java Text.setSpace方法代码示例

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


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

示例1: 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

示例2: setParagraphContent

import org.docx4j.wml.Text; //导入方法依赖的package包/类
/** 
 * 设置段落内容 
 */  
private void setParagraphContent(P p, RPr rpr,String content) {  
    Text t = Docx4j_Helper.factory.createText();  
    t.setSpace("preserve");  
    t.setValue(content);  
    R run = Docx4j_Helper.factory.createR();  
    run.setRPr(rpr);  
    run.getContent().add(t);  
    p.getContent().add(run);  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:13,代码来源:Docx4j_Helper.java

示例3: addImageToPara

import org.docx4j.wml.Text; //导入方法依赖的package包/类
/**
 * @Description: 添加图片到段落
 */
public void addImageToPara(WordprocessingMLPackage wordMLPackage,
        ObjectFactory factory, P paragraph, String filePath,
        String content, RPr rpr, String altText, int id1, int id2)
        throws Exception {
    R run = factory.createR();
    if (content != null) {
        Text text = factory.createText();
        text.setValue(content);
        text.setSpace("preserve");
        run.setRPr(rpr);
        run.getContent().add(text);
    }

    InputStream is = new FileInputStream(filePath);
    byte[] bytes = IOUtils.toByteArray(is);
    BinaryPartAbstractImage imagePart = BinaryPartAbstractImage
            .createImagePart(wordMLPackage, bytes);
    Inline inline = imagePart.createImageInline(filePath, altText, id1,
            id2, false);
    Drawing drawing = factory.createDrawing();
    drawing.getAnchorOrInline().add(inline);
    run.getContent().add(drawing);
    paragraph.getContent().add(run);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:28,代码来源:Docx4j_工具类_S3_Test.java

示例4: addPageNumberField

import org.docx4j.wml.Text; //导入方法依赖的package包/类
public void addPageNumberField(ObjectFactory factory, P paragraph) {
	R run = factory.createR();
	Text txt = new Text();
	txt.setSpace("preserve");
	txt.setValue("PAGE  \\* MERGEFORMAT ");
	run.getContent().add(factory.createRInstrText(txt));
	paragraph.getContent().add(run);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:9,代码来源:Docx4J_例子2.java

示例5: addTotalPageNumberField

import org.docx4j.wml.Text; //导入方法依赖的package包/类
public void addTotalPageNumberField(ObjectFactory factory, P paragraph) {
	R run = factory.createR();
	Text txt = new Text();
	txt.setSpace("preserve");
	txt.setValue("NUMPAGES  \\* MERGEFORMAT ");
	run.getContent().add(factory.createRInstrText(txt));
	paragraph.getContent().add(run);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:9,代码来源:Docx4J_例子2.java

示例6: addPageTextField

import org.docx4j.wml.Text; //导入方法依赖的package包/类
private void addPageTextField(ObjectFactory factory, P paragraph,
		String value) {
	R run = factory.createR();
	Text txt = new Text();
	txt.setSpace("preserve");
	txt.setValue(value);
	run.getContent().add(txt);
	paragraph.getContent().add(run);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:10,代码来源:Docx4J_例子2.java

示例7: addPageNumberField

import org.docx4j.wml.Text; //导入方法依赖的package包/类
public void addPageNumberField(ObjectFactory factory, P paragraph) {  
    R run = factory.createR();  
    Text txt = new Text();  
    txt.setSpace("preserve");  
    txt.setValue("PAGE  \\* MERGEFORMAT ");  
    run.getContent().add(factory.createRInstrText(txt));  
    paragraph.getContent().add(run);  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:9,代码来源:Docx4J_简单例子2.java

示例8: addTotalPageNumberField

import org.docx4j.wml.Text; //导入方法依赖的package包/类
public void addTotalPageNumberField(ObjectFactory factory, P paragraph) {  
    R run = factory.createR();  
    Text txt = new Text();  
    txt.setSpace("preserve");  
    txt.setValue("NUMPAGES  \\* MERGEFORMAT ");  
    run.getContent().add(factory.createRInstrText(txt));  
    paragraph.getContent().add(run);  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:9,代码来源:Docx4J_简单例子2.java

示例9: addPageTextField

import org.docx4j.wml.Text; //导入方法依赖的package包/类
private void addPageTextField(ObjectFactory factory, P paragraph,  
        String value) {  
    R run = factory.createR();  
    Text txt = new Text();  
    txt.setSpace("preserve");  
    txt.setValue(value);  
    run.getContent().add(txt);  
    paragraph.getContent().add(run);  
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:10,代码来源:Docx4J_简单例子2.java

示例10: fillRowFromBand

import org.docx4j.wml.Text; //导入方法依赖的package包/类
public void fillRowFromBand(Tr row, final BandData band) {
    new TraversalUtil(row, new AliasVisitor(docxFormatter) {
        @Override
        protected void handle(Text text) {
            String textValue = text.getValue();
            if (docxFormatter.containsJustOneAlias(textValue)) {//todo eude not only one value cells?
                String parameterName = docxFormatter.unwrapParameterName(textValue);
                String fullParameterName = bandName + "." + parameterName;
                Object parameterValue = band.getParameterValue(parameterName);

                if (docxFormatter.tryToApplyInliners(fullParameterName, parameterValue, text)) return;
            }


            //todo eude the following logic is not full and ignores situation when in 1 text we have both table and not table aliases
            boolean hasTableAliases = false;
            Matcher matcher = AbstractFormatter.UNIVERSAL_ALIAS_PATTERN.matcher(textValue);
            while(matcher.find()) {
                AbstractFormatter.BandPathAndParameterName bandAndParameter = docxFormatter.separateBandNameAndParameterName(matcher.group(1));
                if (isBlank(bandAndParameter.getBandPath()) || isBlank(bandAndParameter.getParameterName())) {
                    hasTableAliases = true;
                }
            }

            if (hasTableAliases) {
                String resultString = docxFormatter.insertBandDataToString(band, textValue);
                text.setValue(resultString);
            }
            text.setSpace("preserve");
        }

        @Override
        public boolean shouldTraverse(Object o) {
            //ignore nested tables in control bands
            return controlTable() ? !(o instanceof Tbl) : super.shouldTraverse(o);
        }
    });
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:39,代码来源:TableManager.java

示例11: addComplexField

import org.docx4j.wml.Text; //导入方法依赖的package包/类
private static void addComplexField(P p, String instrText, String instrText2) {

	    org.docx4j.wml.ObjectFactory wmlObjectFactory = Context.getWmlObjectFactory();

	    // Create object for r
	    R r = wmlObjectFactory.createR(); 
	    p.getContent().add( r); 
        // Create object for fldChar (wrapped in JAXBElement) 
        FldChar fldchar = wmlObjectFactory.createFldChar(); 
        JAXBElement<org.docx4j.wml.FldChar> fldcharWrapped = wmlObjectFactory.createRFldChar(fldchar); 
        r.getContent().add( fldcharWrapped); 
            fldchar.setFldCharType(org.docx4j.wml.STFldCharType.BEGIN);
        // Create object for instrText (wrapped in JAXBElement) 
        Text text = wmlObjectFactory.createText(); 
        JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRInstrText(text); 
        r.getContent().add( textWrapped); 
        text.setValue( instrText); 
        text.setSpace( "preserve");    
        
	    R r2 = wmlObjectFactory.createR(); 
	    p.getContent().add( r2); 
	    
        if (!instrText2.equals("")){
    	    
        	r2.getContent().add(wmlObjectFactory.createRTab());
        	
            text = wmlObjectFactory.createText(); 
            JAXBElement<org.docx4j.wml.Text> textWrapped2 = wmlObjectFactory.createRInstrText(text); 
            r2.getContent().add( textWrapped2); 
            text.setValue( instrText2); 
            text.setSpace( "preserve");
        	
        }

        
//        R r = factory.createR();
//        r.setRsidRPr("TOC entry text");
//        R.Tab tab = new R.Tab();
//        r.getRunContent().add(tab);             
//        p.getParagraphContent().add(r);
        
//		org.docx4j.wml.Text idx = wmlObjectFactory.createText();
//		JAXBElement<org.docx4j.wml.Text> textWrapped2 = wmlObjectFactory.createRInstrText(idx); 
//        r.getContent().add( textWrapped2); 
//        idx.setValue( idxText); 
//        idx.setSpace( "preserve"); 

        // Create object for fldChar (wrapped in JAXBElement) 
        fldchar = wmlObjectFactory.createFldChar(); 
        fldcharWrapped = wmlObjectFactory.createRFldChar(fldchar); 
        r2.getContent().add( fldcharWrapped); 
            fldchar.setFldCharType(org.docx4j.wml.STFldCharType.END);

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

示例12: addTOC

import org.docx4j.wml.Text; //导入方法依赖的package包/类
private static void addTOC(MainDocumentPart documentPart) throws Exception {

		org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document)documentPart.getJaxbElement();
		Body body =  wmlDocumentEl.getBody();

        ObjectFactory factory = Context.getWmlObjectFactory();

        /* Create the following:
         *
		    <w:p>
		      <w:r>
		        <w:fldChar w:dirty="true" w:fldCharType="begin"/>
		        <w:instrText xml:space="preserve">TOC \o &quot;1-3&quot; \h \z \ u \h</w:instrText>
		      </w:r>
		      <w:r/>
		      <w:r>
		        <w:fldChar w:fldCharType="end"/>
		      </w:r>
		    </w:p>         */
        P paragraphForTOC = factory.createP();
        R r = factory.createR();

        FldChar fldchar = factory.createFldChar();
        fldchar.setFldCharType(STFldCharType.BEGIN);
        fldchar.setDirty(true);
        r.getContent().add(getWrappedFldChar(fldchar));
        paragraphForTOC.getContent().add(r);

        R r1 = factory.createR();
        Text txt = new Text();
        txt.setSpace("preserve");
        txt.setValue("TOC \\o \"1-3\" \\h \\z \\u \\h");
        r.getContent().add(factory.createRInstrText(txt) );
        paragraphForTOC.getContent().add(r1);

        FldChar fldcharend = factory.createFldChar();
        fldcharend.setFldCharType(STFldCharType.END);
        R r2 = factory.createR();
        r2.getContent().add(getWrappedFldChar(fldcharend));
        paragraphForTOC.getContent().add(r2);

		body.getContent().add(paragraphForTOC);



	}
 
开发者ID:trackplus,项目名称:Genji,代码行数:47,代码来源:AssembleWordprocessingMLPackage.java

示例13: addTableOfContentField

import org.docx4j.wml.Text; //导入方法依赖的package包/类
/**
 * (不知道该怎么翻译, 因此将英文原注释保留)
 *  Adds the field that Word uses to create a table of content to the paragraph.
 *
 *  First we create a run and a text. Then we indicate that all spaces in the
 *  text are to be preserved and set the value to that of the TOC field.
 *  This field definition takes some arguments. The exact definition can be
 *  found in §17.16.5.58 of the Office Open XML standard. In this case we
 *  specify that we want to include all paragrapsh formatted with headings of
 *  levels 1-3 (\0 “1-3”). We also specify that we want all entries to be
 *  hyperlinks (\h), that we want to hide tab leader and page numbers in Web
 *  layout view (\z), and that we want to use the applied paragraph outline
 *  level (\\u).
 *  Finally we take the text and use it to create a JAXB element containing text
 *  and add this to the run, which we then add to the given paragraph.
 *  
 *  将Word用于创建目录表的域添加到段落中.
 *  
 *  首先创建一个可运行块和一个文本. 然后指出文本中所有的空格都被保护并给TOC域设置值. 这个域定义
 *  需要一些参数, 确切定义可以在Office Open XML标准的§17.16.5.58找到, 这种情况我们指定所有
 *  段落使用1-3级别的标题来格式化(\0 "1-3"). 我们同时指定所有的实体作为超链接(\h), 而且在Web
 *  视图中隐藏标签和页码(\z), 我们要使用段落大纲级别应用(\\u).
 *  最后使用文本对象创建了一个JAXB元素包含文本并添加到随后被添加到段落中的可运行块中. 
 *  
 *  @param paragraph
 */
private static void addTableOfContentField(P paragraph) {
    R run = factory.createR();
    Text txt = new Text();
    txt.setSpace("preserve");
    txt.setValue("TOC \\o \"1-3\" \\h \\z \\u");
    run.getContent().add(factory.createRInstrText(txt));
    paragraph.getContent().add(run);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:35,代码来源:AddingTableOfContent.java

示例14: addPageNumberField

import org.docx4j.wml.Text; //导入方法依赖的package包/类
/**
 *  Creating the page number field is nearly the same as creating the field in
 *  the TOC example. The only difference is in the value. We use the PAGE
 *  command, which prints the number of the current page, together with the
 *  MERGEFORMAT switch, which indicates that the current formatting should be
 *  preserved when the field is updated.
 *
 * @param paragraph
 */
private static void addPageNumberField(P paragraph) {
    R run = factory.createR();
    Text txt = new Text();
    txt.setSpace("preserve");
    txt.setValue(" PAGE   \\* MERGEFORMAT ");
    run.getContent().add(factory.createRInstrText(txt));
    paragraph.getContent().add(run);
}
 
开发者ID:vindell,项目名称:docx4j-template,代码行数:18,代码来源:AddingPageNrToFooter.java

示例15: addPageNumberField

import org.docx4j.wml.Text; //导入方法依赖的package包/类
/**
 * Creating the page number field is nearly the same as creating the field
 * in the TOC example. The only difference is in the value. We use the PAGE
 * command, which prints the number of the current page, together with the
 * MERGEFORMAT switch, which indicates that the current formatting should be
 * preserved when the field is updated.
 *
 * @param paragraph
 */
private static void addPageNumberField(P paragraph, ObjectFactory factory) {
	R run = factory.createR();
	Text txt = new Text();
	txt.setSpace("preserve");
	txt.setValue(" PAGE   \\* MERGEFORMAT ");
	run.getContent().add(factory.createRInstrText(txt));
	paragraph.getContent().add(run);
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:18,代码来源:AddPageNrToFooter.java


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