Browse Source

修改下载变更记录模板接口

fengyanjie 3 years ago
parent
commit
f89c0ba7fb

+ 6 - 4
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/controller/DownloadController.java

@@ -2,9 +2,7 @@ package com.persagy.dmp.rwd.edit.controller;
 
 import com.persagy.dmp.rwd.edit.service.DownloadService;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -47,7 +45,7 @@ public class DownloadController {
         String fileName = "批量上传变更记录模板.xlsx";
         InputStream inputStream = new BufferedInputStream(resourceAsStream);
 //        @SuppressWarnings("resource")
-        Workbook workbook = new HSSFWorkbook(inputStream);
+//        Workbook workbook = new HSSFWorkbook(inputStream);
 //        String userAgent = req.getHeader("User-Agent");
 //        if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
 //            fileName = new String(fileName.getBytes("gbk"), "utf-8");
@@ -73,7 +71,11 @@ public class DownloadController {
             resp.setHeader("Content-disposition", "attachment; filename=" + resultFileName);
             resp.setContentType("application/txt");
             out = resp.getOutputStream();
-            workbook.write(out);
+            int len;
+            byte[] buffer = new byte[1024];        //缓冲区
+            while ((len = inputStream.read(buffer)) != -1) {   //将接受的数据写入缓冲区数组buffer
+                out.write(buffer, 0, len);          //将缓冲区buffer写入byte数组输出流
+            }
             out.flush();
         } catch (Exception e) {
             e.printStackTrace();