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


Java XWPFParagraph类代码示例

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


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

示例1: createDOCXDocument

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
void createDOCXDocument(String pdfText, String outputFileName){
    XWPFDocument pdfTextDocument = new XWPFDocument();
    XWPFParagraph pdfTextParagraph = pdfTextDocument.createParagraph();;
    XWPFRun pdfTextParagraphCharacterRun = pdfTextParagraph.createRun();

    StringTokenizer pdfTextReader = new StringTokenizer(pdfText);
    String pdfTextLine = null;
    while(pdfTextReader.hasMoreTokens()){
       pdfTextLine = pdfTextReader.nextToken("\n");
       pdfTextParagraphCharacterRun.setText(pdfTextLine);
       pdfTextParagraphCharacterRun.addCarriageReturn();
    }
    try{
        pdfTextDocument.write(new FileOutputStream(new File(outputFileName)));
    }
    catch(Exception e){
        System.err.println("An exception occured in creating the DOCX document."+ e.getMessage());
    }
    

    
}
 
开发者ID:michaelgingerich,项目名称:PDFToDOCX,代码行数:23,代码来源:DOCXCreator.java

示例2: main

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
	// Create a new document from scratch
       XWPFDocument doc = new XWPFDocument();
       
       // create paragraph
       XWPFParagraph para = doc.createParagraph();
       
       // create a run to contain the content
       XWPFRun rh = para.createRun();
       
       // Format as desired
   	rh.setFontSize(15);
   	rh.setFontFamily("Verdana");
       rh.setText("This is the formatted Text");
       rh.setColor("fff000");
       para.setAlignment(ParagraphAlignment.RIGHT);
       
       // write the file
       FileOutputStream out = new FileOutputStream("data/Apache_FormattedText.docx");
       doc.write(out);
       out.close();
       
       System.out.println("Process Completed Successfully");
}
 
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:26,代码来源:ApacheFormattedText.java

示例3: readDocx

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的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

示例4: caseDocumentTemplate

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
@Override
public XWPFParagraph caseDocumentTemplate(DocumentTemplate documentTemplate) {
    cleanBody(generatedDocument);
    doSwitch(documentTemplate.getBody());

    final XWPFDocument document = (XWPFDocument) generatedDocument;
    final Iterator<XWPFFooter> footers = document.getFooterList().iterator();
    for (final Template footer : documentTemplate.getFooters()) {
        final XWPFFooter f = footers.next();
        cleanBody(f);
        generatedDocument = f;
        doSwitch(footer);
    }
    final Iterator<XWPFHeader> headers = document.getHeaderList().iterator();
    for (final Template header : documentTemplate.getHeaders()) {
        final XWPFHeader h = headers.next();
        cleanBody(h);
        generatedDocument = h;
        doSwitch(header);
    }

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

示例5: readLinesDocStream

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的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

示例6: render

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
@Override
public void render(ElementTemplate eleTemplate, Object data,
		XWPFTemplate template) {
	NiceXWPFDocument doc = template.getXWPFDocument();
	RunTemplate runTemplate = (RunTemplate) eleTemplate;
	XWPFRun run = runTemplate.getRun();
	try {
		XmlCursor newCursor = ((XWPFParagraph)run.getParent()).getCTP().newCursor();
		newCursor.toParent();
		//if (newCursor.getObject() instanceof CTTc) 
		newCursor.toParent();
		newCursor.toParent();
		XmlObject object = newCursor.getObject();
		XWPFTable table = doc.getTable((CTTbl) object);
		render(table, data);
	} catch (Exception e) {
		logger.error("dynamic table error:" + e.getMessage(), e);
	}
}
 
开发者ID:Sayi,项目名称:poi-tl,代码行数:20,代码来源:DynamicTableRenderPolicy.java

示例7: main

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
public static void main(String[] args) throws Exception
{
	XWPFDocument doc = new XWPFDocument();
       XWPFParagraph p = doc.createParagraph();
       
       String imgFile = "aspose.jpg";
       XWPFRun r = p.createRun();
       
       int format = XWPFDocument.PICTURE_TYPE_JPEG;
       r.setText(imgFile);
       r.addBreak();
       r.addPicture(new FileInputStream(imgFile), format, imgFile, Units.toEMU(200), Units.toEMU(200)); // 200x200 pixels
       r.addBreak(BreakType.PAGE);

    FileOutputStream out = new FileOutputStream("data/Apache_ImagesInDoc.docx");
    doc.write(out);
    out.close();
    
       System.out.println("Process Completed Successfully");
}
 
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:21,代码来源:ApacheInsertImage.java

示例8: addText

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
/**
 * 텍스트 입력
 *
 * @param p
 * @param text
 * @param fontSize
 * @param bold
 * @param italic
 * @param strike
 * @return
 */
public XWPFParagraph addText(XWPFParagraph p, String text, int fontSize, boolean bold, boolean italic, boolean strike) {

	KrXWPFRun r1 = new KrXWPFRun(p.createRun());

	r1.setText(text);
	r1.setBold(bold);
	r1.setItalic(italic);
	r1.setFontFamily(fontName);
	// r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
	r1.setStrike(strike);
	r1.setFontSize(fontSize);
	p.setAlignment(ParagraphAlignment.LEFT);
	// p.setSpacingLineRule(LineSpacingRule.EXACT);

	return p;
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:28,代码来源:MSWord.java

示例9: addBlockText

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
/**
 * 텍스트 입력
 *
 * @param text
 */
public void addBlockText(String text, ParagraphAlignment alignment) {
	XWPFParagraph p1 = doc.createParagraph();
	p1.setAlignment(alignment);
	p1.setBorderBottom(Borders.DOUBLE);
	p1.setBorderTop(Borders.DOUBLE);

	p1.setBorderRight(Borders.DOUBLE);
	p1.setBorderLeft(Borders.DOUBLE);
	p1.setBorderBetween(Borders.SINGLE);

	p1.setVerticalAlignment(TextAlignment.TOP);

	// p1.setSpacingBefore(5);
	// p1.setSpacingAfter(5);
	// KrXWPFRun r1 = new KrXWPFRun(p1.createRun());
	// r1.setFontSize(13);
	// r1.setText(text);
	// r1.setFontFamily(fontName);

	addText(p1, text);
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:27,代码来源:MSWord.java

示例10: linkRuns

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
/**
 * Links the given {@link IConstruct} with new {@link XWPFRun} created in the given {@link XWPFParagraph}.
 * 
 * @param paragraph
 *            the {@link XWPFParagraph}
 * @param construct
 *            the {@link IConstruct}
 */
private static void linkRuns(XWPFParagraph paragraph, IConstruct construct) {
    construct.setStyleRun(paragraph.createRun());

    construct.getRuns().add(paragraph.createRun());
    construct.getRuns().add(paragraph.createRun());
    construct.getRuns().add(paragraph.createRun());

    for (EObject child : construct.eContents()) {
        if (child instanceof IConstruct) {
            linkRuns(paragraph, (IConstruct) child);
        }
    }

    construct.getClosingRuns().add(paragraph.createRun());
    construct.getClosingRuns().add(paragraph.createRun());
    construct.getClosingRuns().add(paragraph.createRun());
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:26,代码来源:M2DocTestUtils.java

示例11: insertRun

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
/**
 * Inserts a run in the generated document. The new run is a copy from the specified run.
 * 
 * @param paragraph
 *            the {@link XWPFParagraph} to modify
 * @param srcRun
 *            the run to copy
 * @return the inserted {@link XWPFRun}
 */
private XWPFRun insertRun(XWPFParagraph paragraph, XWPFRun srcRun) {

    final XWPFParagraph newParagraph;
    if (srcRun.getParent() != currentTemplateParagraph || forceNewParagraph) {
        newParagraph = createNewParagraph(generatedDocument, (XWPFParagraph) srcRun.getParent());
        forceNewParagraph = false;
    } else {
        newParagraph = paragraph;
    }

    XWPFRun newRun = null;
    if (srcRun instanceof XWPFHyperlinkRun) {
        // Hyperlinks meta information is saved in the paragraph and not in the run. So we have to update the paragrapah with a copy of
        // the hyperlink to insert.
        CTHyperlink newHyperlink = newParagraph.getCTP().addNewHyperlink();
        newHyperlink.set(((XWPFHyperlinkRun) srcRun).getCTHyperlink());

        newRun = new XWPFHyperlinkRun(newHyperlink, srcRun.getCTR(), srcRun.getParent());
        newParagraph.addRun(newRun);
    } else {
        newRun = newParagraph.createRun();
        newRun.getCTR().set(srcRun.getCTR());
    }
    return newRun;
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:35,代码来源:M2DocEvaluator.java

示例12: caseQuery

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
@Override
public XWPFParagraph caseQuery(Query query) {
    XWPFParagraph currentParagraph = currentGeneratedParagraph;
    if (hasError(query)) {
        currentParagraph = insertQuerySyntaxMessages(currentParagraph, query, INVALID_QUERY_STATEMENT);
    } else {
        final EvaluationResult queryResult = evaluator.eval(query.getQuery(), variablesStack.peek());
        if (queryResult.getDiagnostic().getSeverity() != Diagnostic.OK) {
            currentParagraph = insertQueryEvaluationMessages(currentParagraph, query, queryResult.getDiagnostic());
        } else {
            final Object value = queryResult.getResult();
            final XWPFRun styleRun = query.getStyleRun();
            currentParagraph = insertObject(currentParagraph, value, styleRun);
        }
    }

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

示例13: insertMText

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的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

示例14: caseLet

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
@Override
public XWPFParagraph caseLet(Let let) {
    XWPFParagraph currentParagraph = currentGeneratedParagraph;
    if (hasError(let)) {
        currentParagraph = insertQuerySyntaxMessages(currentParagraph, let, INVALID_LET_STATEMENT);
    } else {
        final EvaluationResult queryResult = evaluator.eval(let.getValue(), variablesStack.peek());
        if (queryResult.getDiagnostic().getSeverity() != Diagnostic.OK) {
            currentParagraph = insertQueryEvaluationMessages(currentParagraph, let, queryResult.getDiagnostic());
        } else {
            final Map<String, Object> newVariables = new HashMap<>(variablesStack.peek());
            variablesStack.push(newVariables);
            try {
                newVariables.put(let.getName(), queryResult.getResult());
                currentParagraph = doSwitch(let.getBody());
            } finally {
                variablesStack.pop();
            }
        }
    }

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

示例15: caseUserDoc

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入依赖的package包/类
@Override
public XWPFParagraph caseUserDoc(UserDoc userDoc) {
    XWPFParagraph currentParagraph = currentGeneratedParagraph;
    if (hasError(userDoc)) {
        currentParagraph = insertQuerySyntaxMessages(currentParagraph, userDoc, INVALID_USERDOC_STATEMENT);
    } else {
        final EvaluationResult queryResult = evaluator.eval(userDoc.getId(), variablesStack.peek());
        if (queryResult.getDiagnostic().getSeverity() != Diagnostic.OK) {
            currentParagraph = insertQueryEvaluationMessages(currentParagraph, userDoc,
                    queryResult.getDiagnostic());
        } else {
            if (queryResult.getResult() == null) {
                insertMessage(currentParagraph, ValidationMessageLevel.ERROR, "User doc id can't be null.");
            } else {
                final String id = queryResult.getResult().toString();
                currentParagraph = insertUserContent(currentParagraph, userDoc, id);
            }
        }
    }

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


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