- Apache POI Word Tutorial
- Apache POI Word - Home
- Apache POI Word - Overview
- Apache POI Word - Installation
- Apache POI Word - Core Classes
- Apache POI Word - Document
- Apache POI Word - Paragraph
- Apache POI Word - Borders
- Apache POI Word - Tables
- Apache POI Word - Font & Alignment
- Apache POI Word - Text Extraction
- Apache POI Word Resources
- Apache POI Word - Quick Guide
- Apache POI Word - Useful Resources
- Apache POI Word - Discussion
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的空白 Word 文档文件,并在命令提示符中显示以下输出 -
createdocument.docx written successfully