版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、導(dǎo)出word文件需要jar包Echarts圖表可以生成BASE64編碼function inita(hotWords,word,xData,hotWordtwo)/ alert(xData);/$("#chart_wrapper").append('<div style="height:180px" class="pro_zline" id="pro_zline'+i+'"></div>'); require.config( paths: 'echar
2、ts' : 'js/echarts', 'echarts/chart/line' : 'js/echarts', /餅狀圖 'echarts/chart/bar' : 'js/echarts' /柱狀圖 ); require( 'echarts','echarts/chart/line', / 按需加載所需圖表,如需動(dòng)態(tài)類型切換功能,別忘了同時(shí)加載相應(yīng)圖表'echarts/chart/bar' , function (ec) / 基于準(zhǔn)備好的dom,初始化ec
3、harts圖表 var myChart = ec.init(document.getElementById(word); var option = grid : , tooltip : trigger: 'axis' , toolbox: show : true, feature : mark : show: true, dataView : show: true, readOnly: false, magicType : show: true, type: 'line', 'bar', restore : show: true, saveAsI
4、mage : show: true , calculable : true, animation : false, legend: data:'來(lái)電量','昨日數(shù)據(jù)對(duì)比' , xAxis : type : 'category', data : xData , yAxis : type : 'value', name : '來(lái)電量', axisLabel : formatter: 'value' , type : 'value', name : '昨日數(shù)據(jù)對(duì)比', ax
5、isLabel : formatter: 'value%' , series : name:'來(lái)電量', type:"bar", data:getPlatData(hotWords) , name:'昨日數(shù)據(jù)對(duì)比', type:"line", yAxisIndex: 1, data:getPlatData(hotWordtwo) ; / 為echarts對(duì)象加載數(shù)據(jù) myChart.setOption(option); $("#image1").val(myChart.getDataUR
6、L('png'); / alert( myChart.getDataURL('png')/獲取base64編碼 ); 獲取base64編碼圖片后要傳到后臺(tái)function AllAreaWord() var date =$("#year").val(); $.ajax( type:'POST', url:'briefing/exp', /用戶請(qǐng)求數(shù)據(jù)的URL data:"&date="+date+"&image1="+$("#image1&quo
7、t;).val()+"&image2="+$("#image2").val(), beforeSend:function () changeImg(); , error:function (XMLHttpRequest, textStatus, errorThrown) alert(textStatus); , success: function (data) ="<%=basePath%>briefing/expword?date="+encodeURI(date); /后臺(tái)將base64編碼圖片保存sessio
8、n中在執(zhí)行導(dǎo)出word );后臺(tái)處理將圖片編碼存到session中RequestMapping(value="exp")/簡(jiǎn)報(bào)生成echarts圖表public String exp(Model model,HttpServletRequest request)String image1 = request.getParameter("image1");String image2 = request.getParameter("image2");String url = image1.split(","); Str
9、ing url2 = image2.split(","); String imageo=""String imaget=""if(image1!=""&&url.length>1)imageo=url1;if(image2!=null&&url2.length>1)imaget=url21;request.getSession().setAttribute(SystemConstant.SESSION_IMGONE, imageo);request.getSession(
10、).setAttribute(SystemConstant.SESSION_IMGTWO, imaget);return "waihu/generation"后臺(tái)導(dǎo)出word先建一個(gè)類package ;import ; import ; import ; import ; import ; import ; import ; import ; import org.apache.poi.openxml4j.opc.OPCPackage; import ; import ; import ; import ; import ; /* 適用于word 2007* poi 版本
11、3.7*/ public class WordUtil /* * 根據(jù)指定的參數(shù)值、模板,生成 word 文檔 * param param 需要替換的變量 * param template 模板 */ public static CustomXWPFDocument generateWord(Map<String, Object> param, String template) CustomXWPFDocument doc = null; try OPCPackage pack = POIXMLDocument.openPackage(template); doc = new Cu
12、stomXWPFDocument(pack); if (param != null && param.size() > 0) /處理段落 List<XWPFParagraph> paragraphList = doc.getParagraphs(); processParagraphs(paragraphList, param, doc); /處理表格 Iterator<XWPFTable> it = doc.getTablesIterator(); while (it.hasNext() XWPFTable table = it.next();
13、List<XWPFTableRow> rows = table.getRows(); for (XWPFTableRow row : rows) List<XWPFTableCell> cells = row.getTableCells(); for (XWPFTableCell cell : cells) List<XWPFParagraph> paragraphListTable = cell.getParagraphs(); processParagraphs(paragraphListTable, param, doc); catch (Except
14、ion e) e.printStackTrace(); return doc; /* * 處理段落 * param paragraphList */ public static void processParagraphs(List<XWPFParagraph> paragraphList,Map<String, Object> param,CustomXWPFDocument doc) if(paragraphList != null && paragraphList.size() > 0) for(XWPFParagraph paragraph
15、:paragraphList) List<XWPFRun> runs = paragraph.getRuns(); for (XWPFRun run : runs) String text = run.getText(0); if(text != null) boolean isSetText = false; for (Entry<String, Object> entry : param.entrySet() String key = entry.getKey(); if(text.indexOf(key) != -1) isSetText = true; Obje
16、ct value = entry.getValue(); if (value instanceof String) /文本替換 text = text.replace(key, value.toString(); else if (value instanceof Map) /圖片替換 text = text.replace(key, ""); Map pic = (Map)value; int width = Integer.parseInt(pic.get("width").toString(); int height = Integer.parse
17、Int(pic.get("height").toString(); int picType = getPictureType(pic.get("type").toString(); byte byteArray = (byte) pic.get("content"); ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteArray); try int ind = doc.addPicture(byteInputStream,picType); doc.
18、createPicture(ind, width , height,paragraph); catch (Exception e) e.printStackTrace(); if(isSetText) run.setText(text,0); /* * 根據(jù)圖片類型,取得對(duì)應(yīng)的圖片類型代碼 * param picType * return int */ private static int getPictureType(String picType) int res = CustomXWPFDocument.PICTURE_TYPE_PICT; if(picType != null) if(p
19、icType.equalsIgnoreCase("png") res = CustomXWPFDocument.PICTURE_TYPE_PNG; else if(picType.equalsIgnoreCase("dib") res = CustomXWPFDocument.PICTURE_TYPE_DIB; else if(picType.equalsIgnoreCase("emf") res = CustomXWPFDocument.PICTURE_TYPE_EMF; else if(picType.equalsIgnoreCa
20、se("jpg") | picType.equalsIgnoreCase("jpeg") res = CustomXWPFDocument.PICTURE_TYPE_JPEG; else if(picType.equalsIgnoreCase("wmf") res = CustomXWPFDocument.PICTURE_TYPE_WMF; return res; /* * 將輸入流中的數(shù)據(jù)寫(xiě)入字節(jié)數(shù)組 * param in * return */ public static byte inputStream2ByteArray(In
21、putStream in,boolean isClose) byte byteArray = null; try int total = in.available(); byteArray = new bytetotal; in.read(byteArray); catch (IOException e) e.printStackTrace(); finally if(isClose) try in.close(); catch (Exception e2) ("關(guān)閉流失敗"); return byteArray; 后臺(tái)導(dǎo)出RequestMapping(value=&quo
22、t;exp")/簡(jiǎn)報(bào)生成echarts圖表public String exp(Model model,HttpServletRequest request)String image1 = request.getParameter("image1");String image2 = request.getParameter("image2");String url = image1.split(","); String url2 = image2.split(","); String imageo=&quo
23、t;"String imaget=""if(image1!=""&&url.length>1)imageo=url1;if(image2!=null&&url2.length>1)imaget=url21;request.getSession().setAttribute(SystemConstant.SESSION_IMGONE, imageo);request.getSession().setAttribute(SystemConstant.SESSION_IMGTWO, imaget);retu
24、rn "waihu/generation"RequestMapping(value="expword")/簡(jiǎn)報(bào)生成ResponseBodypublic void expword(Map dataMap,Model model,HttpServletRequest request,HttpServletResponse response) throws ExceptionString userId = request.getParameter("userId");String date1 = request.getParameter(&
25、quot;date"); String imageo = (String) request.getSession().getAttribute(SystemConstant.SESSION_IMGONE);String imaget = (String) request.getSession().getAttribute(SystemConstant.SESSION_IMGTWO);Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -1); String yesterday = new SimpleDateFo
26、rmat( "yyyy-MM-dd").format(cal.getTime();if(date1=null)date1=yesterday;List zxlist = workListService.queryByWorkList(date1,"咨詢類");List qzlist = workListService.queryByWorkList(date1,"求助投訴類");List rdlist = workListService.queryByconType(date1,"5");Briefing brie
27、fing1 = new Briefing();Briefing briefing =briefingService.getBriefing(date1,"");if(briefing=null)List list = workListService.queryByType(date1,"");for(int i=0;i<list.size();i+)if(i=0)briefing1.setContentOne(list.get(i).toString();if(i=1)briefing1.setContentTwo(list.get(i).toSt
28、ring();briefing1.setContent("");elsebriefing1=briefing;String aa= imageo.replaceAll(" ","+");String bb= imaget.replaceAll(" ","+");BASE64Decoder decoder = new BASE64Decoder(); byte a = decoder.decodeBuffer(aa);byte b = decoder.decodeBuffer(bb);testTe
29、mplateWrite(zxlist,qzlist,rdlist,briefing1,date1,a,b,response);public void testTemplateWrite(List zxlist,List qzlist,List rdlist,Briefing briefing,String date,byte image1,byte image2,HttpServletResponse response) throws Exception Map<String, Object> params = new HashMap<String, Object>()
30、; String tomcatPath=System.getProperty("user.dir"); Map<String,Object> header = new HashMap<String, Object>(); header.put("width", 550); header.put("height", 150); header.put("type", "png"); header.put("content", image1); params
31、.put("$image1",header); Map<String,Object> headers = new HashMap<String, Object>(); headers.put("width", 550); headers.put("height", 150); headers.put("type", "png"); headers.put("content", image2); params.put("$image2"
32、;,headers); params.put("$date", date); params.put("$content0", briefing.getContent(); params.put("$content1", briefing.getContentOne(); params.put("$content2", briefing.getContentTwo(); String filepath = "" if (tomcatPath.contains("") filep
33、ath = tomcatPath.replace("bin", "webappsarmy-infantryfileData") + "rxjbmb.docx" InputStream is = new FileInputStream(filepath); CustomXWPFDocument doc = new CustomXWPFDocument(is); /替換表格里面的變量 if(zxlist.size()!=0) insertValueToTable(doc, generateTestData(zxlist),1,false)
34、; if(qzlist.size()!=0) insertValueToTable(doc, generateTestData(qzlist),2,true); if(rdlist.size()!=0) insertValueToTable(doc, generateTestDatas(rdlist),2,true); /替換段落里面的變量 List<XWPFParagraph> paragraphList = doc.getParagraphs(); WordUcessParagraphs(paragraphList, params, doc); String fi
35、leName =date+"熱線簡(jiǎn)報(bào).docx" response.reset(); ServletOutputStream out = response.getOutputStream(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment;filename=" + new String(fileName.getBytes("GB2312&q
36、uot;), "ISO-8859-1"); BufferedInputStream bis = null; BufferedOutputStream bos = null; try bis = new BufferedInputStream(new FileInputStream(filepath); bos = new BufferedOutputStream(out); doc.write(out); catch (IOException e) throw e; finally if (bis != null) bis.close(); if (bos != null)
37、 bos.close(); this.close(is); public List<List<String>> generateTestData(List lists) List<List<String>> resultList = new ArrayList<List<String>>(); for (int i = 0; i < lists.size(); i+) List<String> list = new ArrayList<String>(); Object obj =(Objec
38、t) lists.get(i); String obj6="0%" if(obj6!=null) obj6= obj6.toString()+"%" String obj7="0%" if(obj7!=null) obj7= obj7.toString()+"%" list.add(obj0.toString(); list.add(obj1.toString(); list.add(obj2.toString(); list.add(obj3.toString(); list.add(obj4.toString(
39、); list.add(obj5.toString(); list.add(obj6); list.add(obj7); resultList.add(list); return resultList; public List<List<String>> generateTestDatas(List lists) List<List<String>> resultList = new ArrayList<List<String>>(); for (int i = 0; i < lists.size(); i+) Li
40、st<String> list = new ArrayList<String>(); Object obj =(Object) lists.get(i); String obj3="0%" if(obj3!=null) obj3= obj3.toString()+"%" list.add(obj0.toString(); list.add(obj1.toString(); list.add(obj2.toString(); list.add(obj3); resultList.add(list); return resultLis
41、t; public void insertValueToTable(XWPFDocument doc, List<List<String>> resultList,int tableRowSize,boolean isDelTmpRow) throws Exception Iterator<XWPFTable> iterator = doc.getTablesIterator(); XWPFTable table = null; List<XWPFTableRow> rows=null; List<XWPFTableCell> cel
42、ls=null; List<XWPFTableCell> tmpCells=null;/模版列 XWPFTableRow tmpRow=null;/匹配用 XWPFTableCell tmpCell=null;/匹配用 boolean flag=false;/是否找到表格 while (iterator.hasNext() table = iterator.next(); rows = table.getRows(); if(rows.size()=tableRowSize) tmpRow=rows.get(tableRowSize-1); cells =tmpRow.getTab
43、leCells(); if(cells.size()=resultList.get(0).size() flag=true; break; if(!flag) return; tmpCells=tmpRow.getTableCells(); for(int i=0,len=resultList.size();i<len;i+) XWPFTableRow row=table.createRow(); row.setHeight(tmpRow.getHeight(); List<String> list=resultList.get(i); cells=row.getTableCells(); /插入的行會(huì)填充與表格第一行相同的列數(shù) for(int k=0,klen=cells.size();k<klen;k+) tmpCell=tmpCells.get(k); XWPFTabl
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度二零二五年度工藝品電商平臺(tái)入駐合同2篇
- 2025年度城市綜合體地下車位租賃合作協(xié)議3篇
- 2025年度廢舊家電拆解與環(huán)保新材料研發(fā)合同
- 2025年度工業(yè)通信網(wǎng)絡(luò)快速接入標(biāo)準(zhǔn)化合同
- 2025年度城市地下綜合管廊建設(shè)工程施工合同
- 2025年度廠房物業(yè)財(cái)產(chǎn)移交與能源審計(jì)服務(wù)合同
- 2025年度航空航天部件委外加工及檢測(cè)合同
- 2025年度高速公路充電樁場(chǎng)地租賃與配套設(shè)施建設(shè)協(xié)議2篇
- 2025年度城市更新改造合作投標(biāo)協(xié)議書(shū)
- 2025年度國(guó)際文化交流活動(dòng)聘用合同3篇
- 湖北省武漢市洪山區(qū)2022-2023學(xué)年五年級(jí)上學(xué)期期末考試科學(xué)試題
- 以學(xué)增智-提升推進(jìn)高質(zhì)量發(fā)展的本領(lǐng)研討發(fā)言稿
- 2023年10月自考00055企業(yè)會(huì)計(jì)學(xué)真題及答案含評(píng)分標(biāo)準(zhǔn)
- 幼兒園人事工作總結(jié)
- 可修改版五年級(jí)數(shù)學(xué)期中考試答題卡模板
- 精裝修工程工作界面劃分
- 山東省青島市市北區(qū)2023-2024學(xué)年九年級(jí)上學(xué)期11月期中數(shù)學(xué)試題
- 【語(yǔ)文】上海市三年級(jí)上冊(cè)期末復(fù)習(xí)試題(含答案)
- 遙感技術(shù)基礎(chǔ)第二版課后答案
- 項(xiàng)目式高中化學(xué)教學(xué)《保護(hù)珊瑚礁的措施-沉淀溶解平衡》
- 犯罪現(xiàn)場(chǎng)勘察題庫(kù)(348道)
評(píng)論
0/150
提交評(píng)論