1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| @Test public void dynaCol() { try { List<ExcelExportEntity> colList = new ArrayList<ExcelExportEntity>(); ExcelExportEntity colEntity = new ExcelExportEntity("商品名称", "title"); colEntity.setNeedMerge(true); colList.add(colEntity);
colEntity = new ExcelExportEntity("供应商", "supplier"); colEntity.setNeedMerge(true); colList.add(colEntity);
ExcelExportEntity deliColGroup = new ExcelExportEntity("得力", "deli"); List<ExcelExportEntity> deliColList = new ArrayList<ExcelExportEntity>(); deliColList.add(new ExcelExportEntity("市场价", "orgPrice")); deliColList.add(new ExcelExportEntity("专区价", "salePrice")); deliColGroup.setList(deliColList); colList.add(deliColGroup);
ExcelExportEntity jdColGroup = new ExcelExportEntity("京东", "jd"); List<ExcelExportEntity> jdColList = new ArrayList<ExcelExportEntity>(); jdColList.add(new ExcelExportEntity("市场价", "orgPrice")); jdColList.add(new ExcelExportEntity("专区价", "salePrice")); jdColGroup.setList(jdColList); colList.add(jdColGroup);
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); for (int i = 0; i < 10; i++) { Map<String, Object> valMap = new HashMap<String, Object>(); valMap.put("title", "名称." + i); valMap.put("supplier", "供应商." + i);
List<Map<String, Object>> deliDetailList = new ArrayList<Map<String, Object>>(); for (int j = 0; j < 3; j++) { Map<String, Object> deliValMap = new HashMap<String, Object>(); deliValMap.put("orgPrice", "得力.市场价." + j); deliValMap.put("salePrice", "得力.专区价." + j); deliDetailList.add(deliValMap); } valMap.put("deli", deliDetailList);
List<Map<String, Object>> jdDetailList = new ArrayList<Map<String, Object>>(); for (int j = 0; j < 2; j++) { Map<String, Object> jdValMap = new HashMap<String, Object>(); jdValMap.put("orgPrice", "京东.市场价." + j); jdValMap.put("salePrice", "京东.专区价." + j); jdDetailList.add(jdValMap); } valMap.put("jd", jdDetailList);
list.add(valMap); }
Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("价格分析表", "数据"), colList, list); FileOutputStream fos = new FileOutputStream("D:/价格分析表.tt.xls"); workbook.write(fos); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
}
|