Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package templateexemplo; import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFParagraph; import org.apache.poi.xwpf.usermodel.XWPFRun; /** * * @author 20142BSI0038 */ public class ExportWORD extends Export { BufferedWriter out = null; XWPFDocument document; FileOutputStream out1 = null; public ExportWORD() { String current = null; try { current = new java.io.File(".").getCanonicalPath(); out1 = new FileOutputStream(new File(current + "\\src\\" + "word.docx")); document = new XWPFDocument(); //Blank Document } catch (IOException ex) { Logger.getLogger(ExportWORD.class.getName()).log(Level.SEVERE, null, ex); } } @Override public void printLine(String linha) { XWPFParagraph paragraph = document.createParagraph(); XWPFRun run = paragraph.createRun(); run.setText(linha); } @Override public void save() throws IOException { document.write(out1); out1.close(); } }