@RequestMapping(value = "databack", method = RequestMethod.GET)
public void downloadAllClassmate(HttpServletResponse response) throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("信息表");
List classmateList = tagLabelService.findall();
String fileName = "t_o7xz_tagLabel" + ".xls";//设置要导出的文件的名字
//新增数据行,并且设置单元格数据
int rowNum = 1;
String[] headers = { "id", "tag标签名称", "tag标签点击量", "tag标签关联文章数量","tag标签链接","创建时间","是否推荐到首页","备注"};
//headers表示excel表中第一行的表头
HSSFRow row = sheet.createRow(0);
//在excel表中添加表头
for(int i=0;i
HSSFCell cell = row.createCell(i);
HSSFRichTextString text = new HSSFRichTextString(headers[i]);
cell.setCellValue(text);
}
//在表中存放查询到的数据放入对应的列
for (TagdbVo teacher : classmateList) {
HSSFRow row1 = sheet.createRow(rowNum);
row1.createCell(0).setCellValue(teacher.getId());
row1.createCell(1).setCellValue(teacher.getTagLabel_name());
row1.createCell(2).setCellValue(teacher.getTagLabel_click());
row1.createCell(3).setCellValue(teacher.getTagLabel_relate());
row1.createCell(0).setCellValue(teacher.getTagLabel_url());
row1.createCell(0).setCellValue(teacher.getCreate_time());
row1.createCell(0).setCellValue(teacher.getRemark());
row1.createCell(0).setCellValue(teacher.getRem());
rowNum++;
}
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName,"utf-8"));
response.flushBuffer();
workbook.write(response.getOutputStream());
}
前段按钮 <a href="" data-toggle="doajax" class="btn btn-green" onclick="downloadfile();" >下载tagExcl表</a>
function downloadfile(){
window.location.href="${ctxPath}/tagLabel/databack";
}