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


Java XWPFDocument.write方法代码示例

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


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

示例1: createDOCXDocument

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

import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
	XWPFDocument document = new XWPFDocument();
	
	// New 2x2 table
	XWPFTable tableOne = document.createTable();
	XWPFTableRow tableOneRowOne = tableOne.getRow(0);
	tableOneRowOne.getCell(0).setText("Hello");
	tableOneRowOne.addNewTableCell().setText("World");
	
	XWPFTableRow tableOneRowTwo = tableOne.createRow();
	tableOneRowTwo.getCell(0).setText("This is");
	tableOneRowTwo.getCell(1).setText("a table");
	
	// Add a break between the tables
	document.createParagraph().createRun().addBreak();
	
	// New 3x3 table
	XWPFTable tableTwo = document.createTable();
	XWPFTableRow tableTwoRowOne = tableTwo.getRow(0);
	tableTwoRowOne.getCell(0).setText("col one, row one");
	tableTwoRowOne.addNewTableCell().setText("col two, row one");
	tableTwoRowOne.addNewTableCell().setText("col three, row one");
	
	XWPFTableRow tableTwoRowTwo = tableTwo.createRow();
	tableTwoRowTwo.getCell(0).setText("col one, row two");
	tableTwoRowTwo.getCell(1).setText("col two, row two");
	tableTwoRowTwo.getCell(2).setText("col three, row two");
	
	XWPFTableRow tableTwoRowThree = tableTwo.createRow();
	tableTwoRowThree.getCell(0).setText("col one, row three");
	tableTwoRowThree.getCell(1).setText("col two, row three");
	tableTwoRowThree.getCell(2).setText("col three, row three");
	
	FileOutputStream outStream = new FileOutputStream("data/Apache_CreateTable.doc");
	document.write(outStream);
	outStream.close();
}
 
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:39,代码来源:ApacheCreateTable.java

示例4: renderMergedOutputModel

import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
                                       HttpServletResponse response) throws Exception {
    String codedFileName = "临时文件.docx";
    if (model.containsKey(TemplateWordConstants.FILE_NAME)) {
        codedFileName = (String) model.get(TemplateWordConstants.FILE_NAME) + ".docx";
    }
    if (isIE(request)) {
        codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8");
    } else {
        codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1");
    }
    response.setHeader("content-disposition", "attachment;filename=" + codedFileName);
    XWPFDocument document = WordExportUtil.exportWord07(
        (String) model.get(TemplateWordConstants.URL),
        (Map<String, Object>) model.get(TemplateWordConstants.MAP_DATA));
    ServletOutputStream out = response.getOutputStream();
    document.write(out);
    out.flush();
}
 
开发者ID:rushingpig,项目名称:poix,代码行数:21,代码来源:JeecgTemplateWordView.java

示例5: writeDocxFile

import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public void writeDocxFile(File file,StyledText text, boolean onlytext){
	try {
		FileOutputStream fos = new FileOutputStream(file);
		XWPFDocument document = new XWPFDocument();
		black.ba.saveStylesToDocxFile(text,document);
		try {
			document.write(fos);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	} catch (FileNotFoundException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
}
 
开发者ID:piiiiq,项目名称:Black,代码行数:17,代码来源:ioThread.java

示例6: main

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

示例7: disseminateList

import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
@Override
public void disseminateList(Context context, List<Item> items, OutputStream out) throws CrosswalkException, IOException, SQLException, AuthorizeException {
    XWPFDocument document = new XWPFDocument();

    for (Item item : items) {
        if (canDisseminate(context, item)) {
            String citationText = getFirstNonBlankValue(item, "dc", "identifier", "citation");
            String abstractText = getFirstNonBlankValue(item, "dc", "description", "abstract");
            String handleUrl = HandleManager.getCanonicalForm(item.getHandle());

            processSingleItem(document, citationText, abstractText, handleUrl);
        } else {
            log.warn("Cannot disseminate " + item.getTypeText() + " id=" + item.getID() + ", skipping");
        }
    }

    document.write(out);
    out.flush();
}
 
开发者ID:UoW-IRRs,项目名称:API-Extras,代码行数:20,代码来源:WordCitationExportCrosswalk.java

示例8: createSimpleTable

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

示例9: main

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

示例10: main

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

示例11: main

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

示例12: main

import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
	String dataPath = "src/featurescomparison/workingwithtables/createtables/data/";
	
	XWPFDocument document = new XWPFDocument();
	
	// New 2x2 table
	XWPFTable tableOne = document.createTable();
	XWPFTableRow tableOneRowOne = tableOne.getRow(0);
	tableOneRowOne.getCell(0).setText("Hello");
	tableOneRowOne.addNewTableCell().setText("World");
	
	XWPFTableRow tableOneRowTwo = tableOne.createRow();
	tableOneRowTwo.getCell(0).setText("This is");
	tableOneRowTwo.getCell(1).setText("a table");
	
	// Add a break between the tables
	document.createParagraph().createRun().addBreak();
	
	// New 3x3 table
	XWPFTable tableTwo = document.createTable();
	XWPFTableRow tableTwoRowOne = tableTwo.getRow(0);
	tableTwoRowOne.getCell(0).setText("col one, row one");
	tableTwoRowOne.addNewTableCell().setText("col two, row one");
	tableTwoRowOne.addNewTableCell().setText("col three, row one");
	
	XWPFTableRow tableTwoRowTwo = tableTwo.createRow();
	tableTwoRowTwo.getCell(0).setText("col one, row two");
	tableTwoRowTwo.getCell(1).setText("col two, row two");
	tableTwoRowTwo.getCell(2).setText("col three, row two");
	
	XWPFTableRow tableTwoRowThree = tableTwo.createRow();
	tableTwoRowThree.getCell(0).setText("col one, row three");
	tableTwoRowThree.getCell(1).setText("col two, row three");
	tableTwoRowThree.getCell(2).setText("col three, row three");
	
	FileOutputStream outStream = new FileOutputStream(dataPath + "Apache_CreateTable_Out.doc");
	document.write(outStream);
	outStream.close();
	
	System.out.println("Process Completed Successfully");
}
 
开发者ID:asposemarketplace,项目名称:Aspose_Words_for_Apache_POI,代码行数:43,代码来源:ApacheCreateTable.java

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

示例14: exportFiles

import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public void exportFiles(ArrayList<String> al, File outputfile) {
	if (b.fileindex != null) {
		TextViewer tv = new TextViewer(b, SWT.V_SCROLL | SWT.WRAP);
		StyledText styledText = tv.getTextWidget();
		// blackTextArea blackTextArea = new blackTextArea(styledText, b);
		styledText.setVisible(false);
		XWPFDocument doc = new XWPFDocument();
		ioThread io = new ioThread(b);
		Iterator<String> it = al.iterator();
		while (it.hasNext()) {
			String filename = it.next();
			File file = new File(b.projectFile.getParent() + "\\Files\\" + filename);
			if (file.exists()) {
				io.readBlackFile(file, tv);
				saveStylesToDocxFile(styledText, doc);
				// doc.createParagraph().set
			}
		}
		BufferedOutputStream bos = io.getBufferedFileOutputStream(outputfile);
		try {
			doc.write(bos);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		tv.getTextWidget().dispose();
		getMessageBox("", "������" + al.size() + "���ļ�");
	}
}
 
开发者ID:piiiiq,项目名称:Black,代码行数:30,代码来源:blackAction.java

示例15: main

import org.apache.poi.xwpf.usermodel.XWPFDocument; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
	XWPFDocument document = new XWPFDocument();
	XWPFParagraph tmpParagraph = document.createParagraph();
	XWPFRun tmpRun = tmpParagraph.createRun();
	tmpRun.setText("Apache Sample Content for Word file.");
	tmpRun.setFontSize(18);
	
	FileOutputStream fos = new FileOutputStream("data/Apache_newWordDoc.doc");
	document.write(fos);
	fos.close();
}
 
开发者ID:asposemarketplace,项目名称:Aspose_for_Apache_POI,代码行数:13,代码来源:ApacheNewDocument.java


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