vue excel导入,导出
@GetMapping("/exportExample")
@Inner(false)
//public R exportExample(Integer cs,String cs2){
public void exportExample(MeterWater meterWater, HttpServletResponse response) throws IOException {
//查询所有用户
Map<String, Object> row1 = new LinkedHashMap<>();
row1.put("username", "张三");
row1.put("password", 23);
row1.put("nickname", 88.32);
row1.put("email", true);
Map<String, Object> row2 = new LinkedHashMap<>();
row2.put("username", "李四");
row2.put("password", 33);
row2.put("nickname", 59.50);
row2.put("email", false);
ArrayList<Map<String, Object>> rows = CollUtil.newArrayList(row1, row2);
ExcelWriter writer = ExcelUtil.getWriter(true);
//自定义标题别名
writer.addHeaderAlias("username", "姓名");
writer.addHeaderAlias("password", "年龄");
writer.addHeaderAlias("nickname", "成绩");
writer.addHeaderAlias("email", "是否合格");
//只导出标题别名
writer.setOnlyAlias(true);
//默认配置
writer.write(rows, true);
//设置content—type
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset:utf-8");
//设置标题
String fileName = URLEncoder.encode("用户信息", "UTF-8");
//Content-disposition是MIME协议的扩展,MIME协议指示MIME用户代理如何显示附加的文件。
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
ServletOutputStream outputStream = response.getOutputStream();
//将Writer刷新到OutPut
writer.flush(outputStream, true);
outputStream.close();
}
导入
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.10</version>
</dependency>
@PostMapping("/importWaterInfo")
public R importCustomerInfo(@RequestBody Map<String, Object> map, BindingResult bindingResult) {
JSONArray headerKey = JSONUtil.parseArray(map.get("header").toString());
JSONArray jContent = JSONUtil.parseArray(map.get("results").toString());
List<Map> lstMap = JSONUtil.toList(jContent, Map.class);
int iIndex = 1;
for(Map<String,Object> mp: lstMap){
String sName = mp.get("姓名").toString();
iIndex ++;
}
String sSql = "";
return R.ok();
//return customerInfoService.importCustomerInfo(voList, bindingResult);
}
择善人而交,择善书而读,择善言而听,择善行而从。