• poi导出excel


    private static String [] HeaderList4 = { "时间", "小区", "低CQI占比" };

    OutputStream output = null;
            try {
                // 设置response头信息
                response.reset();
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");// 改成输出excel文件
                response.setHeader("Content-disposition",
                        "attachment;filename="  + URLEncoder.encode("优化指标"+TimeConvertor.todayTime()+".xlsx", "UTF-8"));

                // 创建HSSFWorkbook对象(excel的文档对象)
                Workbook wb = new XSSFWorkbook();
                //获取工参时间与详情时间
                request.setScanStartTime(TimeConvertor.beforeYestodaysDate());
                //上个月1号
                request.setBeforeMonth(TimeConvertor.beforeMonth());
                ArrayList<TwoOptimizationKpiEntity> dataList = mapper.getDataList(request);
                for (TwoOptimizationKpiEntity twoOptimizationKpiEntity : dataList) {
                    if(twoOptimizationKpiEntity.getLongitude()==null || twoOptimizationKpiEntity.getLongitude()<100 || twoOptimizationKpiEntity.getLongitude()>200) {
                        Double[] xx = {};
                        twoOptimizationKpiEntity.setCoordinateList(xx);
                    }else {
                    Double[] xx = { twoOptimizationKpiEntity.getLongitude(), twoOptimizationKpiEntity.getLatitude() };
                    twoOptimizationKpiEntity.setCoordinateList(xx);
                    }
                }
                List<List<String>> contenets3 = new ArrayList<>();
                for (TwoOptimizationKpiEntity workOrderEntity : dataList) {
                    List<String> content = new ArrayList<>();
                    content.add(String.valueOf(workOrderEntity.getTimeStamp()));
                    content.add(String.valueOf(workOrderEntity.getCellName()));
                    content.add(String.valueOf(workOrderEntity.getHdFlag()));
                    contenets3.add(content);
                }
                if (request.getHdFlag() == 4) {
                    creatSheet(wb, "低CQI占比", HeaderList4, contenets3);
                }
              
                // 输出Excel文件
                output = response.getOutputStream();
                wb.write(output);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    output.flush();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                try {
                    output.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        private void creatSheet(Workbook wb, String sheetName, String[] header, List<List<String>> contents) {
            // 建立新的sheet对象(excel的表单)
            Sheet sheet = wb.createSheet(sheetName);
            // 在sheet里创建第一行
            Row row = sheet.createRow(0);
            int i = 0;
            for (String head : header) {
                row.createCell(i++).setCellValue(head);
            }
            // 在sheet里创建行
            int rownum = 1;
            for (List<String> content : contents) {
                i = 0;
                Row row1 = sheet.createRow(rownum++);
                for (String s : content) {
                    row1.createCell(i++).setCellValue(s);
                }
            }
        }

  • 相关阅读:
    控制台内容保存为文件
    SpringBoot
    JAVA基础
    jenkins的.gradle目录结构说明和清理
    macos 签名+公证app生成dmg后,安装使用过程中崩溃
    MacOS命令行打包+签名+公证+生成dmg文件
    jenkins构建调用tar报错:tar: Failed to set default locale
    jenkins构建报错:appdmg: command not found
    jenkins 构建xcode-select -s 切换xcode版本失败 (切换xcode路径无效)
    jenkins 执行shell编译go 代码报错:build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined
  • 原文地址:https://www.cnblogs.com/ymj2018/p/10112151.html
Copyright © 2020-2023  润新知