下载,上传excel
ClassPathResource resource = new ClassPathResource("template/企业信息模板.xlsx");
String path = resource.getURL().getPath();
path = URLDecoder.decode(path, "UTF-8");
File file = new File(path);
Workbook workbook = new XSSFWorkbook(file);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/octet-stream;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
workbook.write(response.getOutputStream());
@GetMapping("download")
public void download(HttpServletResponse response) throws IOException {
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
EasyExcel.write(response.getOutputStream(), xx.class).sheet("模板").doWrite(List);
}
@PostMapping("upload")
@ResponseBody
public String upload(MultipartFile file) throws IOException {
EasyExcel.read(file.getInputStream(), DemoData.class, new DemoDataListener()).sheet().doRead();
return "success";
}
读取数据
InputStream inputStream = multipartFile.getInputStream();
List<ExcelImportTktEntInfoVo> list = EasyExcel.read(inputStream).head(ExcelImportTktEntInfoVo.class).sheet().doReadSync();
注解
@ColumnWidth(30)
public class ExcelExportTktInfoVo {
@ExcelIgnore
private String esopEnterpriseId;
@ExcelProperty("地市")
private String busiRegCityName;
}