SpringBoot+easypoi實(shí)現(xiàn)數(shù)據(jù)的Excel導(dǎo)出
本文實(shí)例為大家分享了SpringBoot+easypoi實(shí)現(xiàn)數(shù)據(jù)的Excel導(dǎo)出的具體代碼,供大家參考,具體內(nèi)容如下
maven
<dependency> <groupId>cn.afterturn</groupId> <artifactId>easypoi-spring-boot-starter</artifactId> <version>4.1.0</version></dependency>
Controller層
// 接口不需要返回值@RequestMapping(value = '/export-activity-data')public void exportActivityData(@RequestParam String activityType, @RequestParam String activityState, @RequestParam String queryValue, @RequestParam String levelValue, @RequestParam String startTime, @RequestParam String endTime, HttpServletResponse response) {try { manageService.exportActivityData(TFActivityQueryParam.builder() .activityState(activityState) .activityType(activityType) .queryValue(queryValue) .levelValue(levelValue) .startTime(''.equals(endTime) ? null : new Date(DateTime.parse(startTime).getMillis())) .endTime(''.equals(endTime) ? null : new Date(DateTime.parse(endTime).getMillis())).build(), response);} catch (IOException e) { log.info( '導(dǎo)出失敗', e);} }
service層
public void exportActivityData(TFActivityQueryParam param, HttpServletResponse response) throws IOException {response.setCharacterEncoding('UTF-8');response.setHeader('content-Type', 'application/vnd.ms-excel');response.setHeader('Content-Disposition','attachment;filename=' + URLEncoder.encode('活動(dòng)綜合數(shù)據(jù).xls', 'UTF-8'));val out = response.getOutputStream();List<TFActivityQueryResult> tfActivityList = getTFActivityList(param);List<TFActivityQueryResultExportDto> exportDtoList = new ArrayList<>();tfActivityList.forEach(activity -> { TFActivityQueryResultExportDto convert = TFActivityQueryResultExportDto.convert(activity); if (activity.getLevelType().equals('0')) {convert.setAffiliation('云南省'); } else {EparchyCode eparchyCode = getEparchyCodeList().stream().filter(code -> code.getEparchyCode().equals(activity.getEparchyCode())).collect(Collectors.toList()).get(0);convert.setAffiliation(eparchyCode.getEparchyShortName()); } exportDtoList.add(convert);});Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams('活動(dòng)綜合數(shù)據(jù)', '活動(dòng)'), TFActivityQueryResultExportDto.class, exportDtoList);log.info('workbook: {}', workbook);workbook.write(out);out.close(); }
數(shù)據(jù)bean
public class TFActivityQueryResultExportDto { @Excel(name = '活動(dòng)編碼', width = 20) private String activityCode; @Excel(name = '活動(dòng)名稱', width = 20) private String activityName; @Excel(name = '活動(dòng)標(biāo)題', width = 20) private String activityTitle; @Excel(name = '歸屬', width = 20) private String affiliation; @Excel(name = '活動(dòng)類(lèi)型', width = 20) private String activityType; @Excel(name = '活動(dòng)時(shí)間', width = 30) private String activityTime; @Excel(name = '活動(dòng)狀態(tài)', width = 20) private String activityState; @Excel(name = '備注', width = 30) private String remark; @Excel(name = '創(chuàng)建時(shí)間', width = 30) private String timeCreate; @Excel(name = '最新操作人', width = 30) private String operatorName; @Excel(name = '更新時(shí)間', width = 30) private String timeUpdate;}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 京東如何開(kāi)啟收到消息震動(dòng)提醒功能呢2. 優(yōu)酷怎么共享vip給別人3. 哈羅單車(chē)鎖不上怎么辦,更加詳細(xì)解決辦法!4. 京東網(wǎng)約車(chē)開(kāi)通了哪些城市?上線城市匯總介紹5. 微信拍視頻如何放大畫(huà)面6. 閑魚(yú)如何設(shè)置開(kāi)啟服務(wù)號(hào)通知7. 為什么抖音新出的表情我都沒(méi)有8. 天貓魔盒老是重啟怎么辦9. 網(wǎng)易云音樂(lè)APP設(shè)置同時(shí)顯示中英文歌詞操作步驟10. 抖音怎么知道自己是不是被封號(hào)了?被封號(hào)了怎么申訴恢復(fù)?
