EasyPoi导出包含动态列的Excel

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处连接和
<dependency>
  1.  
    <groupId>cn.afterturn </groupId>
  2.  
    <artifactId>easypoi-base </artifactId>
  3.  
    <version>3.2.0 </version>
  4.  
    </dependency>
@Test
  1.  
        public void dynaCol() {
  2.  
    try {
  3.  
    List<ExcelExportEntity> colList = new ArrayList<ExcelExportEntity>();
  4.  
    ExcelExportEntity colEntity = new ExcelExportEntity( "商品名称", "title");
  5.  
    colEntity.setNeedMerge( true);
  6.  
    colList.add(colEntity);
  7.  
     
  8.  
    colEntity = new ExcelExportEntity( "供应商", "supplier");
  9.  
    colEntity.setNeedMerge( true);
  10.  
    colList.add(colEntity);
  11.  
     
  12.  
    ExcelExportEntity deliColGroup = new ExcelExportEntity( "得力", "deli");
  13.  
    List<ExcelExportEntity> deliColList = new ArrayList<ExcelExportEntity>();
  14.  
    deliColList.add( new ExcelExportEntity( "市场价", "orgPrice"));
  15.  
    deliColList.add( new ExcelExportEntity( "专区价", "salePrice"));
  16.  
    deliColGroup.setList(deliColList);
  17.  
    colList.add(deliColGroup);
  18.  
     
  19.  
    ExcelExportEntity jdColGroup = new ExcelExportEntity( "京东", "jd");
  20.  
    List<ExcelExportEntity> jdColList = new ArrayList<ExcelExportEntity>();
  21.  
    jdColList.add( new ExcelExportEntity( "市场价", "orgPrice"));
  22.  
    jdColList.add( new ExcelExportEntity( "专区价", "salePrice"));
  23.  
    jdColGroup.setList(jdColList);
  24.  
    colList.add(jdColGroup);
  25.  
     
  26.  
     
  27.  
    List< Map< String, Object>> list = new ArrayList< Map< String, Object>>();
  28.  
    for (int i = 0; i < 10; i++) {
  29.  
    Map< String, Object> valMap = new HashMap< String, Object>();
  30.  
    valMap.put( "title", "名称." + i);
  31.  
    valMap.put( "supplier", "供应商." + i);
  32.  
     
  33.  
    List< Map< String, Object>> deliDetailList = new ArrayList< Map< String, Object>>();
  34.  
    for (int j = 0; j < 3; j++) {
  35.  
    Map< String, Object> deliValMap = new HashMap< String, Object>();
  36.  
    deliValMap.put( "orgPrice", "得力.市场价." + j);
  37.  
    deliValMap.put( "salePrice", "得力.专区价." + j);
  38.  
    deliDetailList.add(deliValMap);
  39.  
    }
  40.  
    valMap.put( "deli", deliDetailList);
  41.  
     
  42.  
    List< Map< String, Object>> jdDetailList = new ArrayList< Map< String, Object>>();
  43.  
    for (int j = 0; j < 2; j++) {
  44.  
    Map< String, Object> jdValMap = new HashMap< String, Object>();
  45.  
    jdValMap.put( "orgPrice", "京东.市场价." + j);
  46.  
    jdValMap.put( "salePrice", "京东.专区价." + j);
  47.  
    jdDetailList.add(jdValMap);
  48.  
    }
  49.  
    valMap.put( "jd", jdDetailList);
  50.  
     
  51.  
    list.add(valMap);
  52.  
    }
  53.  
     
  54.  
    Workbook workbook = ExcelExportUtil.exportExcel( new ExportParams( "价格分析表", "数据"), colList,
  55.  
    list);
  56.  
    FileOutputStream fos = new FileOutputStream( "D:/价格分析表.tt.xls");
  57.  
    workbook.write(fos);
  58.  
    fos.close();
  59.  
    } catch (FileNotFoundException e) {
  60.  
    e.printStackTrace();
  61.  
    } catch (IOException e) {
  62.  
    e.printStackTrace();
  63.  
    }
  64.  
    }
 

导出结果图html

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处连接和本声明。
 
  
 
  1.  
    <dependency>
  2.  
    <groupId>cn.afterturn </groupId>
  3.  
    <artifactId>easypoi-base </artifactId>
  4.  
    <version>3.2.0 </version>
  5.  
    </dependency>
@Test
  1.  
        public void dynaCol() {
  2.  
    try {
  3.  
    List<ExcelExportEntity> colList = new ArrayList<ExcelExportEntity>();
  4.  
    ExcelExportEntity colEntity = new ExcelExportEntity( "商品名称", "title");
  5.  
    colEntity.setNeedMerge( true);
  6.  
    colList.add(colEntity);
  7.  
     
  8.  
    colEntity = new ExcelExportEntity( "供应商", "supplier");
  9.  
    colEntity.setNeedMerge( true);
  10.  
    colList.add(colEntity);
  11.  
     
  12.  
    ExcelExportEntity deliColGroup = new ExcelExportEntity( "得力", "deli");
  13.  
    List<ExcelExportEntity> deliColList = new ArrayList<ExcelExportEntity>();
  14.  
    deliColList.add( new ExcelExportEntity( "市场价", "orgPrice"));
  15.  
    deliColList.add( new ExcelExportEntity( "专区价", "salePrice"));
  16.  
    deliColGroup.setList(deliColList);
  17.  
    colList.add(deliColGroup);
  18.  
     
  19.  
    ExcelExportEntity jdColGroup = new ExcelExportEntity( "京东", "jd");
  20.  
    List<ExcelExportEntity> jdColList = new ArrayList<ExcelExportEntity>();
  21.  
    jdColList.add( new ExcelExportEntity( "市场价", "orgPrice"));
  22.  
    jdColList.add( new ExcelExportEntity( "专区价", "salePrice"));
  23.  
    jdColGroup.setList(jdColList);
  24.  
    colList.add(jdColGroup);
  25.  
     
  26.  
     
  27.  
    List< Map< String, Object>> list = new ArrayList< Map< String, Object>>();
  28.  
    for (int i = 0; i < 10; i++) {
  29.  
    Map< String, Object> valMap = new HashMap< String, Object>();
  30.  
    valMap.put( "title", "名称." + i);
  31.  
    valMap.put( "supplier", "供应商." + i);
  32.  
     
  33.  
    List< Map< String, Object>> deliDetailList = new ArrayList< Map< String, Object>>();
  34.  
    for (int j = 0; j < 3; j++) {
  35.  
    Map< String, Object> deliValMap = new HashMap< String, Object>();
  36.  
    deliValMap.put( "orgPrice", "得力.市场价." + j);
  37.  
    deliValMap.put( "salePrice", "得力.专区价." + j);
  38.  
    deliDetailList.add(deliValMap);
  39.  
    }
  40.  
    valMap.put( "deli", deliDetailList);
  41.  
     
  42.  
    List< Map< String, Object>> jdDetailList = new ArrayList< Map< String, Object>>();
  43.  
    for (int j = 0; j < 2; j++) {
  44.  
    Map< String, Object> jdValMap = new HashMap< String, Object>();
  45.  
    jdValMap.put( "orgPrice", "京东.市场价." + j);
  46.  
    jdValMap.put( "salePrice", "京东.专区价." + j);
  47.  
    jdDetailList.add(jdValMap);
  48.  
    }
  49.  
    valMap.put( "jd", jdDetailList);
  50.  
     
  51.  
    list.add(valMap);
  52.  
    }
  53.  
     
  54.  
    Workbook workbook = ExcelExportUtil.exportExcel( new ExportParams( "价格分析表", "数据"), colList,
  55.  
    list);
  56.  
    FileOutputStream fos = new FileOutputStream( "D:/价格分析表.tt.xls");
  57.  
    workbook.write(fos);
  58.  
    fos.close();
  59.  
    } catch (FileNotFoundException e) {
  60.  
    e.printStackTrace();
  61.  
    } catch (IOException e) {
  62.  
    e.printStackTrace();
  63.  
    }
  64.  
    }
 

导出结果图ide

相关文章
相关标签/搜索