| | |
| | | package com.zy.common.web; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.zy.common.utils.excel.EnInitData; |
| | | import com.zy.common.utils.excel.matcode.MatCodeExcelListener; |
| | | import com.zy.common.utils.excel.ExcelUtils; |
| | | import com.core.common.R; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import com.zy.common.utils.excel.ExcelUtils; |
| | | import com.zy.common.utils.excel.matcode.MatCodeExcel; |
| | | import com.zy.common.utils.excel.matcode.MatCodeExcelListener; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | * todo |
| | | * Created by vincent on 2019-11-25 |
| | | */ |
| | | @Controller |
| | | @RestController |
| | | @RequestMapping("excel/") |
| | | public class FileController { |
| | | |
| | |
| | | @PostMapping("upload") |
| | | @ResponseBody |
| | | public R upload(MultipartFile file) throws IOException { |
| | | EasyExcel.read(file.getInputStream(), EnInitData.class, new MatCodeExcelListener()).sheet().doRead(); |
| | | EasyExcel.read(file.getInputStream(), MatCodeExcel.class, new MatCodeExcelListener()).sheet().doRead(); |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("测试", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), EnInitData.class).sheet("模板").doWrite(ExcelUtils.data()); |
| | | EasyExcel.write(response.getOutputStream(), MatCodeExcel.class).sheet("模板").doWrite(ExcelUtils.data()); |
| | | } |
| | | |
| | | } |