Advertisement
juliarnasution

cetak_dokumen

Sep 15th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package model;
  7.  
  8. import java.io.File;
  9. import java.io.FileNotFoundException;
  10. import java.io.FileOutputStream;
  11. import java.io.IOException;
  12. import java.util.logging.Level;
  13. import java.util.logging.Logger;
  14. import javax.swing.JOptionPane;
  15. import org.apache.poi.xwpf.usermodel.XWPFDocument;
  16. import org.apache.poi.xwpf.usermodel.XWPFParagraph;
  17. import org.apache.poi.xwpf.usermodel.XWPFRun;
  18. import view.Frame_surat;
  19.  
  20. /**
  21.  *
  22.  * @author nasution
  23.  */
  24. public class Model_dokumen {
  25.    
  26.     public void Cetak(Frame_surat fs) throws Exception {
  27.         try {
  28.             XWPFDocument document = new XWPFDocument();
  29. //            XWPFDocument document = new XWPFDocument();//blank document
  30.             //membuat paragraf
  31.            
  32.              //membuat dokumen surat keluar
  33.             try (FileOutputStream outputStream = new FileOutputStream(new File("Surat_keluar.docx"))) {
  34.                 //membuat paragraf
  35.                 XWPFParagraph paragraf = document.createParagraph();
  36.                 XWPFRun run = paragraf.createRun();
  37.                 run.setText("ini adalah halaman dokumen yg baru saja dibuat menggunakan POI");
  38.                 document.write(outputStream);
  39.             }
  40.             JOptionPane.showMessageDialog(null, "Surat keluar berhasil dibuat");
  41.         } catch (FileNotFoundException ex) {
  42.             Logger.getLogger(Model_dokumen.class.getName()).log(Level.SEVERE, null, ex);
  43.         } catch (IOException ex) {
  44.             Logger.getLogger(Model_dokumen.class.getName()).log(Level.SEVERE, null, ex);
  45.         }
  46.     }
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement