• 使用poi进行excel下载


    进行信息表excel导出

    @RequestMapping("exportExl")
    public ResponseEntity<byte[]> exportExl() throws Exception {
        List<Customer> clist = cs.getList();
        HSSFWorkbook book = new HSSFWorkbook();
        HSSFSheet sheet = book.createSheet("客户信息表");
        sheet.setDefaultColumnWidth(15);
        //表头行创建
        HSSFRow header = sheet.createRow(0);
        header.createCell(0).setCellValue("职工序号");
        header.createCell(1).setCellValue("联系人姓名");
        header.createCell(2).setCellValue("公司名称");
        header.createCell(3).setCellValue("添加时间");
        header.createCell(4).setCellValue("联系电话");
        //clist数据写入单元格
        for (int i = 0; i < clist.size(); i++) {
            Customer cus = clist.get(i);
            HSSFRow row = sheet.createRow(i + 1);
            row.createCell(0).setCellValue(cus.getId());
            row.createCell(1).setCellValue(cus.getCompanyperson());
            row.createCell(2).setCellValue(cus.getComname());
            row.createCell(3).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(cus.getAddtime()));

            row.createCell(4).setCellValue(cus.getComphone());
        }
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        book.write(bos);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentDispositionFormData("attachment", new String("客户列表.xls".getBytes("GBK"), "ISO-8859-1"));
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(bos.toByteArray(), headers, HttpStatus.OK);

     

  • 相关阅读:
    postman参数化—上个接口返回数据作为下个接口入参
    postman设置token为全局变量
    postman请求https协议接口
    安装VMware 置灰正确解决办法
    Cron 表达式详解
    Jmeter + ant + jenkins轻量级接口自动化测试
    Jmeter CSV 参数化/检查点/断言
    Android专项测试-cpu,流量
    Android专项测试-获取启动时间
    腾讯云测试工程师--面试总结
  • 原文地址:https://www.cnblogs.com/meani/p/12628354.html
Copyright © 2020-2023  润新知