How to create a Word document using Apache POI?

How to create a Word document using Apache POI?

I am developing a resume editor for Atlassian Confluence as a commercial plugin.

I wish I had to ask about this, but I do not find textbooks that can help me.

+4
source share
2 answers

The attached code file "DownloadAsMicrosoftWordDocument.java.txt" contains code for downloading files; no word document creation.

When you are looking to create a Word Document, refer to the links below:

HWPF link (.doc): There are no examples in the POI line like XWPF, however the Scratchpad POI has test files around it, please find

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

And also link to POI Javadocs for XWPF (Word Document).

I hope this will provide a launch for you!

+13
source
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 ru?"); } } 
+8
source

Source: https://habr.com/ru/post/1447666/


All Articles