Переглянути джерело

重置输出流,清空上次遗留信息

peiguo 4 роки тому
батько
коміт
127184d78b

+ 1 - 1
whepi-web/src/main/java/com/bofeng/excel/ExcelBuilder.java

@@ -6,7 +6,6 @@ import com.alibaba.excel.metadata.Sheet;
 import com.alibaba.excel.metadata.Table;
 import com.alibaba.excel.support.ExcelTypeEnum;
 import com.alibaba.excel.util.StringUtils;
-import com.alibaba.excel.util.TypeUtil;
 import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
 import lombok.*;
@@ -41,6 +40,7 @@ public class ExcelBuilder {
 
     @SneakyThrows
     public void export(HttpServletResponse response, String fileName) {
+        response.resetBuffer();// 重置输出流,清空上次遗留信息,防止报错
         response.setContentType("application/vnd.ms-excel;charset=utf-8");
         response.setHeader("Content-Disposition", "attachment;filename=" + new String(( fileName + ".xlsx").getBytes(), "iso-8859-1"));
         try (OutputStream outputStream = response.getOutputStream()) {