当前位置:文档之家› echarts图表与列表文字结合导出word文档

echarts图表与列表文字结合导出word文档

导出word文件需要jar包Echarts图表可以生成BASE64编码function inita(hotWords,word,xData,hotWordtwo){ppend('<div style="height:180px" class="pro_zline"id="pro_zline'+i+'"></div>');({paths: {'echarts' : 'js/echarts','echarts/chart/line' : 'js/echarts', al('png'));al();$.ajax({type:'POST',url:'briefing/exp', al()+"&image2="+$("#image2").val(),beforeSend:function () { changeImg(); },error:function (XMLHttpRequest, textStatus, errorThrown) {alert(textStatus);},success: function (data) {="<%=basePath%>briefing/expword?date="+encodeURI(date); etAttribute, imageo);().setAttribute, imaget);return"waihu/generation";}后台导出word先建一个类packageimportimportimportimportimportimportimportimportimportimportimportimportimport/*** 适用于word 2007* poi 版本*/public class WordUtil {/*** 根据指定的参数值、模板,生成 word 文档* @param param 需要替换的变量* @param template 模板*/public static CustomXWPFDocument generateWord(Map<String, Object> param, String template) {CustomXWPFDocument doc = null;try {OPCPackage pack = (template);doc = new CustomXWPFDocument(pack);if (param != null && () > 0) {oString());int height = ("height").toString());int picType = getPictureType("type").toString());byte[] byteArray = (byte[]) ("content");ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteArray);try {int ind = (byteInputStream,picType);(ind, width , height,paragraph);} catch (Exception e) {();}}}}if(isSetText){(text,0);}}}}}}/*** 根据图片类型,取得对应的图片类型代码* @param picType* @return int*/private static int getPictureType(String picType){int res = ;if(picType != null){if("png")){res = ;}else if("dib")){res = ;}else if("emf")){res = ;}else if("jpg") || ("jpeg")){res = ;}else if("wmf")){res = ;}}return res;}/*** 将输入流中的数据写入字节数组* @param in* @return*/public static byte[] inputStream2ByteArray(InputStream in,boolean isClose){ byte[] byteArray = null;try {int total = ();byteArray = new byte[total];(byteArray);} catch (IOException e) {();}finally{if(isClose){try {();} catch (Exception e2) {"关闭流失败");}}}return byteArray;}}后台导出@RequestMapping(value="exp")etAttribute, imageo);().setAttribute, imaget);return"waihu/generation";}@RequestMapping(value="expword")etAttribute;String imaget = (String) ().getAttribute;Calendar cal = ();, -1);String yesterday = new SimpleDateFormat( "yyyy-MM-dd").format());if(date1==null){date1=yesterday;}List zxlist = (date1,"咨询类");List qzlist = (date1,"求助投诉类");List rdlist = (date1,"5");Briefing briefing1 = new Briefing();Briefing briefing =(date1,"");if(briefing==null){List list = (date1,"");for(int i=0;i<();i++){if(i==0){(i).toString());}if(i==1){(i).toString());}}("");}else{briefing1=briefing;}String aa= (" ","\\+");String bb= (" ","\\+");BASE64Decoder decoder = new BASE64Decoder();byte[] a = (aa);byte[] b = (bb);testTemplateWrite(zxlist,qzlist,rdlist,briefing1,date1,a,b,response);}public void testTemplateWrite(List zxlist,List qzlist,List rdlist,Briefingbriefing,String date,byte[] image1,byte[] image2,HttpServletResponse response) throws Exception {Map<String, Object> params = new HashMap<String, Object>();String tomcatPath=("");Map<String,Object> header = new HashMap<String, Object>();("width", 550);("height", 150);("type", "png");("content", image1);("${image1}",header);Map<String,Object> headers = new HashMap<String, Object>();("width", 550);("height", 150);("type", "png");("content", image2);("${image2}",headers);("${date}", date);("${content0}", ());("${content1}", ());("${content2}", ());String filepath = "";if ("\\")) {filepath = ("\\bin", "\\webapps\\army-infantry\\fileData\\") + "";}InputStream is = new FileInputStream(filepath);CustomXWPFDocument doc = new CustomXWPFDocument(is);ocx";();ServletOutputStream out = ();("application/");("Content-disposition", "attachment;filename=" + new String("GB2312"), "ISO-8859-1"));BufferedInputStream bis = null;BufferedOutputStream bos = null;try {bis = new BufferedInputStream(new FileInputStream(filepath));bos = new BufferedOutputStream(out);(out);} catch (IOException e) { throw e;} finally {if (bis != null)();if (bos != null)();}(is);}public List<List<String>> generateTestData(List lists) { List<List<String>> resultList = new ArrayList<List<String>>();for (int i = 0; i < (); i++) {List<String> list = new ArrayList<String>();Object[] obj =(Object[]) (i);String obj6="0%";if(obj[6]!=null){obj6= obj[6].toString()+"%";}String obj7="0%";if(obj[7]!=null){obj7= obj[7].toString()+"%";}(obj[0].toString());(obj[1].toString());(obj[2].toString());(obj[3].toString());(obj[4].toString());(obj[5].toString());(obj6);(obj7);(list);}return resultList;}public List<List<String>> generateTestDatas(List lists) { List<List<String>> resultList = new ArrayList<List<String>>();for (int i = 0; i < (); i++) {List<String> list = new ArrayList<String>();Object[] obj =(Object[]) (i);String obj3="0%";if(obj[3]!=null){obj3= obj[3].toString()+"%";}(obj[0].toString());(obj[1].toString());(obj[2].toString());(obj3);(list);}return resultList;}public void insertValueToTable(XWPFDocument doc,List<List<String>> resultList,int tableRowSize,boolean isDelTmpRow) throws Exception {Iterator<XWPFTable> iterator = ();XWPFTable table = null;List<XWPFTableRow> rows=null;List<XWPFTableCell> cells=null;List<XWPFTableCell> tmpCells=null;ize()){flag=true;break;}}}if(!flag){return;}tmpCells=();for(int i=0,len=();i<len;i++){XWPFTableRow row=();());List<String> list=(i);cells=();etW().getW());}etVal().getVal());ize()>0){CTP ctp=().get(0);if()!=null){if().getJc()!=null){().get(0).addNewPPr().addNewJc().setVal().getJc().getVal());}}}et(0);XWPFParagraph cellP=().get(0);XWPFRun tmpR =null;if()!=null&&().size()>0){tmpR=().get(0);XWPFRun cellR = ();(text);sSetRPr()){CTRPr tmpRPr =().getRPr();if()){CTFonts tmpFonts=();CTRPr cellRPr=().isSetRPr() ? ().getRPr() : ().addNewRPr();CTFonts cellFonts = () ? () : ();());());());());());());());());}}}}etPPr()!=null){CTPPr tmpPPr = ().getPPr();CTPPr cellPPr = ().getPPr() != null ? ().getPPr() : ().addNewPPr();?)\\}", ;Matcher matcher = (str);return matcher;}/*** 关闭输入流* @param is*/private void close(InputStream is) {if (is != null) {try {();} catch (IOException e) {();}}}模版导出的文件。

相关主题