7

How to create a Word Document using Apache POI?

I am developing a Resume Editor for Atlassian Confluence as Commercial Plugin.

I am sorry I had to ask this but I do not find tutorials witch can help me.

3
  • Anyone can answerd for this question? Commented Nov 22, 2012 at 10:26
  • Do you want to generate an OLE2 based .doc Word document, or the newer OOXML based .docx one? Commented Nov 27, 2012 at 11:10
  • 1
    I want generate .doc Word Doucment. Commented Jan 18, 2013 at 17:46

2 Answers 2

16

Your attached code file "DownloadAsMicrosoftWordDocument.java.txt" has a coding for file download functionality; no Word document creation.

As you looking for Word Document creation, please find references below:

HWPF Reference(.doc): POI trunk doesn't have examples as XWPF do, However POI Scratchpad has Testcases around it, please find

XWPF Reference(.docx): Examples from Apache POI SVN Repo

And also refer POI Javadocs for XWPF (Word Document).

I hope it will provide startup for you!

Sign up to request clarification or add additional context in comments.

10 Comments

@Matti Kiviharju - is above details helpful for you?
Thanks but Confluence includes POI that not include XWPF.
@MattiKiviharju - added HWPF scratchpad reference
@seinecle - POI team restructured the package, I have updated the links and removed non-working links. Thanks.
The Links are broken again as it has been restructured yet again.Latest Working Links as of 3 JAN 2021 svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/…
|
10
package org.poi.images;

import java.io.File;   
  import java.io.FileOutputStream;   
  import org.apache.poi.xwpf.usermodel.XWPFDocument;   
  import org.apache.poi.xwpf.usermodel.XWPFParagraph;   
  import org.apache.poi.xwpf.usermodel.XWPFRun;   
  public class DocFile {   
    public void newWordDoc(String filename, String fileContent)   
         throws Exception {   
       XWPFDocument document = new XWPFDocument();   
       XWPFParagraph tmpParagraph = document.createParagraph();   
       XWPFRun tmpRun = tmpParagraph.createRun();   
       tmpRun.setText(fileContent);   
       tmpRun.setFontSize(18);   
       FileOutputStream fos = new FileOutputStream(new File("C:\\Users\\amitabh\\Pictures\\pics\\"+filename + ".doc"));   
       document.write(fos);   
       fos.close();   
    }   
    public static void main(String[] args) throws Exception {   
         DocFile app = new DocFile();   
         app.newWordDoc("testfile", "Hi hw r u?");   

    }   
  }   

1 Comment

Thanks from the answer. I was long time banned from Stack Overflow, because I asked too complex questions and they was too difficult to understand.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.