I need to generate MS word documents automatically. Then I started to search how to accomplish this task and found Apache POI library. We can easily work with MS Office documents (word, excel, etc.) with Apache POI library. For details please go https://poi.apache.org.

I want to go on with my case. I need to get values (parameters) from a text file or excel file and generate multiple word documents according to those values. For the simplicity, I selected to use a text file for reading parameters and then generate word documents.

Now, let’s go with JAVA codes.

I divided my code in three parts.

1) ReadFile Class: Reads the text file and returns list of values. These values will be our parameters for word generation.

2) WordGenerator Class: It contains getLines and createWord methods. First we get the values with getLines method and createWord method to create word documents.

3) Main Class: This is our top level class in which we instantiate WordGenerator Class and call its methods.

ReadFile Class

WordGenerator Class

Main Class

Input Text File

Console Output and Result:



word generation