首页 > 其他 > 详细

导出生成xsl文件

时间:2018-01-06 18:18:58      阅读:401      评论:0      收藏:0      [点我收藏+]
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文件

原文:https://www.cnblogs.com/guanzhuang/p/8214913.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!