zoukankan      html  css  js  c++  java
  • 使用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);

     

  • 相关阅读:
    设计模式—适配器模式
    设计模式—策略模式 状态模式
    设计模式——装饰模式和代理模式
    C++常考算法
    ModelState.AddModelError使用
    Json
    ref与out
    三层与mvc
    新的方法(Set<T>)实现mvc的crud
    【程序45】
  • 原文地址:https://www.cnblogs.com/meani/p/12628354.html
Copyright © 2011-2022 走看看