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?"); } }
source share