1. 程式人生 > >導出生成xsl文件

導出生成xsl文件

down value getc eas ast output create hssf pda

public String expData() throws Exception{ List<SubArea> list = subAreaService.findAll(); HSSFWorkbook hssf = new HSSFWorkbook(); HSSFSheet sheet = hssf.createSheet("分頁信息"); HSSFRow titleRow = sheet.createRow(0); titleRow.createCell(0).setCellValue("分區編號"); titleRow.createCell(1).setCellValue("所屬省份"); titleRow.createCell(2).setCellValue("所屬城市"); titleRow.createCell(3).setCellValue("所屬區域"); for (SubArea subArea: list) { HSSFRow dataRow = sheet.createRow(sheet.getLastRowNum()+1); dataRow.createCell(0).setCellValue(subArea.getId()); dataRow.createCell(1).setCellValue(subArea.getArea().getProvince()); dataRow.createCell(2).setCellValue(subArea.getArea().getCity()); dataRow.createCell(3).setCellValue(subArea.getArea().getDistrict()); } ServletOutputStream out = ServletActionContext.getResponse().getOutputStream(); ServletActionContext.getResponse().setContentType("application/vnd.ms-excel"); String fileName = "分區數據.xls"; String agent = ServletActionContext.getRequest().getHeader("User-Agent"); fileName = FileUtils.encodeDownloadFilename(fileName, agent); ServletActionContext.getResponse().setHeader("content-disposition", "attachment;filename="+fileName ); hssf.write(out); return NONE; }

導出生成xsl文件