poi将html导出到word

来源:互联网 发布:ucg软件下载 编辑:程序博客网 时间:2024/06/06 18:47
import java.io.ByteArrayInputStream;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;import org.apache.poi.poifs.filesystem.DirectoryEntry;import org.apache.poi.poifs.filesystem.DocumentEntry;import org.apache.poi.poifs.filesystem.POIFSFileSystem;public class Main {public static void main(String[] args) {    boolean w = false;          String path = "d:/";          try {              if (!"".equals(path)) {                  // 检查目录是否存在                  File fileDir = new File(path);                  if (fileDir.exists()) {                      // 生成临时文件名称                      String fileName = "a.doc";                      String content = "<html><div style=\"text-align: center\"><span style=\"font-size: 28px\"><span style=\"font-family: 黑体\">" +                          "制度发布通知<br /> <br /> </span></span></div></html>";                      byte b[] = content.getBytes();                      ByteArrayInputStream bais = new ByteArrayInputStream(b);                      POIFSFileSystem poifs = new POIFSFileSystem();                      DirectoryEntry directory = poifs.getRoot();                      DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);                      FileOutputStream ostream = new FileOutputStream(path+ fileName);                      poifs.writeFilesystem(ostream);                      bais.close();                      ostream.close();                  }              }          } catch (IOException e) {              e.printStackTrace();        }  }}


 

0 0
原创粉丝点击