Browse Source

结算单-bytedance

yangzian 3 years ago
parent
commit
f52daa69ca

+ 242 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/controller/DemoReportController.java

@@ -0,0 +1,242 @@
+package org.jeecg.ctop.finance.settlement.controller;
+
+import cn.afterturn.easypoi.cache.manager.POICacheManager;
+import cn.afterturn.easypoi.entity.ImageEntity;
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
+import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportBytedanceVo;
+import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
+import org.jeecg.ctop.finance.settlement.service.serviceImpl.FileLoaderImpl;
+import org.jeecg.ctop.finance.utils.SettlementUtil;
+import org.jeecg.ctop.finance.utils.createExcelByTemplate;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+/**
+ * 导出 结算单 利润表
+ * Administrator
+ * 2021/7/28
+ **/
+
+@Slf4j
+@RestController
+@RequestMapping("/finance/exportReportDemoController")
+public class DemoReportController {
+
+    @Autowired
+    private IReportSettlementService reportSettlementService;
+
+    @ApiOperation(value="财务结算-结算单导出", notes="财务结算-结算单导出")
+    @GetMapping(value = "/exportSettlementReport")
+    public Result exportSettlementReport(HttpServletResponse response) {
+
+       // byte[] img = SettlementUtil.getByteImgByUrl("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg");
+
+        List<SettlementReportBytedanceVo> list = reportSettlementService.getAccountTransactionDayBytedance();
+
+
+
+        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("这是表头", "这是sheet名称"), SettlementReportBytedanceVo.class, list);
+
+
+        try {
+            response.setCharacterEncoding("UTF-8");
+            response.setHeader("content-Type", "application/vnd.ms-excel");
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("文件名称.xlsx", "UTF-8"));
+            workbook.write(response.getOutputStream());
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+
+       return null;
+    }
+
+
+
+    @ApiOperation(value="财务结算-模板结算单导出", notes="财务结算-模板结算单导出")
+    @GetMapping(value = "/exportImg")
+    public String exportImg(HttpServletResponse response) throws Exception {
+
+       // byte[] img = SettlementUtil.getByteImgByUrl("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg");
+
+        TemplateExportParams params = new TemplateExportParams("C://Users//Administrator//Desktop//bytedance.xlsx",true);
+       // params.setSheetName("这是sheet名称");
+        params.setSheetName(new String[]{"这是sheet名称1","这是sheet名称2"});
+
+        // 重要代码
+        //POICacheManager.setFileLoader(new FileLoaderImpl());
+        POICacheManager.setFileLoder(new FileLoaderImpl());
+
+        Map<String, Object> map = new HashMap<String, Object>();
+        List<SettlementReportBytedanceVo> list = reportSettlementService.getAccountTransactionDayBytedance();
+        List<Map<String, Object>> pictureList = new ArrayList<Map<String, Object>>() ;
+
+        Map<String,Object> picture1 = new HashMap<String, Object>();
+        Map<String,Object> picture2 = new HashMap<String, Object>();
+       byte[] datas =  SettlementUtil.getByteImgByUrl("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg");
+        ImageEntity img = new ImageEntity();
+        img.setUrl("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg");
+        //img.setUrl("C:\\Users\\Administrator\\Desktop\\汇创\\20210507161223.jpg");
+        img.setHeight(1000);
+        img.setWidth(500);
+        picture1.put("imag", img);
+        picture2.put("imag", img);
+        pictureList.add(picture1);
+        pictureList.add(picture2);
+
+        Map<String, Object> resultMap = new HashMap<>();
+        resultMap.put("l",list);
+        resultMap.put("p",pictureList);
+
+        try {
+            Workbook workbook = ExcelExportUtil.exportExcel(params, resultMap);
+            response.setCharacterEncoding("UTF-8");
+            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+            response.setHeader("Pragma", "no-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            response.setDateHeader("Expires", 0);
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("文件名称.xlsx", "UTF-8"));
+            OutputStream output = response.getOutputStream();
+            BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
+            workbook.write(bufferedOutPut);
+            bufferedOutPut.flush();
+            bufferedOutPut.close();
+            output.close();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+
+       return "123";
+    }
+
+
+    @ApiOperation(value="财务结算-结算单导出", notes="财务结算-结算单导出")
+    @GetMapping(value = "/demo")
+    public String demo(HttpServletResponse response) throws Exception {
+        //第一步创建workbook
+        HSSFWorkbook wb = new HSSFWorkbook();
+
+        HSSFCellStyle style = wb.createCellStyle();
+        style.setAlignment(HorizontalAlignment.CENTER);//水平居中
+
+        HSSFFont font = wb.createFont();
+        font.setFontName("黑体");
+        font.setFontHeightInPoints((short) 12);//设置字体大小
+        style.setFont(font);
+
+        //第二步创建sheet
+        HSSFSheet sheet = wb.createSheet("账户id");
+
+        sheet.autoSizeColumn(1,true);
+
+        HSSFRow row1 = sheet.createRow(0);
+        HSSFCell cell1 = row1.createCell(0);     //第一个单元格
+        cell1.setCellValue("头条");         //设定值
+        CellRangeAddress region = new CellRangeAddress(0, 0, 0, 1);
+        sheet.addMergedRegion(region);
+        cell1.setCellStyle(style);
+
+        //第三步创建行row:添加表头0行
+        HSSFRow row = sheet.createRow(1);
+
+        //第四步创建单元格
+        HSSFCell cell = row.createCell(0);     //第一个单元格
+        cell.setCellValue("测试1");         //设定值
+        cell.setCellStyle(style);          //内容居中
+
+        cell = row.createCell(1);          //第二个单元格
+        cell.setCellValue("测试2");
+        cell.setCellStyle(style);
+
+        List<SettlementReportBytedanceVo> list = reportSettlementService.getAccountTransactionDayBytedance();
+        for (int i = 0; i < list.size(); i++) {
+            SettlementReportBytedanceVo vo = list.get(i);
+            //创建行
+            row = sheet.createRow(i+2);
+            row.setRowStyle(style);
+            //创建单元格并且添加数据
+            row.createCell(0).setCellValue(vo.getAdvertiserId());
+            row.createCell(1).setCellValue(vo.getDate());
+        }
+
+        FileOutputStream fileOut = null;
+        BufferedImage bufferImg = null;
+
+        //先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
+        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
+        //bufferImg = ImageIO.read(new File("C:\\Users\\Administrator\\Desktop\\汇创\\20210507161223.jpg"));
+        //bufferImg = ImageIO.read(new File(URLDecoder.decode("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg","utf-8")));
+        String imagePath = "https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg";
+        //InputStream is = new FileInputStream(imagePath);
+        InputStream is = createExcelByTemplate.getInputStreamByUrl(imagePath);
+        bufferImg = ImageIO.read(is);
+
+        ImageIO.write(bufferImg, imagePath.substring(imagePath.lastIndexOf(".")+1), byteArrayOut);
+
+        //画图的顶级管理器,一个sheet只能获取一个
+        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
+        //anchor主要用于设置图片的属性
+        //HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255,(short) 1, 1, (short) 5, 8);
+        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255,(short) 5, list.size()+6, (short) 10, 40);
+        HSSFClientAnchor anchor2 = new HSSFClientAnchor(0, 0, 255, 255,(short) 5, list.size()+40, (short) 10, 40*2);
+        anchor.setAnchorType(3);
+        //插入图片
+        patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
+        patriarch.createPicture(anchor2, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
+
+
+        response.setCharacterEncoding("UTF-8");
+        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+        response.setHeader("Pragma", "no-cache");
+        response.setHeader("Cache-Control", "no-cache");
+        response.setDateHeader("Expires", 0);
+        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("文件名称.xlsx", "UTF-8"));
+        OutputStream output = response.getOutputStream();
+        BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
+        wb.write(bufferedOutPut);
+        bufferedOutPut.flush();
+        bufferedOutPut.close();
+        output.close();
+       return "123";
+    }
+
+
+    public static void main(String[] args) throws Exception {
+        File file1 = new File("C:\\Users\\Administrator\\Desktop\\汇创\\20210507161223.jpg");
+        File file2 = new File("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg");
+        System.out.println(file1.exists());
+        System.out.println(file2.exists());
+
+        //BufferedImage bufferImg = ImageIO.read(new File("media-1301855440\\u002Ecos\\u002Eap-chongqing\\u002Emyqcloud\\u002Ecom/image/2021-08-05/2-1628129040416.jpg"));
+       //String imagePath = "https:\\/\\/media-1301855440.cos.ap-chongqing.myqcloud.com"+File.separator+"image"+File.separator+"2021-08-05"+File.separator+"2-1628129040416.jpg";
+        String imagePath = "https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg";
+        System.out.println(imagePath);
+        //InputStream is = new FileInputStream(imagePath);
+        InputStream is = createExcelByTemplate.getInputStreamByUrl(imagePath);
+        System.out.println(is);
+
+    }
+
+}

+ 146 - 81
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/controller/ExportReportController.java

@@ -1,32 +1,23 @@
 package org.jeecg.ctop.finance.settlement.controller;
 
-import cn.afterturn.easypoi.cache.manager.POICacheManager;
-import cn.afterturn.easypoi.entity.ImageEntity;
-import cn.afterturn.easypoi.excel.ExcelExportUtil;
-import cn.afterturn.easypoi.excel.entity.ExportParams;
-import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.jeecg.common.api.vo.Result;
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.usermodel.ClientAnchor;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.util.CellRangeAddress;
 import org.jeecg.ctop.finance.settlement.entity.vo.SettlementReportBytedanceVo;
 import org.jeecg.ctop.finance.settlement.service.IReportSettlementService;
-import org.jeecg.ctop.finance.settlement.service.serviceImpl.FileLoaderImpl;
-import org.jeecg.ctop.finance.utils.SettlementUtil;
+import org.jeecg.ctop.finance.utils.createExcelByTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
-import java.awt.*;
-import java.io.BufferedOutputStream;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.OutputStream;
+import java.awt.image.BufferedImage;
+import java.io.*;
 import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 
 /**
@@ -43,91 +34,165 @@ public class ExportReportController {
     @Autowired
     private IReportSettlementService reportSettlementService;
 
+
+
     @ApiOperation(value="财务结算-结算单导出", notes="财务结算-结算单导出")
-    @GetMapping(value = "/exportSettlementReport")
-    public Result exportSettlementReport(HttpServletResponse response) {
+    @GetMapping(value = "/settlementReportBytedance")
+    public String settlementReportBytedance(HttpServletResponse response) throws Exception {
+        //第一步创建workbook
+        HSSFWorkbook wb = new HSSFWorkbook();
 
-       // byte[] img = SettlementUtil.getByteImgByUrl("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg");
+        //设置样式
+        HSSFCellStyle style = wb.createCellStyle();
+        style.setAlignment(HorizontalAlignment.CENTER);//水平居中
 
-        List<SettlementReportBytedanceVo> list = reportSettlementService.getAccountTransactionDayBytedance();
+        //设置字体
+        HSSFFont font = wb.createFont();
+        font.setFontName("黑体");
+        font.setFontHeightInPoints((short) 12);//设置字体大小
+        style.setFont(font);
 
 
 
-        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("这是表头", "这是sheet名称"), SettlementReportBytedanceVo.class, list);
+        for (int j = 0; j< 2;j++){
 
 
-        try {
-            response.setCharacterEncoding("UTF-8");
-            response.setHeader("content-Type", "application/vnd.ms-excel");
-            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("文件名称.xlsx", "UTF-8"));
-            workbook.write(response.getOutputStream());
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
 
 
-       return null;
-    }
+        //2:创建sheet
+        HSSFSheet sheet = wb.createSheet("账户id"+j);
 
 
+        //3:添加 第一行单元格
+        HSSFRow row0 = sheet.createRow(0);
+        HSSFCell cell0 = row0.createCell(0);
+        //设置 第一行 表头
+        cell0.setCellValue("头条结算单");
+        CellRangeAddress region = new CellRangeAddress(0, 0, 0, 10);
+        sheet.addMergedRegion(region);//合并行
+        cell0.setCellStyle(style);
 
-    @ApiOperation(value="财务结算-结算单导出", notes="财务结算-结算单导出")
-    @GetMapping(value = "/exportImg")
-    public String exportImg(HttpServletResponse response) throws Exception {
 
-       // byte[] img = SettlementUtil.getByteImgByUrl("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg");
 
-        TemplateExportParams params = new TemplateExportParams("C://Users//Administrator//Desktop//bytedance.xlsx",true);
 
-        // 重要代码
-        //POICacheManager.setFileLoader(new FileLoaderImpl());
-        POICacheManager.setFileLoder(new FileLoaderImpl());
+        //4:添加表头2行
+        HSSFRow row = sheet.createRow(1);
+
+        //5:创建第2行的单元格
+        HSSFCell cell = row.createCell(0);     //第一个单元格
+        cell.setCellValue("      广告主ID      ");         //设定值
+        cell.setCellStyle(style);          //内容居中
+
+
+        cell = row.createCell(1);
+        cell.setCellValue("   日期   ");
+        cell.setCellStyle(style);
+
+        cell = row.createCell(2);
+        cell.setCellValue("日终结余(单位元)");
+        cell.setCellStyle(style);
+
+        cell = row.createCell(3);
+        cell.setCellValue("现金支出(单位元)");
+        cell.setCellStyle(style);
+
+        cell = row.createCell(4);
+        cell.setCellValue("总支出(单位元)");
+        cell.setCellStyle(style);
+
+        cell = row.createCell(5);
+        cell.setCellValue("冻结(单位元)");
+        cell.setCellStyle(style);
+
+        cell = row.createCell(6);
+        cell.setCellValue("总存入(单位元)");
+        cell.setCellStyle(style);
 
-        Map<String, Object> map = new HashMap<String, Object>();
+        cell = row.createCell(7);
+        cell.setCellValue("赠款支出(单位元)");
+        cell.setCellStyle(style);
+
+        cell = row.createCell(8);
+        cell.setCellValue("共享钱包支出(单位元)");
+        cell.setCellStyle(style);
+
+        cell = row.createCell(9);
+        cell.setCellValue("总转入(单位元)");
+        cell.setCellStyle(style);
+
+        cell = row.createCell(10);
+        cell.setCellValue("总转出(单位元)");
+        cell.setCellStyle(style);
+
+
+
+        //添加数据
         List<SettlementReportBytedanceVo> list = reportSettlementService.getAccountTransactionDayBytedance();
-        List<Map<String, Object>> pictureList = new ArrayList<Map<String, Object>>() ;
-
-        Map<String,Object> picture1 = new HashMap<String, Object>();
-        Map<String,Object> picture2 = new HashMap<String, Object>();
-       byte[] datas =  SettlementUtil.getByteImgByUrl("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg");
-        ImageEntity img = new ImageEntity();
-        img.setUrl("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg");
-        //img.setUrl("C:\\Users\\Administrator\\Desktop\\汇创\\20210507161223.jpg");
-        img.setHeight(1000);
-        img.setWidth(500);
-        picture1.put("imag", img);
-        picture2.put("imag", img);
-        pictureList.add(picture1);
-        pictureList.add(picture2);
-
-
-
-        Map<String, Object> resultMap = new HashMap<>();
-        resultMap.put("l",list);
-        resultMap.put("p",pictureList);
-
-
-        try {
-            Workbook workbook = ExcelExportUtil.exportExcel(params, resultMap);
-
-            response.setCharacterEncoding("UTF-8");
-            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
-            response.setHeader("Pragma", "no-cache");
-            response.setHeader("Cache-Control", "no-cache");
-            response.setDateHeader("Expires", 0);
-            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("文件名称.xlsx", "UTF-8"));
-            OutputStream output = response.getOutputStream();
-            BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
-            workbook.write(bufferedOutPut);
-            bufferedOutPut.flush();
-            bufferedOutPut.close();
-            output.close();
-        } catch (IOException e) {
-            throw new RuntimeException(e);
+        for (int i = 0; i < list.size(); i++) {
+            SettlementReportBytedanceVo vo = list.get(i);
+            //创建行 (表头占0-1行 所以 从 2开始)
+            row = sheet.createRow(i+2);
+            sheet.autoSizeColumn(0,true);
+            sheet.autoSizeColumn(i+1,true);
+
+            //创建单元格并且添加数据
+            row.createCell(0).setCellValue(vo.getAdvertiserId());
+            row.createCell(1).setCellValue(vo.getDate());
+            row.createCell(2).setCellValue(vo.getBalance());
+            row.createCell(3).setCellValue(vo.getCashCost());
+            row.createCell(4).setCellValue(vo.getCost());
+            row.createCell(5).setCellValue(vo.getFrozen());
+            row.createCell(6).setCellValue(vo.getIncome());
+            row.createCell(7).setCellValue(vo.getRewardCost());
+            row.createCell(8).setCellValue(vo.getSharedWalletCost());
+            row.createCell(9).setCellValue(vo.getTransferIn());
+            row.createCell(10).setCellValue(vo.getTransferOut());
+
         }
 
 
-       return "123";
+
+        //先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray
+        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
+        //bufferImg = ImageIO.read(new File("C:\\Users\\Administrator\\Desktop\\汇创\\20210507161223.jpg"));
+        //bufferImg = ImageIO.read(new File(URLDecoder.decode("https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg","utf-8")));
+        String imagePath = "https://media-1301855440.cos.ap-chongqing.myqcloud.com/image/2021-08-05/2-1628129040416.jpg";
+        //InputStream is = new FileInputStream(imagePath);
+        //通过图片网络地址 获取输入流
+        InputStream is = createExcelByTemplate.getInputStreamByUrl(imagePath);
+        BufferedImage bufferImg = ImageIO.read(is);
+
+        ImageIO.write(bufferImg, imagePath.substring(imagePath.lastIndexOf(".")+1), byteArrayOut);
+
+        //画图的顶级管理器,一个sheet只能获取一个
+        HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
+        //anchor主要用于设置图片的属性
+        //HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255,(short) 1, 1, (short) 5, 8);
+        HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 255, 255,(short) 5, list.size()+6, (short) 10, 40);
+        HSSFClientAnchor anchor2 = new HSSFClientAnchor(0, 0, 255, 255,(short) 5, list.size()+40, (short) 10, 40*2);
+        anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
+        anchor2.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
+        //插入图片
+        patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
+        patriarch.createPicture(anchor2, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG));
+
+
+
+        }
+        response.setCharacterEncoding("UTF-8");
+        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+        response.setHeader("Pragma", "no-cache");
+        response.setHeader("Cache-Control", "no-cache");
+        response.setDateHeader("Expires", 0);
+        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("文件名称.xlsx", "UTF-8"));
+        OutputStream output = response.getOutputStream();
+        BufferedOutputStream bufferedOutPut = new BufferedOutputStream(output);
+        wb.write(bufferedOutPut);
+        bufferedOutPut.flush();
+        bufferedOutPut.close();
+        output.close();
+
+       return "success";
     }
 
 

+ 5 - 2
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/settlement/service/serviceImpl/ExcelListener.java

@@ -1,3 +1,4 @@
+/*
 package org.jeecg.ctop.finance.settlement.service.serviceImpl;
 
 import cn.afterturn.easypoi.cache.ImageCache;
@@ -25,10 +26,12 @@ import com.google.common.cache.LoadingCache;
 
 import cn.afterturn.easypoi.cache.ImageCache;
 import cn.afterturn.easypoi.cache.manager.POICacheManager;
+*/
 /**
  * Administrator
  * 2021/8/5
- **/
+ **//*
+
 @Component
 public class ExcelListener implements ApplicationListener<ApplicationReadyEvent> {
     @Override
@@ -53,4 +56,4 @@ public class ExcelListener implements ApplicationListener<ApplicationReadyEvent>
                 });
         ImageCache.setLoadingCache(loadingCache);
     }
-}
+}*/

+ 54 - 0
jeecg-boot-finance/src/main/java/org/jeecg/ctop/finance/utils/createExcelByTemplate.java

@@ -0,0 +1,54 @@
+package org.jeecg.ctop.finance.utils;
+
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.util.IOUtils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+/**
+ * zian Y
+ * 2021/8/5
+ **/
+
+@Slf4j
+public class createExcelByTemplate {
+
+
+
+    /**
+     * 根据地址获得数据的输入流
+     * @param strUrl 网络连接地址
+     * @return url的输入流
+     */
+    public static InputStream getInputStreamByUrl(String strUrl){
+        HttpURLConnection conn = null;
+        try {
+            URL url = new URL(strUrl);
+            conn = (HttpURLConnection)url.openConnection();
+            conn.setRequestMethod("GET");
+            conn.setConnectTimeout(20 * 1000);
+            final ByteArrayOutputStream output = new ByteArrayOutputStream();
+            IOUtils.copy(conn.getInputStream(),output);
+            return  new ByteArrayInputStream(output.toByteArray());
+        } catch (Exception e) {
+            log.error(e+"");
+        }finally {
+            try{
+                if (conn != null) {
+                    conn.disconnect();
+                }
+            }catch (Exception e){
+                log.error(e+"");
+            }
+        }
+        return null;
+    }
+
+
+
+}