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


Java XWPFRun类代码示例

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


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

示例1: addTableText

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
private static void addTableText(XWPFRun rh, String text) {
	if (text == null) {
		rh.setText("null");
		return;
	}

	String[] split = text.split("\n");
	int size = split.length;
	for (int i = 0; i < size; i++) {
		String d = split[i];
		rh.setText(ValueUtil.leftTrim(d));
		if (i < size - 1) {
			rh.addBreak();
		}
	}
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:17,代码来源:MSWord.java

示例2: testNonEmptyDoc

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
@Test
public void testNonEmptyDoc() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenProvider iterator = new TokenProvider(document);
        XWPFRun run = iterator.next().getRun();
        assertEquals("P1Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P1Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" P1Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("", run.getText(run.getTextPosition()));
        assertTrue(!iterator.hasNext());
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:RunProviderTests.java

示例3: testNonEmptyDoc

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
@Test
public void testNonEmptyDoc() throws InvalidFormatException, IOException {
    try (FileInputStream is = new FileInputStream("resources/document/notEmpty/notEmpty-template.docx");
            OPCPackage oPackage = OPCPackage.open(is);
            XWPFDocument document = new XWPFDocument(oPackage);) {
        TokenIterator iterator = new TokenIterator(document);
        XWPFRun run = iterator.next().getRun();
        assertEquals("P1Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P1Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" P1Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run1 ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run2", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals(" ", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("P2Run3", run.getText(run.getTextPosition()));
        run = iterator.next().getRun();
        assertEquals("", run.getText(run.getTextPosition()));
        assertTrue(!iterator.hasNext());
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:RunIteratorTests.java

示例4: insertTextAtBookMark

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * Insert text into the Word document in the location indicated by this
 * bookmark.
 *
 * @param bookmarkValue An instance of the String class that encapsulates
 * the text to insert into the document.
 * @param where A primitive int whose value indicates where the text ought
 * to be inserted. There are three options controlled by constants; insert
 * the text immediately in front of the bookmark (Bookmark.INSERT_BEFORE),
 * insert text immediately after the bookmark (Bookmark.INSERT_AFTER) and
 * replace any and all text that appears between the bookmark's square
 * brackets (Bookmark.REPLACE).
 */
public void insertTextAtBookMark(String bookmarkValue, int where) {

    //根据标签的类型,进行不同的操作
    if(this._isCell) {
        this.handleBookmarkedCells(bookmarkValue, where);
    } else {

        //普通标签,直接创建一个元素
        XWPFRun run = this._para.createRun();
        run.setText(bookmarkValue);
        switch(where) {
            case BookMark.INSERT_AFTER:
                this.insertAfterBookmark(run);
                break;
            case BookMark.INSERT_BEFORE:
                this.insertBeforeBookmark(run);
                break;
            case BookMark.REPLACE:
                this.replaceBookmark(run);
                break;
        }
    }
}
 
开发者ID:dragon-yuan,项目名称:Ins_fb_pictureSpider_WEB,代码行数:37,代码来源:BookMark.java

示例5: replaceMark

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * 替换含样式的标签
 * @param value
 */
public void replaceMark(String value){
    try{
        Node pNode =  this._ctBookmark.getDomNode();//获取根节点

        Node styleNode = this.getStyleNode(pNode.getNextSibling());//获取样式节点

        //创建内容
        XWPFRun run = this._para.createRun();

        run.setText(value);
        //替换内容
        run.getCTR().getDomNode().insertBefore(styleNode.cloneNode(true), run.getCTR().getDomNode().getFirstChild());
        //删除原内容
        this._para.getCTP().getDomNode().removeChild(pNode.getNextSibling());
    }catch(Exception ex){
        ex.printStackTrace();
        throw new RuntimeException("替换标签出错");
    }

}
 
开发者ID:dragon-yuan,项目名称:Ins_fb_pictureSpider_WEB,代码行数:25,代码来源:BookMark.java

示例6: insertMText

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * Inserts the given {@link MText}.
 * 
 * @param paragraph
 *            the {@link XWPFParagraph} to modify
 * @param run
 *            the {@link XWPFRun}
 * @param text
 *            the {@link MText}
 * @return the last inserted XWPFRun
 */
private XWPFRun insertMText(XWPFParagraph paragraph, XWPFRun run, MText text) {
    final XWPFRun res;

    if (text.getText() != null) {
        final XWPFRun textRun = insertFieldRunReplacement(paragraph, run, text.getText());
        if (text.getStyle() != null) {
            applyMStyle(textRun, text.getStyle());
        }
        res = textRun;
    } else {
        res = run;
    }

    return res;
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:27,代码来源:M2DocEvaluator.java

示例7: eSet

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue) {
    switch (featureID) {
        case TemplatePackage.COMMENT__STYLE_RUN:
            setStyleRun((XWPFRun) newValue);
            return;
        case TemplatePackage.COMMENT__RUNS:
            getRuns().clear();
            getRuns().addAll((Collection<? extends XWPFRun>) newValue);
            return;
        case TemplatePackage.COMMENT__CLOSING_RUNS:
            getClosingRuns().clear();
            getClosingRuns().addAll((Collection<? extends XWPFRun>) newValue);
            return;
        case TemplatePackage.COMMENT__VALIDATION_MESSAGES:
            getValidationMessages().clear();
            getValidationMessages().addAll((Collection<? extends TemplateValidationMessage>) newValue);
            return;
        case TemplatePackage.COMMENT__TEXT:
            setText((String) newValue);
            return;
    }
    super.eSet(featureID, newValue);
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:32,代码来源:CommentImpl.java

示例8: addAnImage

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * 添加图片
 * 
 * @author JueYue
 *  2013-11-20
 * @param obj
 * @param currentRun
 * @throws Exception
 */
private void addAnImage(WordImageEntity obj, XWPFRun currentRun) throws Exception {
    Object[] isAndType = PoiPublicUtil.getIsAndType(obj);
    String picId;
    try {
        picId = currentRun.getDocument().addPictureData((byte[]) isAndType[0],
            (Integer) isAndType[1]);
        ((MyXWPFDocument) currentRun.getDocument()).createPicture(currentRun,
            picId, currentRun.getDocument()
                .getNextPicNameNumber((Integer) isAndType[1]),
            obj.getWidth(), obj.getHeight());

    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }

}
 
开发者ID:rushingpig,项目名称:poix,代码行数:26,代码来源:ParseWord07.java

示例9: markDanglingReferences

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * Marks dangling references.
 * 
 * @param result
 *            the {@link GenerationResult}
 * @return <code>true</code> if any dangling reference was found, <code>false</code> otherwise
 */
public boolean markDanglingReferences(GenerationResult result) {
    final boolean res = !pendingReferences.isEmpty();

    if (res) {
        for (Entry<String, Set<CTText>> entry : pendingReferences.entrySet()) {
            for (CTText ref : entry.getValue()) {
                final XWPFRun refRun = messagePositions.remove(ref);
                result.addMessage(M2DocUtils.insertMessageAfter(refRun, ValidationMessageLevel.ERROR,
                        "dangling reference for bookmark " + entry.getKey()));
            }
        }
    }

    return res;
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:23,代码来源:BookmarkManager.java

示例10: changeValues

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * 根据条件改变值
 * 
 * @param map
 * @author JueYue
 *  2013-11-16
 */
private void changeValues(XWPFParagraph paragraph, XWPFRun currentRun, String currentText,
                          List<Integer> runIndex, Map<String, Object> map) throws Exception {
    Object obj = PoiPublicUtil.getRealValue(currentText, map);
    if (obj instanceof WordImageEntity) {// 如果是图片就设置为图片
        currentRun.setText("", 0);
        addAnImage((WordImageEntity) obj, currentRun);
    } else {
        currentText = obj.toString();
        PoiPublicUtil.setWordText(currentRun, currentText);
    }
    for (int k = 0; k < runIndex.size(); k++) {
        paragraph.getRuns().get(runIndex.get(k)).setText("", 0);
    }
    runIndex.clear();
}
 
开发者ID:rushingpig,项目名称:poix,代码行数:23,代码来源:ParseWord07.java

示例11: eSet

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * 
 * @generated
 */
@SuppressWarnings("unchecked")
@Override
public void eSet(int featureID, Object newValue) {
    switch (featureID) {
        case TemplatePackage.CONTENT_CONTROL__STYLE_RUN:
            setStyleRun((XWPFRun) newValue);
            return;
        case TemplatePackage.CONTENT_CONTROL__RUNS:
            getRuns().clear();
            getRuns().addAll((Collection<? extends XWPFRun>) newValue);
            return;
        case TemplatePackage.CONTENT_CONTROL__CLOSING_RUNS:
            getClosingRuns().clear();
            getClosingRuns().addAll((Collection<? extends XWPFRun>) newValue);
            return;
        case TemplatePackage.CONTENT_CONTROL__VALIDATION_MESSAGES:
            getValidationMessages().clear();
            getValidationMessages().addAll((Collection<? extends TemplateValidationMessage>) newValue);
            return;
        case TemplatePackage.CONTENT_CONTROL__CONTROL:
            setControl((XWPFSDT) newValue);
            return;
    }
    super.eSet(featureID, newValue);
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:32,代码来源:ContentControlImpl.java

示例12: checkUserDocIdTypes

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * Checks if the given types are assignable to no a {@link ICollectionType}.
 * 
 * @param userDoc
 *            the {@link UserDoc}
 * @param run
 *            the {@link XWPFRun}
 * @param validationResult
 *            validation Result for {@link UserDoc#getId() id}
 * @return the {@link ValidationMessageLevel}
 */
private ValidationMessageLevel checkUserDocIdTypes(UserDoc userDoc, XWPFRun run,
        IValidationResult validationResult) {
    ValidationMessageLevel res = ValidationMessageLevel.OK;

    final Set<IType> types = validationResult.getPossibleTypes(userDoc.getId().getAst());
    for (IType type : types) {
        if (type instanceof ICollectionType) {
            userDoc.getValidationMessages().add(new TemplateValidationMessage(ValidationMessageLevel.ERROR,
                    String.format("The id type must not be a collection (%s).", type), run));
            res = ValidationMessageLevel.ERROR;
            break;
        }
    }

    return res;
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:28,代码来源:M2DocValidator.java

示例13: lookAheadTag

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * Extract tag string (word field) from runs list.
 * The tag must begin at the first run, return empty sting if not.
 * 
 * @param runs
 *            list of run where find tag
 * @param index
 *            run index in iterator
 * @return tag string
 * @deprecated @see {@link #lookAheadTag(TokenProvider)}
 */
@Deprecated
public String lookAheadTag(List<XWPFRun> runs, int index) {
    int i = index;
    // first run must begin a field.
    XWPFRun run = runs.get(i);
    if (run != null) {
        if (isFieldBegin(run)) {
            StringBuilder builder = new StringBuilder();
            i++;
            run = runs.get(i);
            // run is null when EOF is reached or a table is encountered.
            while (run != null && !isFieldEnd(run)) {
                builder.append(readUpInstrText(run));
                run = runs.get(++i);
            }
            return builder.toString().trim();
        }
    }
    return "";
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:32,代码来源:FieldUtils.java

示例14: addAnImage

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * 添加图片
 * 
 * @Author JueYue
 * @date 2013-11-20
 * @param obj
 * @param currentRun
 * @throws Exception
 */
private void addAnImage(WordImageEntity obj, XWPFRun currentRun) throws Exception {
    Object[] isAndType = PoiPublicUtil.getIsAndType(obj);
    String picId;
    try {
        picId = currentRun.getParagraph().getDocument()
            .addPictureData((byte[]) isAndType[0], (Integer) isAndType[1]);
        ((MyXWPFDocument) currentRun.getParagraph().getDocument()).createPicture(currentRun,
            picId,
            currentRun.getParagraph().getDocument()
                .getNextPicNameNumber((Integer) isAndType[1]), obj.getWidth(), obj.getHeight());

    } catch (Exception e) {
        LOGGER.error(e.getMessage(),e);
    }

}
 
开发者ID:xiaolanglang,项目名称:easypoi,代码行数:26,代码来源:ParseWord07.java

示例15: validateRepetitionQueryType

import org.apache.poi.xwpf.usermodel.XWPFRun; //导入依赖的package包/类
/**
 * Validates the {@link Repetition#getQuery() query}.
 * 
 * @param repetition
 *            the {@link Repetition}
 * @param run
 *            the {@link XWPFRun}
 * @param types
 *            the {@link Set} of {@link IType} for the {@link Repetition#getQuery() query}
 * @return the {@link ValidationMessageLevel}
 */
private ValidationMessageLevel validateRepetitionQueryType(Repetition repetition, final XWPFRun run,
        final Set<IType> types) {
    ValidationMessageLevel res = ValidationMessageLevel.OK;

    for (IType type : types) {
        if (!(type instanceof ICollectionType)) {
            res = ValidationMessageLevel.ERROR;
            repetition.getValidationMessages().add(new TemplateValidationMessage(res,
                    String.format("The iteration variable types must be collections (%s).", types), run));
            break;
        }
    }

    return res;
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:27,代码来源:M2DocValidator.java


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