读书人

java html变换为word文档

发布时间: 2013-08-01 15:23:18 作者: rapoo

java html转换为word文档

public static boolean writeWordFile() {          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();        }        return w;      }  

?

读书人网 >CSS

热点推荐