zoukankan      html  css  js  c++  java
  • java POI html生成word(html里面带图片,Linux系统导出图片无法显示)

    /**
     * html导出word
     * @param person 人员数据
     * @param wordfile word入径 
     * @param filtlist 过滤子弹
     * @param showCJ 是否导出成绩
     * @throws InvalidParameterException
     * @throws IOException
     */
    public void createWord(BasicDBObject person,File wordfile,Map<String, String> filtlist,Boolean showCJ) throws IOException {
        StringBuffer html = new StringBuffer();
        for (String key : filtlist.keySet()) {
            if(filtlist.get(key).equals("4")||filtlist.get(key).equals("9"))
                person.put(key, null);
            else
                person.put(key, "***");
        }
        if(showCJ)
            html.append(CreateHtmlPrint(person,printContent2));
        
        html.append(CreateHtmlPrint(person,printContent1));
        
        POIFSFileSystem poifs = null;
        FileOutputStream ostream = null;
        ByteArrayInputStream bais = null;
        try {
            byte[] b = getHtml(html).toString().getBytes();
            bais = new ByteArrayInputStream(b);
            poifs = new POIFSFileSystem();
            DirectoryEntry directory = poifs.getRoot();
            directory.createDocument("WordDocument", bais);//WordDocument名称不允许修改
            ostream = new FileOutputStream(wordfile);
            poifs.writeFilesystem(ostream);//生成word文档
        } finally {
            if (ostream != null) ostream.close();
            if (bais != null) bais.close();
        }
    }
    
    public StringBuffer getHtml(Object in){
        StringBuffer html = new StringBuffer();
        html.append("<html>")
            .append("<head>")
            .append("<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />")
            .append("<style>")
            .append("BODY {PADDING-BOTTOM: 0px; LINE-HEIGHT: 1.5; FONT-STYLE: normal; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; COLOR: #333; FONT-SIZE: 13px; FONT-WEIGHT: normal; PADDING-TOP: 0px}")
            .append("table{border:1px solid #000;}")
            .append("table td{border:1px solid #000;}")
            .append("</style>")
            .append("</head>")
            .append("<body>");
        html.append(in);
        html.append("</body></html>");
        return html;
    }
  • 相关阅读:
    Hanlp(汉语言处理包)配置、使用、官方文档
    Mysql 在DOS窗口下的操作
    漂亮的省级下拉选择
    数组的应用排序
    设置外部样式坐标的位置
    动态设置Div坐标
    对联广告
    树形菜单
    隐藏图和图框架
    使用clssneme改变图片或样式
  • 原文地址:https://www.cnblogs.com/BobXie85/p/12409058.html
Copyright © 2011-2022 走看看