日期:2014-05-17 浏览次数:20831 次
public String downloadTemplate() throws FileNotFoundException, IOException { String template = get("template"); URL url = ClassLoaderUtil.getResource(template, this.getClass()); String fileName = url.getFile(); Workbook workbook = new HSSFWorkbook(url.openStream()); Sheet sheet = workbook.getSheetAt(0); Row titles = sheet.getRow(0); Row keys = sheet.getRow(1); List<CourseHourType> courseHourTypes = baseCodeService.getCodes(CourseHourType.class); for (CourseHourType courseHourType : courseHourTypes) { Cell hourTitleCell = titles.createCell(titles.getLastCellNum(), Cell.CELL_TYPE_STRING); hourTitleCell.setCellValue(courseHourType.getName()); Cell hourKeyCell = keys.createCell(keys.getLastCellNum(), Cell.CELL_TYPE_STRING); hourKeyCell.setCellValue("period_hours_" + courseHourType.getCode()); } response.reset(); String contentType = response.getContentType(); String attch_name = DownloadHelper.getAttachName(fileName); if (null == contentType) { contentType = "application/x-msdownload"; response.setContentType(contentType); logger.debug("set content type {} for {}", contentType, attch_name); } response.addHeader("Content-Disposition", "attachment; filename=\"" + RequestUtils.encodeAttachName(request, attch_name) + "\""); workbook.write(response.getOutputStream()); return null; }