多くの場合、プロセスを自動化し、プログラムでドキュメントを操作する必要があります。結果のドキュメントを大量に作成し、読み取り、処理し、保存するドキュメントを作成する必要があります。さまざまなファイル形式を同時に使用する必要があります。幸いなことに、Java開発者にとっては、wordSpreadsheetPresentionemail、[diagram][5で動作するオープンソースAPIがあります。 ]ファイル形式 - Apache Poi。このクロスプラットフォームAPIは、Java Virtual Machine(JVM)ベースの言語で動作するように設計されています。

{.wp-block-heading}のインストール方法}

Apache POIのインストールは簡単です。必要なのは、Mavenベースのプロジェクトに依存関係を追加することです。 pom.xmlに次の依存関係を追加して、Apache Poiを開始できます。

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>     
  <groupId>org.apache.poi</groupId>     
  <artifactId>poi</artifactId>     
  <version>4.1.0</version> 
</dependency>

単語文書を作成します

Apache POIを使用して、 xwpfdocument を使用して単語ドキュメントを作成し、 xwpfparagraph classを使用して段落を挿入できます。次のコードスニペットは、APIを使用して単語ドキュメントを作成する方法を示しています。

// initialize a blank document
XWPFDocument document = new XWPFDocument();
// create a new file
FileOutputStream out = new FileOutputStream(new File("createdocument.docx"));
// create a new paragraph paragraph
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("File Format Developer Guide -  " +
            "Learn about computer files that you come across in " +
            "your daily work at: www.fileformat.com ");
document.write(out);
out.close();
System.out.println("Document created successfully")

以下は、結果の出力ドキュメントです。 *