zoukankan      html  css  js  c++  java
  • 添加POI导出excel通用工具类

            /**
         * 文件写入excel
         * @param file 文件
         * @param list 数据源
         * @param sheetname 工作簿
         * @throws IOException
         */
        @SuppressWarnings("resource")
        public void exportExcel(File file,List<LinkedHashMap<String,Object>> list,String sheetname) throws IOException{
            
            Workbook workbook = new XSSFWorkbook(FileUtils.openInputStream(file));
            Sheet sheet = workbook.getSheet(sheetname);
            
            Row row = sheet.getRow(1);
            if (row == null) {
                row = sheet.createRow(1);
            }
            LinkedHashMap<String, Object> m =list.get(0);
                    String [] title = new String[m.size()];
                    int v = 0;
            for(String key : m.keySet()){
                title[v] = key;
                v++;
            }
            fos = new FileOutputStream(file);
            for (int i = 0; i < list.size(); i++) {
                row = sheet.createRow(i + 1);
                LinkedHashMap<String, Object> map = list.get(i);
                for (int j = 0; j < title.length; j++) {
                    row.createCell((short) j).setCellValue(map.get(title[j]) + "");
                }
            }
            workbook.write(fos);
            fos.flush();
            fos.close();
        }

  • 相关阅读:
    树型表的设计 上海
    FTP通讯封装 上海
    线程淡写 上海
    TCP通讯故障 上海
    设计模式引导 上海
    初试Delegate 上海
    c# 扫描端口 上海
    攻读计算机研究生的看法(转载) 上海
    挖掘表字段中的汉字 上海
    新生活运动 上海
  • 原文地址:https://www.cnblogs.com/ymj2018/p/11907266.html
Copyright © 2011-2022 走看看