From cbaa49fbdfda6b931ef74a9e8705e557bda1d03c Mon Sep 17 00:00:00 2001 From: zhengjie <201507802@qq.com> Date: Sun, 13 Dec 2020 12:19:35 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96](v2.6)?= =?UTF-8?q?=EF=BC=9A=E5=BA=8F=E5=88=97=E5=8C=96=E4=BC=98=E5=8C=96=EF=BC=8C?= =?UTF-8?q?Excel=20=E5=AF=BC=E5=87=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/me/zhengjie/utils/FileUtil.java | 34 ------------------- .../me/zhengjie/config/ConfigurerAdapter.java | 10 +----- 2 files changed, 1 insertion(+), 43 deletions(-) diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java b/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java index ee0a66b6..10ccd712 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java @@ -20,15 +20,11 @@ import cn.hutool.core.util.IdUtil; import cn.hutool.poi.excel.BigExcelWriter; import cn.hutool.poi.excel.ExcelUtil; import me.zhengjie.exception.BadRequestException; -import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.util.IOUtils; -import org.apache.poi.xssf.streaming.SXSSFCell; -import org.apache.poi.xssf.streaming.SXSSFRow; import org.apache.poi.xssf.streaming.SXSSFSheet; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.multipart.MultipartFile; - import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -217,8 +213,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { sheet.trackAllColumnsForAutoSizing(); //列宽自适应 writer.autoSizeColumnAll(); - //列宽自适应支持中文单元格 - sizeChineseColumn(sheet, writer); //response为HttpServletResponse对象 response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 @@ -231,34 +225,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil { IoUtil.close(out); } - /** - * 自适应宽度(中文支持) - */ - private static void sizeChineseColumn(SXSSFSheet sheet, BigExcelWriter writer) { - for (int columnNum = 0; columnNum < writer.getColumnCount(); columnNum++) { - int columnWidth = sheet.getColumnWidth(columnNum) / 256; - for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) { - SXSSFRow currentRow; - if (sheet.getRow(rowNum) == null) { - currentRow = sheet.createRow(rowNum); - } else { - currentRow = sheet.getRow(rowNum); - } - if (currentRow.getCell(columnNum) != null) { - SXSSFCell currentCell = currentRow.getCell(columnNum); - if (currentCell.getCellTypeEnum() == CellType.STRING) { - int length = currentCell.getStringCellValue().getBytes().length; - // 如果长度大于最大值 65280,那就取 length - if (columnWidth < length || (columnWidth * 256 > 65280)) { - columnWidth = length; - } - } - } - } - sheet.setColumnWidth(columnNum, columnWidth * 256); - } - } - public static String getFileType(String type) { String documents = "txt doc pdf ppt pps xlsx xls docx"; String music = "mp3 wav wma mpa ram ra aac aif m4a"; diff --git a/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java b/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java index 643b75df..4a47cb67 100644 --- a/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java +++ b/eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java @@ -81,15 +81,7 @@ public class ConfigurerAdapter implements WebMvcConfigurer { config.setSerializerFeatures( SerializerFeature.DisableCircularReferenceDetect, //保留空的字段 - SerializerFeature.WriteMapNullValue, - //String null -> "" - SerializerFeature.WriteNullStringAsEmpty, - //Number null -> 0 - SerializerFeature.WriteNullNumberAsZero, - //List null-> [] - SerializerFeature.WriteNullListAsEmpty, - //Boolean null -> false - SerializerFeature.WriteNullBooleanAsFalse); + SerializerFeature.WriteMapNullValue); converter.setFastJsonConfig(config); converter.setSupportedMediaTypes(supportMediaTypeList); converter.setDefaultCharset(StandardCharsets.UTF_8);