當前位置: 首頁>>代碼示例>>Java>>正文


Java XWPFDocument.getParagraphs方法代碼示例

本文整理匯總了Java中org.apache.poi.xwpf.usermodel.XWPFDocument.getParagraphs方法的典型用法代碼示例。如果您正苦於以下問題:Java XWPFDocument.getParagraphs方法的具體用法?Java XWPFDocument.getParagraphs怎麽用?Java XWPFDocument.getParagraphs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.poi.xwpf.usermodel.XWPFDocument的用法示例。


在下文中一共展示了XWPFDocument.getParagraphs方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readDocx

import org.apache.poi.xwpf.usermodel.XWPFDocument; //導入方法依賴的package包/類
private String readDocx(String path) {
    String content = "";
    try {
        File file = new File(path);
        FileInputStream fis = new FileInputStream(file.getAbsolutePath());

        XWPFDocument document = new XWPFDocument(fis);

        List<XWPFParagraph> paragraphs = document.getParagraphs();

        for (XWPFParagraph para : paragraphs) {
            content += para.getText();
        }
        fis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return content;
}
 
開發者ID:jatanrathod,項目名稱:Idea-Plagiarism,代碼行數:20,代碼來源:checkPlagiarism.java

示例2: readLinesDocStream

import org.apache.poi.xwpf.usermodel.XWPFDocument; //導入方法依賴的package包/類
public static List<String> readLinesDocStream(InputStream is, boolean trim) throws IOException {
    XWPFDocument document=new XWPFDocument(is);
    List<XWPFParagraph> paragraphs = document.getParagraphs();
    List<String> ret = new ArrayList<String>();
    for(XWPFParagraph paragraph : paragraphs){
        String[] lines = paragraph.getParagraphText().split("\n");
        for (String line : lines) {
            if (trim) {
                line = line.replaceAll("^[\uFEFF-\uFFFF]+", ""); // trim and remove unicode
                line = line.replaceAll("\\[[a-z]\\]", ""); // remove comments from google docs
                line = line.trim();
            }
            if (!line.isEmpty()) {
                ret.add(line);
            }
        }
    }
    return ret;
}
 
開發者ID:oncokb,項目名稱:oncokb,代碼行數:20,代碼來源:FileUtils.java

示例3: processParagraphRequest

import org.apache.poi.xwpf.usermodel.XWPFDocument; //導入方法依賴的package包/類
/**
 * Processing of text requests.
 * 
 * @param docx word document
 * @param paraRef reference to paragraphs
 * @return list of values as {@code LinkedList<Value>}
 */
private LinkedList<Value> processParagraphRequest(XWPFDocument docx, String paraRef) {
    LinkedList<Value> valList = new LinkedList<Value>();

    List<XWPFParagraph> paraList = docx.getParagraphs();
    setStartEndParagraph(paraRef, "*");
    // -1 => all paragraphs requested
    if (this.startPara == -1 || this.endPara == -1) {
        this.startPara = 0;
        this.endPara = paraList.size() - 1;
    }

    if (this.startPara < paraList.size()) {
        if (!(this.endPara < paraList.size())) {
            this.endPara = paraList.size() - 1;
        }

        for (Integer pPos = this.startPara; pPos <= this.endPara; pPos++) {
            Integer subURI = pPos + 1;
            valList.add(getParagraph(paraList.get(pPos), subURI.toString()));
        }
    }

    return valList;
}
 
開發者ID:chsatgithub,項目名稱:PANDA-DEEPLINKING,代碼行數:32,代碼來源:DataWordResource.java

示例4: modifyWord

import org.apache.poi.xwpf.usermodel.XWPFDocument; //導入方法依賴的package包/類
public void  modifyWord(InputStream docx, Map<String, String> textMap, OutputStream out) {
	try {
		XWPFDocument doc = new XWPFDocument(OPCPackage.open(docx));

		// tentative avec les noms {{}}
		for (XWPFParagraph p : doc.getParagraphs()) {

			for(CTBookmark bookmark: p.getCTP().getBookmarkStartList()) {
				log.trace(bookmark.getName());
				for(String key : textMap.keySet()) {
					String cleanKey = StringUtils.stripAccents(key);
					cleanKey = cleanKey.replaceAll(" ", "_");
					cleanKey = cleanKey.replaceAll( "\\W", "");
					if(bookmark.getName().equalsIgnoreCase(cleanKey)) {
						Node nextNode = bookmark.getDomNode().getNextSibling();
		                while(nextNode != null &&  nextNode.getNodeName() != null &&  !(nextNode.getNodeName().contains("bookmarkEnd"))) { 
		                    p.getCTP().getDomNode().removeChild(nextNode); 
		                    nextNode = bookmark.getDomNode().getNextSibling(); 
		                } 
						XWPFRun run = p.createRun();
						run.setText(textMap.get(key));
						p.getCTP().getDomNode().insertBefore(run.getCTR().getDomNode(), nextNode); 
					}
				}
			}
		}

		doc.write(out);
	} catch(Exception e) {
		log.error("Pb durant la modification du document word", e);
	}

}
 
開發者ID:EsupPortail,項目名稱:esup-dematec,代碼行數:34,代碼來源:WordParser.java

示例5: getRunContaining

import org.apache.poi.xwpf.usermodel.XWPFDocument; //導入方法依賴的package包/類
/**
 * Gets the {@link XWPFRun} containing the given text in the given {@link XWPFDocument}.
 * 
 * @param document
 *            the {@link XWPFDocument}
 * @param text
 *            the {@link XWPFRun}
 * @return the {@link XWPFRun} containing the given text in the given {@link XWPFDocument} if any, <code>null</code> otherwise
 */
public static XWPFRun getRunContaining(XWPFDocument document, String text) {
    XWPFRun res = null;

    for (XWPFParagraph paragraph : document.getParagraphs()) {
        for (XWPFRun run : paragraph.getRuns()) {
            if (run.text().contains(text)) {
                res = run;
                break;
            }
        }
    }

    return res;
}
 
開發者ID:ObeoNetwork,項目名稱:M2Doc,代碼行數:24,代碼來源:M2DocTestUtils.java


注:本文中的org.apache.poi.xwpf.usermodel.XWPFDocument.getParagraphs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。