Articles in this section
Category / Section

How to generate Word document in Java

3 mins read

Syncfusion® Java Word library (Essential® DocIO) is used to generate, read, and edit Word documents programmatically without Microsoft Word or Interop dependencies. Using this library, you can generate a Word document in the Java application.

Steps to generate Word document programmatically in Java

  1. Create a new HelloWorld.java file and include the following namespaces.

JAVA

import com.syncfusion.docio.*;
  1. Use the following code sample to generate a Word document with a simple text.

JAVA

// Creates a new instance of WordDocument (Empty Word Document).
WordDocument document = new WordDocument();
// Add a section and a paragraph to the document.
document.ensureMinimal();
// Append text to the last paragraph of the document.
document.getLastParagraph().appendText("Hello World");
// Save the Word document.
document.save("Result.docx");
// Close the Word document.
document.close();

A complete working example of how to generate a Word document in Java can be downloaded from GitHub.

By executing the program, you will get the Word document as follows,

Generated or created Word document

You can refer to here to know about how to run the Syncfusion® Java Word library (Essential® DocIO).

Take a moment to peruse the documentation. You can find the basic Word document processing options along with features like mail merge, merge, and split documents.

Explore more about a rich set of Syncfusion® Word Framework features.

A Github example to generate or create a Word document with basic elements.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied