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


Java XWPFParagraph.createRun方法代码示例

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


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

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

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

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

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

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

示例6: insertReference

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
/**
 * Inserts a pending reference to the given name in the given {@link XWPFParagraph}.
 * 
 * @param paragraph
 *            the {@link XWPFParagraph}
 * @param name
 *            the bookmark name
 * @param text
 *            the text
 */
public void insertReference(XWPFParagraph paragraph, String name, String text) {
    final CTBookmark bookmark = bookmarks.get(name);
    if (bookmark != null) {
        insertReference(paragraph, bookmark, text);
    } else {
        final XWPFRun messageRun = paragraph.createRun();
        final CTText ref = insertPendingReference(paragraph, name, text);
        messagePositions.put(ref, messageRun);
        Set<CTText> pendingRefs = pendingReferences.get(name);
        if (pendingRefs == null) {
            pendingRefs = new LinkedHashSet<CTText>();
            pendingReferences.put(name, pendingRefs);
        }
        pendingRefs.add(ref);
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:27,代码来源:BookmarkManager.java

示例7: createSimpleTable

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
public static void createSimpleTable() throws Exception {
    @SuppressWarnings("resource")
XWPFDocument doc = new XWPFDocument();

    XWPFTable table = doc.createTable(3, 3);

    table.getRow(1).getCell(1).setText("EXAMPLE OF TABLE");

    // table cells have a list of paragraphs; there is an initial
    // paragraph created when the cell is created. If you create a
    // paragraph in the document to put in the cell, it will also
    // appear in the document following the table, which is probably
    // not the desired result.
    XWPFParagraph p1 = table.getRow(0).getCell(0).getParagraphs().get(0);

    XWPFRun r1 = p1.createRun();
    r1.setBold(true);
    r1.setText("The quick brown fox");
    r1.setItalic(true);
    r1.setFontFamily("Courier");
    r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH);
    r1.setTextPosition(100);

    table.getRow(2).getCell(2).setText("only text");

    FileOutputStream out = new FileOutputStream("simpleTable.docx");
    doc.write(out);
    out.close();
}
 
开发者ID:Sayi,项目名称:poi-tl,代码行数:30,代码来源:SimpleTable.java

示例8: createCellText

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
public void createCellText(XWPFTableCell cell) {
	XWPFParagraph paragraph;
	// If no header is set, use the cell's default paragraph.
	if (cell.getParagraphs().get(0).getRuns().size() == 0)
		paragraph = cell.getParagraphs().get(0);
	else
		paragraph = cell.addParagraph();

	XWPFRun run = paragraph.createRun();
	run.setBold(isBold);
	run.setText(text);
	run.setFontFamily(fontFamily);
	run.setFontSize(fontSize);
	paragraph.setAlignment(alignment);
	paragraph.setSpacingAfter(10);
	paragraph.setSpacingBefore(topMargin);
	paragraph.setIndentationLeft(leftMargin);
	paragraph.setIndentationRight(50);
	paragraph.setIndentationHanging(hangingIndent);
	if (bottomBorder)
		paragraph.setBorderBottom(Borders.SINGLE);
}
 
开发者ID:FraunhoferCESE,项目名称:HazardTrackingSystem,代码行数:23,代码来源:ParagraphBuilder.java

示例9: createCellHeader

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
public void createCellHeader(XWPFTableCell cell) {
	XWPFParagraph p;
	if (cell.getParagraphs().get(0).getRuns().size() == 0)
		p = cell.getParagraphs().get(0);
	else
		p = cell.addParagraph();

	p.setAlignment(alignment);
	p.setSpacingBefore(beforeSpacing);
	p.setIndentationLeft(20);
	p.setSpacingAfter(100);
	XWPFRun rHeading = p.createRun();
	rHeading.setText(text.toUpperCase());
	rHeading.setFontFamily("Arial");
	rHeading.setFontSize(6);
	rHeading.setBold(isBold);
}
 
开发者ID:FraunhoferCESE,项目名称:HazardTrackingSystem,代码行数:18,代码来源:CellHeaderBuilder.java

示例10: main

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
	String dataPath = "src/featurescomparison/workingwithdocuments/savedocument/data/";

	XWPFDocument document = new XWPFDocument();
	XWPFParagraph tmpParagraph = document.createParagraph();
	
	XWPFRun tmpRun = tmpParagraph.createRun();
	tmpRun.setText("Apache Sample Content for Word file.");
	
	FileOutputStream fos = new FileOutputStream(dataPath + "Apache_SaveDoc_Out.doc");
	document.write(fos);
	fos.close();
	
       System.out.println("Process Completed Successfully");
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Words_for_Apache_POI,代码行数:17,代码来源:ApacheSaveDocument.java

示例11: main

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
	String dataPath = "src/featurescomparison/workingwithdocuments/formattext/data/";
	
	// 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(dataPath + "Apache_FormattedText_Out.docx");
       doc.write(out);
       out.close();
       
       System.out.println("Process Completed Successfully");
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Words_for_Apache_POI,代码行数:28,代码来源:ApacheFormattedText.java

示例12: main

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
	String dataPath = "src/featurescomparison/workingwithimages/insertimage/data/";

	XWPFDocument doc = new XWPFDocument();
       XWPFParagraph p = doc.createParagraph();
       
       String imgFile = dataPath + "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(dataPath + "Apache_ImagesInDoc_Out.docx");
    doc.write(out);
    out.close();
    
       System.out.println("Process Completed Successfully");
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Words_for_Apache_POI,代码行数:23,代码来源:ApacheInsertImage.java

示例13: addTableLevelSection

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
private static void addTableLevelSection(CustomXWPFDocument document, ETL etl) throws InvalidFormatException, FileNotFoundException {
	XWPFParagraph tmpParagraph = document.createParagraph();
	XWPFRun tmpRun = tmpParagraph.createRun();
	
	MappingPanel mappingPanel = new MappingPanel(etl.getTableToTableMapping());
	mappingPanel.setShowOnlyConnectedItems(true);
	int height = mappingPanel.getMinimumSize().height;
	mappingPanel.setSize(800, height);
	
	tmpRun.setText(mappingPanel.getSourceDbName() + " Data Mapping Approach to " + mappingPanel.getTargetDbName());
	tmpRun.setFontSize(18);
	
	BufferedImage im = new BufferedImage(800, height, BufferedImage.TYPE_INT_ARGB);
	im.getGraphics().setColor(Color.WHITE);
	im.getGraphics().fillRect(0, 0, im.getWidth(), im.getHeight());
	mappingPanel.paint(im.getGraphics());
	document.addPicture(im, 600, height * 6 / 8);
}
 
开发者ID:OHDSI,项目名称:WhiteRabbit,代码行数:19,代码来源:ETLDocumentGenerator.java

示例14: modifyWord

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

示例15: setCellContent

import org.apache.poi.xwpf.usermodel.XWPFParagraph; //导入方法依赖的package包/类
/**
 * Create a new run in the cell's paragraph and set this run's text, and apply the given style to the cell and its paragraph.
 * 
 * @param cell
 *            Cell to fill in
 * @param mCell
 *            the cell to read data from
 */
private void setCellContent(XWPFTableCell cell, MCell mCell) {
    XWPFParagraph cellParagraph = cell.getParagraphs().get(0);
    XWPFRun cellRun = cellParagraph.createRun();
    if (mCell != null) {
        final MElement contents = mCell.getContents();
        if (contents != null) {
            final IBody savedGeneratedDocument = generatedDocument;
            final XWPFParagraph savedGeneratedParagraph = currentGeneratedParagraph;
            final XWPFParagraph savedTemplateParagraph = currentTemplateParagraph;
            generatedDocument = cell;
            currentGeneratedParagraph = cellParagraph;
            currentTemplateParagraph = cellParagraph;
            try {
                insertObject(cellParagraph, contents, cellRun);
            } finally {
                generatedDocument = savedGeneratedDocument;
                currentGeneratedParagraph = savedGeneratedParagraph;
                currentTemplateParagraph = savedTemplateParagraph;
            }
            cellParagraph.removeRun(cellParagraph.getRuns().indexOf(cellRun));
        }
        final Color backGroundColor = mCell.getBackgroundColor();
        if (backGroundColor != null) {
            cell.setColor(hexColor(backGroundColor));
        }
    }
}
 
开发者ID:ObeoNetwork,项目名称:M2Doc,代码行数:36,代码来源:M2DocEvaluator.java


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