/**.
 */

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"));
 
  }

}