技术前沿网
技术前沿网 找到你想要的开源项目,分享和交流
打开

依据map生成多个sheet求助

2

仿照着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();
		}
	}

知识水平有限,该如何修改?


我来回答
精彩回答
你可以看看demo不
例子弱爆了,没什么参考价值!作者要真想推广使用,要在示例和文档上下点功夫!
×