Apache-poi-word-quick-guide

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

Apache POI Word-概要

多くの場合、Microsoft Wordファイル形式の参照ドキュメントを生成するにはソフトウェアアプリケーションが必要です。 場合によっては、アプリケーションがWordファイルを入力データとして受け取ることさえ期待されます。

出力としてMS-Officeファイルを作成するJavaプログラマは、事前定義された読み取り専用APIを使用して作成する必要があります。

Apache POIとは何ですか?

Apache POIは、プログラマーがJavaプログラムを使用してMS-Officeファイルを作成、変更、表示できる一般的なAPIです。 Javaプログラムを使用してMS-Officeファイルを設計または変更するために、Apache Software Foundationによって開発および配布されたオープンソースライブラリです。 ユーザー入力データまたはファイルをMS-Officeドキュメントにデコードするクラスとメソッドが含まれています。

Apache POIのコンポーネント

Apache POIには、MS-OfficeのすべてのOLE2複合ドキュメントで動作するクラスとメソッドが含まれています。 このAPIのコンポーネントのリストは以下のとおりです-

  • * POIFS(難読化実装ファイルシステム)*-このコンポーネントは、他のすべてのPOI要素の基本的な要素です。 異なるファイルを明示的に読み取るために使用されます。
  • * HSSF(恐ろしいスプレッドシート形式)*-MS-Excelファイルの.xls形式の読み取りおよび書き込みに使用されます。
  • * XSSF(XML SpreadSheet Format)*-MS-Excelの.xlsxファイル形式に使用されます。
  • * HPSF(恐ろしいプロパティセット形式)*-MS-Officeファイルのプロパティセットを抽出するために使用されます。
  • * HWPF(Horrible Word Processor Format)*-MS-Wordの.doc拡張ファイルの読み取りと書き込みに使用されます。
  • * XWPF(XML Word Processor Format)-MS-Wordの *.docx 拡張ファイルの読み取りおよび書き込みに使用されます。
  • * HSLF(恐ろしいスライドレイアウト形式)*-PowerPointプレゼンテーションの読み取り、作成、および編集に使用されます。
  • * HDGF(Horrible DiaGram Format)*-MS-Visioバイナリファイルのクラスとメソッドが含まれています。
  • * HPBF(Horrible PuBlisher Format)*-MS-Publisherファイルの読み取りと書き込みに使用されます。

このチュートリアルでは、Javaを使用してMS-Wordファイルで作業するプロセスをガイドします。 したがって、説明はHWPFおよびXWPFコンポーネントに限定されます。

-DOC、XLS、PPT、ETCなどのPOIサポートバイナリファイル形式の古いバージョン。 バージョン3.5以降、POIはDOCX、XLSX、PPTX、ETCなどのMS-OfficeのOOXMLファイル形式をサポートしています。

Apache POI Word-インストール

この章では、WindowsおよびLinuxベースのシステムでApache POIを設定するプロセスについて説明します。 Apache POIは簡単にインストールして現在のJava環境に統合でき、複雑なセットアップ手順なしでいくつかの簡単な手順を実行できます。 インストール中にユーザー管理が必要です。

システム要求

JDK Java SE 2 JDK 1.5 or above
Memory 1 GB RAM (recommended)
Disk Space No minimum requirement
Operating System Version Windows XP or above, Linux

Apache POIをインストールする手順に進みましょう。

ステップ1:Javaインストールを確認する

まず、システムにJava Software Development Kit(SDK)をインストールする必要があります。 これを確認するには、作業しているプラ​​ットフォームに応じて、以下の2つのコマンドのいずれかを実行します。

Javaインストールが適切に行われている場合、Javaインストールの現在のバージョンと仕様が表示されます。 サンプル出力は、次の表に記載されています-

Platform Command Sample Output
Windows

Open command console and type −

  • \> java –version*

a

Javaバージョン「1.7.0_60」

Java(TM)SEランタイム環境(ビルド1.7.0_60-b19)

Java Hotspot(TM)64ビットサーバーVM(ビルド24.60-b09、混合モード)

Linux

Open command terminal and type −

  • $ java –version*

a

Javaバージョン "1.7.0_25"

JDKランタイム環境を開く(rhel-2.3.10.4.el6_4-x86_64)

JDK 64ビットサーバーVMを開く(ビルド23.7-b01、混合モード)

ステップ2:Java環境を設定する

Javaがマシンにインストールされているベースディレクトリの場所を指すように、環境変数JAVA_HOMEを設定します。 例えば、

Platform Description
Windows Set JAVA_HOME to C:\ProgramFiles\java\jdk1.7.0_60
Linux Export JAVA_HOME =/usr/local/java-current

Javaコンパイラの場所の完全パスをシステムパスに追加します。

Platform Description
Windows Append the String "C:\Program Files\Java\jdk1.7.0_60\bin" to the end of the system variable PATH.
Linux Export PATH = $PATH:$JAVA_HOME/bin/

上記で説明したように、コマンドプロンプトからコマンド java-version を実行します。

ステップ3:Apache POIライブラリをインストールする

[[1]] POIをダウンロードし、必要なライブラリをJavaプログラムにリンクできるフォルダにそのコンテンツを解凍します。 ファイルがCドライブのフォルダーに収集されると仮定します。

次の画像は、ダウンロードしたフォルダ内のディレクトリとファイル構造を示しています-

Jar Hierarchy1

Jar Hierarchy2

上記の画像で強調表示されている5つの jars の完全なパスをCLASSPATHに追加します。

Platform Description
Windows

Append the following strings to the end of the user variable CLASSPATH −

「C:\ poi-3.9 \ poi-3.9-20121203.jar;」

「C:\ poi-3.9 \ poi-ooxml-3.9-20121203.jar;」

「C:\ poi-3.9 \ poi-ooxml-schemas-3.9-20121203.jar;」

「C:\ poi-3.9 \ ooxml-lib \ dom4j-1.6.1.jar;」

「C:\ poi-3.9 \ ooxml-lib \ xmlbeans-2.3.0.jar;。;」

Linux

Export CLASSPATH = $CLASSPATH:

/usr/share/poi-3.9/poi-3.9-20121203.tar:

/usr/share/poi-3.9/poi-ooxml-schemas-3.9-20121203.tar:

/usr/share/poi-3.9/poi-ooxml-3.9-20121203.tar:

/usr/share/poi-3.9/ooxml-lib/dom4j-1.6.1.tar:

/usr/share/poi-3.9/ooxml-lib/xmlbeans-2.3.0.tar

Apache POI Word-コアクラス

この章では、Word文書を管理するためのApache POIのクラスとメソッドについて説明します。

資料

これは、実装されたクラスがワードドキュメントを作成できることを通知するマーカーインターフェイスです(インターフェイスにはメソッドが含まれていません)。

XWPFDocument

これは org.apache.poi.xwpf.usermodel パッケージの下のクラスです。 .docxファイル形式でMS-Wordドキュメントを作成するために使用されます。

クラスメソッド

Sr.No. Method & Description
1

commit()

ドキュメントをコミットして保存します。

2

createParagraph()

このドキュメントに新しい段落を追加します。

3

createTable()

デフォルトで1行1列の空のテーブルを作成します。

4

createTOC()

Wordドキュメントの目次を作成します。

5

getParagraphs()

ヘッダーまたはフッターのテキストを保持する段落を返します。

6

getStyle()

使用されているスタイルオブジェクトを返します。

このクラスの残りのメソッドについては、完全なAPIドキュメントを参照してください-

Package org.apache.poi.openxml4j.opc.internal

XWPFParagraph

これは org.apache.poi.xwpf.usermodel パッケージの下のクラスであり、単語文書に段落を作成するために使用されます。 このインスタンスは、すべてのタイプの要素をワード文書に追加するためにも使用されます。

クラスメソッド

Sr.No. Method & Description
1

createRun()

この段落に新しい実行を追加します。

2

getAlignment()

この段落のテキストに適用される段落の配置を返します。

3

setAlignment(ParagraphAlignment align)

この段落のテキストに適用される段落の配置を指定します。

4

setBorderBottom(Borders border)

段落の境界設定の同じセットを持つ段落のセットの下に表示される境界を指定します。

5

setBorderLeft(Borders border)

指定された段落の周囲のページの左側に表示される境界線を指定します。

6

setBorderRight(Borders border)

指定した段落の周囲のページの右側に表示される境界線を指定します。

7

setBorderTop(Borders border)

同じ段落境界設定のセットを持つ段落のセットの上に表示される境界を指定します。

このクラスの残りのメソッドについては、完全なAPIドキュメントを参照してください-

https://poi.apache.org/apidocs/indexl?org/apache/poi/openxml4j/opc/internal/package-summaryl.[POI APIドキュメント]

XWPFRun

これは org.apache.poi.xwpf.usermodel パッケージの下のクラスであり、段落にテキストの領域を追加するために使用されます。

クラスメソッド

Sr.No. Method & Description
1

addBreak()

実行コンテンツの現在の位置にブレークを配置することを指定します。

2

addTab()

実行コンテンツの現在の場所にタブを配置することを指定します。

3

setColor(java.lang.String rgbStr)

テキストの色を設定します。

4

setFontSize(int size)

表示時にこの実行のコンテンツ内のすべての非複雑なスクリプト文字に適用されるフォントサイズを指定します。

5

setText(java.lang.String value)

このテキストランのテキストを設定します。

6

setBold(boolean value)

ドキュメントに表示されるときに、この実行のコンテンツ内のすべての非複雑なスクリプト文字に太字プロパティを適用するかどうかを指定します。

このクラスの残りのメソッドについては、完全なAPIドキュメントを参照してください-

https://poi.apache.org/apidocs/indexl?org/apache/poi/openxml4j/opc/internal/package-summaryl.[POI APIドキュメント]

XWPFStyle

これは org.apache.poi.xwpf.usermodel パッケージの下のクラスであり、ワードドキュメント内のオブジェクト要素に異なるスタイルを追加するために使用されます。

クラスメソッド

Sr.No. Method & Description
1

getNextStyleID()

次のスタイルのStyleIDを取得するために使用されます。

2

getStyleId()

スタイルのStyleIDを取得するために使用されます。

3

getStyles()

スタイルを取得するために使用されます。

4

setStyleId(java.lang.String styleId)

styleIDの設定に使用されます。

このクラスの残りのメソッドについては、完全なAPIドキュメントを参照してください-

https://poi.apache.org/apidocs/indexl?org/apache/poi/openxml4j/opc/internal/package-summaryl.[POI APIドキュメント]

XWPFTable

これは org.apache.poi.xwpf.usermodel パッケージの下のクラスであり、表データをワード文書に追加するために使用されます。

クラスメソッド

Sr.No. Method & Description
1

addNewCol()

このテーブルの各行に新しい列を追加します。

2

addRow(XWPFTableRow row, int pos)

テーブルの位置posに新しい行を追加します。

3

createRow()

その瞬間に定義された列の数と同じ数のセルを持つ新しいXWPFTableRowオブジェクトを作成します。

4

setWidth(int width)

列の幅を設定します。

このクラスの残りのメソッドについては、https://poi.apache.org/apidocs/indexl?org/apache/poi/openxml4j/opc/internal/package-summaryl。[POI APIドキュメント]にある完全なAPIドキュメントを参照してください。

XWPFWordExtractor

これは org.apache.poi.xwpf.extractor パッケージの下のクラスです。 これは、Word文書から単純なテキストを抽出するために使用される基本的なパーサークラスです。

クラスメソッド

Sr.No. Method & Description
1

getText()

ドキュメントからすべてのテキストを取得します。

このクラスの残りのメソッドについては、https://poi.apache.org/apidocs/indexl?org/apache/poi/openxml4j/opc/internal/package-summaryl。[POI APIドキュメント]にある完全なAPIドキュメントを参照してください。

Apache POI Word-ドキュメント

ここで、「ドキュメント」という用語はMS-Wordファイルを指します。 この章を完了すると、Javaプログラムを使用して新しいドキュメントを作成し、既存のドキュメントを開くことができます。

白紙の文書を作成

次の簡単なプログラムは、空白のMS-Word文書を作成するために使用されます-

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

public class CreateDocument {

   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("createdocument.docx"));
      document.write(out);
      out.close();
      System.out.println("createdocument.docx written successully");
   }
}

上記のJavaコードを* CreateDocument.java、*として保存し、次のようにコマンドプロンプトからコンパイルして実行します-

$javac  CreateDocument.java
$java CreateDocument

システム環境がPOIライブラリで構成されている場合、現在のディレクトリに createdocument.docx という名前の空のExcelファイルを生成するためにコンパイルおよび実行され、コマンドプロンプトに次の出力が表示されます-

createdocument.docx written successfully

Apache POI Word-段落

この章では、段落を作成する方法と、Javaを使用して文書に段落を追加する方法を学習します。 段落は、Wordファイルのページの一部です。

この章を完了すると、段落を作成し、読み取り操作を実行できるようになります。

段落を作成する

まず、前の章で説明した参照クラスを使用して段落を作成しましょう。 前の章に従って、最初にドキュメントを作成し、次に段落を作成できます。

次のコードスニペットは、スプレッドシートを作成するために使用されます-

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

//Create a blank spreadsheet
   XWPFParagraph paragraph = document.createParagraph();

段落で実行

*Run* を使用して、テキストまたは任意のオブジェクト要素を入力できます。 Paragraphインスタンスを使用して、*実行*を作成できます。

次のコードスニペットを使用して、Runを作成します。

XWPFRun run = paragraph.createRun();

段落に書き込む

文書にテキストを入力してみましょう。 以下のテキストデータを考慮してください-

At finddevguides.com, we strive hard to provide quality tutorials for self-learning
purpose in the domains of Academics, Information Technology, Management and Computer
Programming Languages.

次のコードは、上記のデータを段落に書き込むために使用されます。

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

public class CreateParagraph {

   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("createparagraph.docx"));

     //create Paragraph
      XWPFParagraph paragraph = document.createParagraph();
      XWPFRun run = paragraph.createRun();
      run.setText("At finddevguides.com, we strive hard to " +
         "provide quality tutorials for self-learning " +
         "purpose in the domains of Academics, Information " +
         "Technology, Management and Computer Programming
         Languages.");

      document.write(out);
      out.close();
      System.out.println("createparagraph.docx written successfully");
   }
}

上記のJavaコードを* CreateParagraph.java、*として保存し、次のようにコマンドプロンプトからコンパイルして実行します-

$javac CreateParagraph.java
$java CreateParagraph

現在のディレクトリに createparagraph.docx という名前のWordファイルを生成するためにコンパイルおよび実行され、コマンドプロンプトで次の出力が表示されます-

createparagraph.docx written successfully
*createparagraph.docx* ファイルは次のようになります。

段落の作成

Apache POI Word-ボーダー

この章では、Javaプログラミングを使用して段落に境界線を適用する方法を学習します。

ボーダーを適用する

次のコードは、ドキュメントに境界線を適用するために使用されます-

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

public class ApplyingBorder {

   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("applyingborder.docx"));

     //create paragraph
      XWPFParagraph paragraph = document.createParagraph();

     //Set bottom border to paragraph
      paragraph.setBorderBottom(Borders.BASIC_BLACK_DASHES);

     //Set left border to paragraph
      paragraph.setBorderLeft(Borders.BASIC_BLACK_DASHES);

     //Set right border to paragraph
      paragraph.setBorderRight(Borders.BASIC_BLACK_DASHES);

     //Set top border to paragraph
      paragraph.setBorderTop(Borders.BASIC_BLACK_DASHES);

      XWPFRun run = paragraph.createRun();
         run.setText("At finddevguides.com, we strive hard to " +
         "provide quality tutorials for self-learning " +
         "purpose in the domains of Academics, Information " +
         "Technology, Management and Computer Programming " +
         "Languages.");

      document.write(out);
      out.close();
      System.out.println("applyingborder.docx written successully");
   }
}

上記のコードを* ApplyingBorder.javaという名前のファイルに保存し、次のようにコマンドプロンプトからコンパイルして実行します-

$javac ApplyingBorder.java
$java ApplyingBorder

システムがPOIライブラリで構成されている場合、現在のディレクトリに applyingborder.docx という名前のWord文書を生成するためにコンパイルおよび実行され、次の出力が表示されます-

applyingborder.docx written successfully
*applyingborder.docx* ファイルは次のようになります-

境界線段落

Apache POI Word-テーブル

この章では、ドキュメントにデータのテーブルを作成する方法を学びます。 XWPFTable クラスを使用して、テーブルデータを作成できます。 各 Row をテーブルに追加し、各 cellRow に追加すると、テーブルデータが取得されます。

テーブルを作成

次のコードは、ドキュメント内のテーブルを作成するために使用されます-

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

public class CreateTable {

   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("create_table.docx"));

     //create table
      XWPFTable table = document.createTable();

     //create first row
      XWPFTableRow tableRowOne = table.getRow(0);
      tableRowOne.getCell(0).setText("col one, row one");
      tableRowOne.addNewTableCell().setText("col two, row one");
      tableRowOne.addNewTableCell().setText("col three, row one");

     //create second row
      XWPFTableRow tableRowTwo = table.createRow();
      tableRowTwo.getCell(0).setText("col one, row two");
      tableRowTwo.getCell(1).setText("col two, row two");
      tableRowTwo.getCell(2).setText("col three, row two");

     //create third row
      XWPFTableRow tableRowThree = table.createRow();
      tableRowThree.getCell(0).setText("col one, row three");
      tableRowThree.getCell(1).setText("col two, row three");
      tableRowThree.getCell(2).setText("col three, row three");

      document.write(out);
      out.close();
      System.out.println("create_table.docx written successully");
   }
}

上記のコードを* CreateTable.java。*という名前のファイルに保存し、次のようにコンパイルしてコマンドプロンプトから実行します-

$javac CreateTable.java
$java CreateTable

現在のディレクトリに createtable.docx という名前のWordファイルを生成し、コマンドプロンプトに次の出力を表示します-

createtable.docx written successfully
*createtable.docx* ファイルは次のようになります-

テーブルの作成

Apache POI Word-フォントと配置

この章では、Javaを使用してWord文書にさまざまなフォントスタイルと配置を適用する方法を示します。 通常、フォントスタイルには、フォントサイズ、タイプ、太字、斜体、下線が含まれます。 また、配置は左、中央、右、および正当化に分類されます。

フォントスタイル

次のコードは、フォントの異なるスタイルを設定するために使用されます-

import java.io.File;
import java.io.FileOutputStream;

import org.apache.poi.xwpf.usermodel.VerticalAlign;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

public class FontStyle {

   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("fontstyle.docx"));

     //create paragraph
      XWPFParagraph paragraph = document.createParagraph();

     //Set Bold an Italic
      XWPFRun paragraphOneRunOne = paragraph.createRun();
      paragraphOneRunOne.setBold(true);
      paragraphOneRunOne.setItalic(true);
      paragraphOneRunOne.setText("Font Style");
      paragraphOneRunOne.addBreak();

     //Set text Position
      XWPFRun paragraphOneRunTwo = paragraph.createRun();
      paragraphOneRunTwo.setText("Font Style two");
      paragraphOneRunTwo.setTextPosition(100);

     //Set Strike through and Font Size and Subscript
      XWPFRun paragraphOneRunThree = paragraph.createRun();
      paragraphOneRunThree.setStrike(true);
      paragraphOneRunThree.setFontSize(20);
      paragraphOneRunThree.setSubscript(VerticalAlign.SUBSCRIPT);
      paragraphOneRunThree.setText(" Different Font Styles");

      document.write(out);
      out.close();
      System.out.println("fontstyle.docx written successully");
   }
}

上記のコードを FontStyle.java として保存し、次のようにコマンドプロンプトからコンパイルして実行します-

$javac FontStyle.java
$java FontStyle

現在のディレクトリに fontstyle.docx という名前のWordファイルが生成され、コマンドプロンプトに次の出力が表示されます-

fontstyle.docx written successfully
*fontstyle.docx* ファイルは次のようになります。

フォントスタイル

アライメント

次のコードは、段落テキストに配置を設定するために使用されます-

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

public class AlignParagraph {

   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("alignparagraph.docx"));

     //create paragraph
      XWPFParagraph paragraph = document.createParagraph();

     //Set alignment paragraph to RIGHT
      paragraph.setAlignment(ParagraphAlignment.RIGHT);
      XWPFRun run = paragraph.createRun();
      run.setText("At finddevguides.com, we strive hard to " +
         "provide quality tutorials for self-learning " +
         "purpose in the domains of Academics, Information " +
         "Technology, Management and Computer Programming " +
         "Languages.");

     //Create Another paragraph
      paragraph = document.createParagraph();

     //Set alignment paragraph to CENTER
      paragraph.setAlignment(ParagraphAlignment.CENTER);
      run = paragraph.createRun();
      run.setText("The endeavour started by Mohtashim, an AMU " +
         "alumni, who is the founder and the managing director " +
         "of Tutorials Point (I) Pvt. Ltd. He came up with the " +
         "website finddevguides.com in year 2006 with the help" +
         "of handpicked freelancers, with an array of tutorials" +
         " for computer programming languages. ");

      document.write(out);
      out.close();
      System.out.println("alignparagraph.docx written successfully");
   }
}

上記のコードを AlignParagraph.java として保存し、コマンドプロンプトから次のようにコンパイルして実行します-

$javac AlignParagraph.java
$java AlignParagraph

現在のディレクトリに alignparagraph.docx という名前のWordファイルが生成され、コマンドプロンプトに次の出力が表示されます-

alignparagraph.docx written successfully
*alignparagraph.docx* ファイルは次のようになります-

段落の整列

Apache POI Word-テキスト抽出

この章では、Javaを使用してWord文書から単純なテキストデータを抽出する方法について説明します。 Word文書からメタデータを抽出する場合は、Apache Tikaを使用してください。

docxファイルの場合、Wordファイルから単純なデータを抽出して返すクラスorg.apache.poi.xwpf.extractor.XPFFWordExtractorを使用します。 同様に、見出し、脚注、表データなどを抽出するさまざまな方法があります。 Wordファイルから。.

次のコードは、Wordファイルから単純なテキストを抽出する方法を示しています-

import java.io.FileInputStream;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

public class WordExtractor {

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

      XWPFDocument docx = new XWPFDocument(new FileInputStream("create_paragraph.docx"));

     //using XWPFWordExtractor Class
      XWPFWordExtractor we = new XWPFWordExtractor(docx);
      System.out.println(we.getText());
   }
}

上記のコードを* WordExtractor.java。*として保存し、次のようにコンパイルしてコマンドプロンプトから実行します-

$javac WordExtractor.java
$java WordExtractor

次の出力が生成されます。

At finddevguides.com, we strive hard to provide quality tutorials for self-learning
purpose in the domains of Academics, Information Technology, Management and Computer
Programming Languages.