zoukankan      html  css  js  c++  java
  • EXCEL最简洁导出(不带样式设置)

    /**.
     */
    
    package com.encdata.lihao;
    
    import java.io.FileOutputStream;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.LinkedHashMap;
    import java.util.List;
    import java.util.Map;
    
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Workbook;
    
    /**.
     *
     * @author admin
     *
     */
    public class ExcelExport {
      
      /**
       * https://blog.csdn.net/ink4t/article/details/77150183.
       * @param args
       * @throws Exception
       */
      
      public static void main(String[] args) throws Exception {
        
        List<List<Map<String, Object>>> listlist = new ArrayList<>();
        
        List<Map<String, Object>> mapList1 = new ArrayList<>();
        List<Map<String, Object>> mapList2 = new ArrayList<>();
        List<Map<String, Object>> mapList3 = new ArrayList<>();
        
        Map<String, Object> map1 = new LinkedHashMap<>();
        Map<String, Object> map2 = new LinkedHashMap<>();
        Map<String, Object> map3 = new LinkedHashMap<>();
        
        map1.put("name1", "value1");
        map1.put("name2", "value2");
        
        map2.put("name11", "value11");
        map2.put("name22", "value22");
        
        map3.put("name111", "value111");
        map3.put("name222", "value222");
        
        mapList1.add(map1);
        mapList1.add(map2);
        mapList1.add(map3);
        
        
        mapList2.add(map2);
        mapList2.add(map1);
        mapList2.add(map3);
        
        mapList3.add(map3);
        mapList3.add(map2);
        mapList3.add(map1);
        
        listlist.add(mapList1);
        listlist.add(mapList2);
        listlist.add(mapList3);
        
        // 建立一个Excel
        Workbook book = new HSSFWorkbook();
        
        int i= 0;
        
        for (List<Map<String, Object>> mapList : listlist ) {
          
          Sheet sheet1 =(Sheet) book.createSheet("分表"+i);
          
          i++;
          
          int j= 0;
          
          for (Map<String, Object> map : mapList) {
            
            Row row = sheet1.createRow(j);
            
            j++;
            
            int k=0;
            
            for (String str : map.keySet()) {
              
              Cell cell = row.createCell(k);
              
              k++;
              
              cell.setCellValue((String)map.get(str));
              
            }
            
          }
          
        }
          
        book.write( new FileOutputStream("D://aaa.xls"));
     
      }
    
    }
  • 相关阅读:
    Intellij IDEA + Jrebel
    WebConfig配置详解大全
    .Net 获取前端传递的数据
    js 格式验证大全
    EasyUI DataGrid 时间格式化、字符串长度截取
    SQL取某个字符串最后一次出现的位置后面的字符串方法
    公民身份号码校验码算法(C#版)
    组织机构代码校验码生成算法(C#版)
    MySQL实现根据当前ID读取上一条和下一条记录
    js jquery.pagination.js分页
  • 原文地址:https://www.cnblogs.com/lh-masteryi/p/9087219.html
Copyright © 2011-2022 走看看