| | |
| | | import org.sxkj.fw.record.service.IFwDroneFlightRecordService; |
| | | import org.sxkj.fw.record.vo.FwDroneFlightRecordVO; |
| | | import org.sxkj.fw.record.wrapper.FwDroneFlightRecordWrapper; |
| | | import org.sxkj.fw.utils.JaExcelUtil; |
| | | import springfox.documentation.annotations.ApiIgnore; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | @ApiOperation(value = "导出数据", notes = "传入fwDroneFlightRecord") |
| | | public void exportFwDroneFlightRecord(FwDroneFlightRecordExportParam fwDroneFlightRecord, HttpServletResponse response) throws IOException { |
| | | Map<String,List<FwDroneFlightRecordExcel>> list = fwDroneFlightRecordService.exportFwDroneFlightRecord(fwDroneFlightRecord); |
| | | exportMultipleSheets(response, "无人机飞行记录表数据" + DateUtil.time(), list, FwDroneFlightRecordExcel.class); |
| | | JaExcelUtil.exportMultipleSheets(response, "无人机飞行记录表数据" + DateUtil.time(), list, FwDroneFlightRecordExcel.class); |
| | | } |
| | | |
| | | // ... existing code ... |
| | | |
| | | /** |
| | | * 导出多个sheet到Excel文件 |
| | | * @param response HTTP响应对象 |
| | | * @param fileName 文件名 |
| | | * @param sheetDataMap 包含sheet名称和对应数据列表的映射 |
| | | * @param clazz 数据类型对应的类 |
| | | */ |
| | | public static <T> void exportMultipleSheets(HttpServletResponse response, String fileName, |
| | | java.util.Map<String, List<T>> sheetDataMap, Class<T> clazz) throws IOException { |
| | | try { |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding(StandardCharsets.UTF_8.name()); |
| | | fileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.name()); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | |
| | | ExcelWriter excelWriter = null; |
| | | try { |
| | | excelWriter = EasyExcel.write(response.getOutputStream(), clazz).build(); |
| | | int sheetIndex = 0; |
| | | for (java.util.Map.Entry<String, List<T>> entry : sheetDataMap.entrySet()) { |
| | | String sheetName = entry.getKey(); |
| | | List<T> dataList = entry.getValue(); |
| | | if (dataList != null && !dataList.isEmpty()) { |
| | | com.alibaba.excel.write.metadata.WriteSheet writeSheet = EasyExcel.writerSheet(sheetIndex++, sheetName).build(); |
| | | excelWriter.write(dataList, writeSheet); |
| | | } |
| | | } |
| | | } finally { |
| | | if (excelWriter != null) { |
| | | excelWriter.finish(); |
| | | } |
| | | } |
| | | } catch (Throwable $ex) { |
| | | throw $ex; |
| | | } |
| | | } |
| | | |
| | | |
| | | |