| | |
| | | public void exportDpt(HttpServletResponse response) { |
| | | List<UmsDepartDto> umsDepartDtos = departService.departExp(); |
| | | String sheetName = "部门导出"; |
| | | EasyExcelUtils.export(response, sheetName, UmsDepartDto.class, umsDepartDtos); |
| | | EasyExcelUtils.export1(response, sheetName, UmsDepartDto.class, umsDepartDtos, "部门导出"); |
| | | } |
| | | |
| | | @Resource |
| | |
| | | public void exportUser(HttpServletResponse response) { |
| | | List<UmsUserDto1> umsUserDtos = adminService.userExp(); |
| | | String sheetName = "用户导出"; |
| | | EasyExcelUtils.export(response, sheetName, UmsUserDto1.class, umsUserDtos); |
| | | EasyExcelUtils.export1(response, sheetName, UmsUserDto1.class, umsUserDtos, "用户导出"); |
| | | } |
| | | |
| | | @Resource |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Collection; |
| | |
| | | } |
| | | |
| | | @SneakyThrows |
| | | public static void export1(HttpServletResponse response, String sheetName, Class className, Collection<?> collection, String fileName) { |
| | | fileName = URLEncoder.encode(fileName, "UTF-8"); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), className) |
| | | .sheet(sheetName) |
| | | .doWrite(collection); |
| | | } |
| | | |
| | | @SneakyThrows |
| | | public static void importDepartFile(MultipartFile file) throws IOException { |
| | | EasyExcel.read(file.getInputStream()) |
| | | .head(UmsDepartDto.class) |