标签:size new lis print inpu order keyset @param out
/** * 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; }
标签:size new lis print inpu order keyset @param out
原文地址:https://www.cnblogs.com/BobXie85/p/12409058.html