Javaexamples-create-blank-word-document

提供:Dev Guides
移動先:案内検索

空の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");
   }
}

出力

空白語