Javaexamples-create-blank-word-document

提供:Dev Guides
2020年6月22日 (月) 17:28時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

空のWord文書を作成する

問題の説明

Javaを使用して空白のワードドキュメントを作成する方法。

溶液

以下は、Javaを使用して空のワードドキュメントを作成するプログラムです。

import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

public class CreateWordDocument {
   public static void main(String[] args)throws Exception {

     //Blank Document
      XWPFDocument document = new XWPFDocument();

     //Write the Document in file system
      FileOutputStream out = new FileOutputStream (
         new File("C:/poiword/createdocument.docx"));

      document.write(out);
      out.close();

      System.out.println("createdocument.docx written successully");
   }
}

出力

空白語