当前位置: 代码迷 >> HTML/CSS >> java html变换为word文档
  详细解决方案

java html变换为word文档

热度:143   发布时间:2013-08-01 15:23:18.0
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;  
    }  

?

  相关解决方案