@RequestMapping(value = "readviewxl.do", method = RequestMethod.GET) // 选择 public @ResponseBody byte[] readViewXl(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException { String dwxxId = request.getParameter("companyId"); String year = request.getParameter("year"); String month = request.getParameter("month"); List<String[]> ret = fxJkcbJsjbService.getViewDataListXl(dwxxId, year, month); String retstr = JSONArray.fromObject(ret).toString().replace("null", "\"\""); String result = "{\"values\":" + retstr + "}"; return result.getBytes("utf-8"); }
@RequestMapping(value = "exportxl.do") public @ResponseBody byte[] exportxl(HttpServletRequest request, HttpServletResponse response) throws IOException { String dwxxId = ""; String dwxxname = ""; dwxxId = request.getParameter("companyId"); if (dwxxId.equals("900000")) { dwxxname = "变压器产业"; } else if (dwxxId.equals("800000")) { dwxxname = "线缆产业"; } else { dwxxname = zzyDWXXService.getDwxx(Integer.parseInt(dwxxId)).getName(); } String year = request.getParameter("year"); String month = request.getParameter("month"); List<String[]> data = fxJkcbJsjbService.getViewDataListXl(dwxxId, year, month); String fileNameAndSheetName = dwxxname; fileNameAndSheetName += request.getParameter("year") + "年" + request.getParameter("month") + "月技术降本"; JygkZzyExcelTemplate template = JygkZzyExcelTemplate.createJygkTemplate("20006"); HSSFWorkbook workbook = template.getWorkbook(); HSSFSheet sheet = workbook.getSheetAt(0); JygkZzyFormatterHandler formatterChain = this.getFormatterChainWithHeader(new Integer[] {}, new Integer[] {1, 2, 3, 4, 5}); for (int i = 0, ilen = data.size(); i < ilen; ++i) { HSSFRow row = sheet.createRow(1 + i); for (int j = 0, jlen = data.get(i).length; j < jlen; ++j) { HSSFCell cell = row.createCell(j); formatterChain.handle(data.get(i)[0], j, template, cell, data.get(i)[j]); } } template.write(response, fileNameAndSheetName + ".xls"); return "".getBytes("utf-8"); }