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

相關文章
相關標籤/搜索