EXCEL最简洁导出(不带样式设置)

Posted lh-masteryi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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"));
 
  }

}

 

以上是关于EXCEL最简洁导出(不带样式设置)的主要内容,如果未能解决你的问题,请参考以下文章

vue3导出表格excel(支持多sheet页),并自定义导出样式

导出Excel之Epplus使用教程2(样式设置)

DevExpress导出Excel样式设置

poi导出excel设置样式

Office Com组件根据模板导出Excel

导出Excel之Epplus使用教程4(其他设置)