依据map生成多个sheet求助
仿照着test,自己写了个依据map生成多个sheet的测试类,生成的文件打不开
@Test public void testsheet() { try { List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>(); ExcelExportEntity excelentity = new ExcelExportEntity("姓名", "name"); excelentity.setNeedMerge(true); entity.add(excelentity); entity.add(new ExcelExportEntity("性别", "sex")); excelentity = new ExcelExportEntity(null, "students"); List<ExcelExportEntity> temp = new ArrayList<ExcelExportEntity>(); temp.add(new ExcelExportEntity("姓名", "name")); temp.add(new ExcelExportEntity("性别", "sex")); excelentity.setList(temp); entity.add(excelentity); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map; for (int i = 0; i < 10; i++) { map = new HashMap<String, Object>(); map.put("name", "1" + i); map.put("sex", "2" + i); List<Map<String, Object>> tempList = new ArrayList<Map<String, Object>>(); tempList.add(map); tempList.add(map); map.put("students", tempList); list.add(map); } List<Map<String, Object>> slist = new ArrayList<Map<String, Object>>(); Map<String, Object> smap = new HashMap<String, Object>(); ExportParams params = new ExportParams("测试一", "sheet"); smap.put("title", params); smap.put("entity", entity); smap.put("data", list); for (int i = 0; i < 3; i++) { slist.add(smap); } // Workbook workbook2 = ExcelExportUtil.exportExcel(list,"XSSF"); Workbook workbook2= ExcelExportUtil.exportExcel(list,"HSSF"); FileOutputStream fos = new FileOutputStream("d:/tt.xls"); workbook2.write(fos); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
知识水平有限,该如何修改?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
例子弱爆了,没什么参考价值!作者要真想推广使用,要在示例和文档上下点功夫!
你可以看看demo不