使用freemarker导出EXCEL WPS可以打开EXCEL2016打不开问题解决

导出代码如下:
public void freeMarkerDownTest(HttpServletResponse response, HttpServletRequest request)
			throws UnsupportedEncodingException {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = null;
		for (int i = 1; i < 10; i++) {
			map = new HashMap<String, Object>();
			map.put("dx", i);
			map.put("class", i + "班");
			map.put("d1", i + "1%");
			map.put("d2", i + "2%");
			map.put("d3", i + "3%");
			map.put("d4", i + "4%");
			map.put("d5", i + "5%");
			map.put("d6", i + "6%");
			map.put("d7", i + "7%");
			map.put("d8", i + "8%");
			list.add(map);
		}
		Map<String, Object> testMap = new HashMap<String, Object>();
		testMap.put("datas", list);
		Configuration configuration = new Configuration();
		FreeMarkerUtil handler = new FreeMarkerUtil(configuration);
		response.setContentType("application/octet-stream;charset=utf-8");
		String fileName = FileControl.encodeFileName(request, "2017-10-23 -学校考勤报表.xls");
		response.setHeader("Content-Disposition", "attachment;" + fileName);
		try {
			String templatePath = "E:/zlsu/Document/marking/framktodoc/";
			handler.write(templatePath, "freemark测试1.xml", testMap, response.getWriter());
			System.out.println("导出成功!");
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
 

导出完用WPS 打开正常 用EXCEL2016 打开出现文件错误如下:

解决方法:

 用OpenOffice.org 3.4.1 打开EXCEL 文件 然后把它 用Oppenoffice 另存为XML, 然后插入对应的 freemarker 指令 把这个 xml文件作为 导出的模板, 导出的excel 就能用

EXCEL2016 打开了如下图:

  

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值