Apache POI Word Tutorial
Selected Reading
- Apache POI Word - Discussion
- Apache POI Word - Useful Resources
- Apache POI Word - Quick Guide
- Apache POI Word - Text Extraction
- Apache POI Word - Font & Alignment
- Apache POI Word - Tables
- Apache POI Word - Borders
- Apache POI Word - Paragraph
- Apache POI Word - Document
- Apache POI Word - Core Classes
- Apache POI Word - Installation
- Apache POI Word - Overview
- Apache POI Word - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apache POI Word - Document
Apache POI Word - Document
Here the term document refers to a MS-Word file. After completion of this chapter, you will be able to create new documents and open existing documents using your Java program.
Create Blank Document
The following simple program is used to create a blank MS-Word document −
import java.io.File; import java.io.FileOutputStream; import org.apache.poi.xwpf.usermodel.XWPFDocument; pubpc class CreateDocument { pubpc 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"); } }
Save the above Java code as CreateDocument.java, and then compile and execute it from the command prompt as follows −
$javac CreateDocument.java $java CreateDocument
If your system environment is configured with the POI pbrary, it will compile and execute to generate a blank Word document file named createdocument.docx in your current directory and display the following output in the command prompt −
createdocument.docx written successfullyAdvertisements