SpringBoot 通过File将Workbook生成的Excel文件下载到项目中

ExportParams exportParams = new ExportParams("错误集合", "错误集合", ExcelType.XSSF);
            Workbook workbook = ExcelExportUtil.exportExcel(exportParams, Invite.class, errorItems);

            /**
             * 写入到本地文件
             * Springboot获取文件路径
             * https://blog.csdn.net/qq_20282955/article/details/89856223
             */
            File outputFile = new File(ResourceUtils.getURL("classpath:").getPath());
            if (!outputFile.exists())
                outputFile = new File("");
            File upload = new File(outputFile.getAbsolutePath(), "download/");
            if (!upload.exists())
                upload.mkdirs();
            FileOutputStream fos = new FileOutputStream(outputFile);
            logger.error("getAbsolutePath=========>{}",outputFile.getAbsolutePath());
            workbook.write(fos);// 写文件

猜你喜欢

转载自www.cnblogs.com/slAmor/p/12969477.html