在Java编程中,如何使用Java来创建一个空的Wold文档?
注意:需要访问网址: , 下载一个Apache POI软件包。这里下载最新版本:poi-bin-3.17-20170915.tar.gz解压并将全部.jar文件导入。
需要导入全部包,如下图所示 –
以下是使用Java创建一个空的Wold文档的程序。
package com.yiibai; import java.io.File; import java.io.FileOutputStream; import org.apache.poi.xwpf.usermodel.XWPFDocument; public class CreateWordDocument { 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"); } }
执行上面示例代码,得到以下结果 –
createdocument.docx written successully
¥ 我要打赏 纠错/补充 收藏