1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| //excel表录入添加数据 @PostMapping("/excelData") public DataResult addBidDataFromExcel (MultipartFile file) { bidExcelService.addSubject(file, bidExcelService); return DataResult.success(); }
/** * 文件下载(失败了会返回一个有部分数据的Excel) * <p> * 1. 创建excel对应的实体对象 参照{} * <p> * 2. 设置返回的 参数 * <p> * 3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大 */ @GetMapping("/download") public void download(HttpServletResponse response) throws IOException { // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 String fileName = URLEncoder.encode("中标系统导出数据", "UTF-8").replaceAll("\\+", "%20"); response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); List<BidInfor> bidInforList = bidExcelService.list( Wrappers.<BidInfor>lambdaQuery().orderByDesc(BidInfor::getBidDate).select(BidInfor::getIndustry, BidInfor::getBidDate, BidInfor::getProvince, BidInfor::getProjectName, BidInfor::getPurchaseWay,BidInfor::getPurchaseCompany, BidInfor::getDataSource, BidInfor::getBidCompany, BidInfor::getAmount, BidInfor::getNote, BidInfor::getBusinessLabel, BidInfor::getTechnologyLabel, BidInfor::getCustomerLevel)); List<DownloadDataVo> downloadDataVoList = new LinkedList<>(); for (BidInfor bidInfor : bidInforList) { downloadDataVoList.add(new DownloadDataVo(bidInfor.getIndustry(), bidInfor.getBidDate(), bidInfor.getProvince(), bidInfor.getProjectName(), bidInfor.getPurchaseWay(), bidInfor.getPurchaseCompany(), bidInfor.getDataSource(), bidInfor.getBidCompany(), bidInfor.getAmount(), bidInfor.getNote(), bidInfor.getBusinessLabel(), bidInfor.getTechnologyLabel(), bidInfor.getCustomerLevel())); } EasyExcel.write(response.getOutputStream(), DownloadDataVo.class).sheet("中标系统导出数据").doWrite(downloadDataVoList); }
|
This is copyright.