Friday, 8 June 2012

Java: Generate Microsoft Word document


First you need download Apache POI - the Java API for Microsoft Documents, and next this fragment of code
    public void generateDoc(String text,int size, File file) throws Exception {
     XWPFDocument document = new XWPFDocument();
     XWPFParagraph tmpParagraph = document.createParagraph();
     XWPFRun tmpRun = tmpParagraph.createRun();
     tmpRun.setText(text);
     tmpRun.setFontSize(size);
     document.write(new FileOutputStream(file));
    }

2 comments:

  1. You can create word document from scratch by using Aspose.Words for Java Library. This Library offers many other features also. Try it, i hope you will like it also.

    http://www.aspose.com/java/word-component.aspx

    ReplyDelete
  2. Aspose is $999/year for a single develoepr.. and apache is free, isn't it?

    ReplyDelete