zoukankan      html  css  js  c++  java
  • excel导出

    查询的结果结

    List list  = commissionMService.getMapper().meishengExport(paramMap);

    // 第一步,创建一个webbook,对应一个Excel文件
    HSSFWorkbook wb = new HSSFWorkbook();
    // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
    HSSFSheet sheet = wb.createSheet("委托单数据");
    // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
    HSSFRow row = sheet.createRow((int) 0);
    // 第四步,创建单元格,并设置值表头 设置表头居中
    HSSFCellStyle style = wb.createCellStyle();
    sheet.setDefaultColumnWidth(30);

    sheet.setColumnWidth(0, 20 * 256);

    HSSFCell cell = row.createCell((short) 0);
    cell.setCellValue("委托单号");
    cell.setCellStyle(style);
    cell = row.createCell((short) 1);
    cell.setCellValue("出厂计划号");
    cell.setCellStyle(style);
    cell = row.createCell((short) 2);
    cell.setCellValue("提单号");
    cell.setCellStyle(style);
    cell = row.createCell((short) 3);
    cell.setCellValue("装点库区");
    cell.setCellStyle(style);
    cell = row.createCell((short) 4);
    cell.setCellValue("计划净重");
    cell.setCellStyle(style);

    遍历结果集填充excel

    for(int i =0;i<list.size();i++){

    String mission = (String) map.get("MISSION_NO");//委托单号
    String pack_code = (String) map.get("PACK_CODE");//出厂计划
    String product_id = (String) map.get("PRODUCT_ID");//提单号
    String PRODUCT_SHOPSIGN = (String) map.get("PRODUCT_SHOPSIGN");//装区库点
    double NET_WEIGHT = 0;
    if(StrUtil.isNotNull(map.get("NET_WEIGHT"))){
    NET_WEIGHT = Double.parseDouble(map.get("NET_WEIGHT").toString());//计划净重
    }
    double GROSS_WEIGHT = 0;
    if(StrUtil.isNotNull(map.get("GROSS_WEIGHT"))){
    NET_WEIGHT = Double.parseDouble(map.get("GROSS_WEIGHT").toString());//毛重
    }
    double SHEET_COUNTS = 0;
    if(StrUtil.isNotNull(map.get("SHEET_COUNTS"))){
    NET_WEIGHT = Double.parseDouble(map.get("SHEET_COUNTS").toString());//件数
    }
    String TRANS_FROM_CONTRACT = (String)map.get("TRANS_FROM_CONTRACT");//固定人

    row.createCell((short) 0).setCellValue (mission); //委托单号
    row.createCell((short) 1).setCellValue (pack_code); //出厂计划
    row.createCell((short) 2).setCellValue (product_id); //提单号
    row.createCell((short) 3).setCellValue (PRODUCT_SHOPSIGN); //装区库点
    row.createCell((short) 4).setCellValue (NET_WEIGHT); //计划净重
    row.createCell((short) 5).setCellValue (GROSS_WEIGHT); //毛重
    row.createCell((short) 6).setCellValue (SHEET_COUNTS); //件数
    row.createCell((short) 7).setCellValue (TRANS_FROM_CONTRACT); // 固定人

    }

    最后输出excel

    OutputStream os = response.getOutputStream();
    wb.write(os);
    os.flush();
    os.close();

  • 相关阅读:
    微信小程序开发工具初始化代码仓库
    微信小程序开发如何初始化远程仓库并 PUSH
    Git 提示用户密码错误如何修改
    MariaDB 在创建外键的时候提示 1005 错误
    Fiddler实现移动端手机抓包
    Windows 安装 Go语言开发环境以及使用
    laravel队列,事件简单使用方法
    视图
    laravel Passport
    多台服务器 同时部署一套代码
  • 原文地址:https://www.cnblogs.com/lizihao/p/5690687.html
Copyright © 2011-2022 走看看