Apache POI Word - Preface
Overview
In order to learn the Apache POI Word API more effectively, I have created a simple Word document lookes like following:
The document is designed with colorful elements, and its aesthetics are not the main focus. The purpose of creating such a document is to explore and utilize various features of the Apache POI Word API. It's important to note that the generation of this document will be done at the end as a practical exercise, rather than being generated from the start.
The reason for creating this series of articles is that the official documentation for Apache POI Word is quite limited. Although the official documentation does provide a quick guide, it might be "overly quick". The official documentation also includes some code samples for those who are interested, which can be found on the official website.
By creating this series of articles, we aim to provide more comprehensive and detailed explanations, examples, and practical exercises to help users better understand and utilize the Apache POI Word API.
Dependencies
We are using a relatively newer version of the POI library.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
If there are any charts involved, the following dependencies are also required.
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-full</artifactId>
<version>5.2.3</version>
</dependency>
The main content
To generate the aforementioned document, the following topics are involved, and we will introduce them in the following order:
- Creating and saving documents: Core class XWPFDocument
- Adding paragraphs and text to the document: Core classes XWPFParagraph and Run
- Generating tables: Core class XWPFTable
- Inserting images: Core class XWPFPicture
- Creating charts: Core class XWPFChart
In addition to the above topics, this series will also cover the following:
- Headers and footers
- Page breaks and sections
Please note that the document we are creating is in the docx format, corresponding to XWPFDocument in POI. If you're interested, please bookmark this page as the links to subsequent articles will be updated here.
Notice:Feedback requires logging into the system first.