日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

进入指定url就可下载xlsx文件

發布時間:2023/12/13 综合教程 43 生活家
生活随笔 收集整理的這篇文章主要介紹了 进入指定url就可下载xlsx文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

GuestApplyService.java


//
private final static int PERSONAL_NAME_INDEX = 0;
private final static int USER_NAME_INDEX = 1;
private final static int COMPANY_NAME_INDEX = 2;
private final static int LOGIN_NAME_INDEX = 3;
private final static int APPLY_DAYS_INDEX = 4;
private final static int TELEPHONE_INDEX = 5;
private final static int APPLY_REASON_INDEX = 6;
private final static int APPLY_TIME_INDEX = 7;
//


//導出 @Transactional public void exportListApplications(TenantId tenantId, String templatePath, OutputStream os) throws IOException { DataPage<GuestApplication> applications = this.guestApplicationRepository.getByTenantId(tenantId, 0, Integer.MAX_VALUE); List<GuestApplicationDTO> dtos = new ArrayList<GuestApplicationDTO>(); for (GuestApplication guestApplication : applications.getData()) { dtos.add(GuestApplicationDTO.fromGuestApplication(guestApplication)); } String tempPath = FileUtils.getTempDirectoryPath(); File excelFile = new File(tempPath + "\" + generateFileName() + ".xlsx"); File templateFile = new File(templatePath); FileUtils.copyFile(templateFile, excelFile); XSSFWorkbook wb; try (OPCPackage opk = OPCPackage.open(excelFile)) { wb = new XSSFWorkbook(opk); XSSFSheet sheet = wb.getSheetAt(0); int maxRowNum = sheet.getLastRowNum(); XSSFRow row = null; GuestApplicationDTO guestApp = null; for (int i = 3; i < maxRowNum; i++) { row = sheet.getRow(i); if (row != null) { sheet.removeRow(row); } } for (int i = 3; i < dtos.size() + 3; i++) { row = sheet.createRow(i); guestApp = dtos.get(i - 3); if (guestApp == null) { continue; }

row.createCell(PERSONAL_NAME_INDEX, Cell.CELL_TYPE_STRING).setCellValue(guestApp.getPersonalName());
row.createCell(LOGIN_NAME_INDEX, Cell.CELL_TYPE_STRING).setCellValue(guestApp.getLoginName());
row.createCell(COMPANY_NAME_INDEX, Cell.CELL_TYPE_STRING).setCellValue(guestApp.getCompanyName());
row.createCell(USER_NAME_INDEX, Cell.CELL_TYPE_STRING).setCellValue(guestApp.getUserName());
row.createCell(APPLY_DAYS_INDEX, Cell.CELL_TYPE_STRING).setCellValue(guestApp.getApplyDays());
row.createCell(TELEPHONE_INDEX, Cell.CELL_TYPE_STRING).setCellValue(guestApp.getTelephone());
row.createCell(APPLY_REASON_INDEX, Cell.CELL_TYPE_STRING).setCellValue(guestApp.getApplyReason());
row.createCell(APPLY_TIME_INDEX, Cell.CELL_TYPE_STRING).setCellValue(guestApp.getApplyTime());

            }
            wb.write(os);
        } catch (InvalidFormatException ex) {
            throw new DkRuntimeException(ex);
        } finally {
            FileUtils.forceDelete(excelFile);
        }
    }

GuestController.java

 @RequestMapping(value = "/guest/export")
    public void exportGuest(HttpServletRequest request, HttpServletResponse response) {
        OutputStream os = null;
        String fileName = "guest_application_template.xlsx";
        try {
            response.reset();
            response.setContentType("application/octet-stream;charset=UTF-8");
            os = response.getOutputStream();
            String fileAbsolutePath = request.getSession().getServletContext()
                    .getRealPath("/")
                    + "page/resources/" + fileName;
            guestApplyApplicationService.exportListApplications(new TenantId(CurrentTenant.getInstance(request).getTenant().getId()), fileAbsolutePath, os);

        } catch (IOException e) {
            _logger.error(e.getMessage(), e);
        } finally {
            IOUtils.closeQuietly(os);
        }
    }

url:http://localhost:8080/am/controller/tenant/guest/export

guest_application_template.xlsx

總結

以上是生活随笔為你收集整理的进入指定url就可下载xlsx文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。