Skip to content

Commit 1634026

Browse files
committed
Merge branch 'master' into deploy
2 parents 0ccaeb7 + cbaa49f commit 1634026

2 files changed

Lines changed: 1 addition & 43 deletions

File tree

eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@
2020
import cn.hutool.poi.excel.BigExcelWriter;
2121
import cn.hutool.poi.excel.ExcelUtil;
2222
import me.zhengjie.exception.BadRequestException;
23-
import org.apache.poi.ss.usermodel.CellType;
2423
import org.apache.poi.util.IOUtils;
25-
import org.apache.poi.xssf.streaming.SXSSFCell;
26-
import org.apache.poi.xssf.streaming.SXSSFRow;
2724
import org.apache.poi.xssf.streaming.SXSSFSheet;
2825
import org.slf4j.Logger;
2926
import org.slf4j.LoggerFactory;
3027
import org.springframework.web.multipart.MultipartFile;
31-
3228
import javax.servlet.ServletOutputStream;
3329
import javax.servlet.http.HttpServletRequest;
3430
import javax.servlet.http.HttpServletResponse;
@@ -217,8 +213,6 @@ public static void downloadExcel(List<Map<String, Object>> list, HttpServletResp
217213
sheet.trackAllColumnsForAutoSizing();
218214
//列宽自适应
219215
writer.autoSizeColumnAll();
220-
//列宽自适应支持中文单元格
221-
sizeChineseColumn(sheet, writer);
222216
//response为HttpServletResponse对象
223217
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
224218
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
@@ -231,34 +225,6 @@ public static void downloadExcel(List<Map<String, Object>> list, HttpServletResp
231225
IoUtil.close(out);
232226
}
233227

234-
/**
235-
* 自适应宽度(中文支持)
236-
*/
237-
private static void sizeChineseColumn(SXSSFSheet sheet, BigExcelWriter writer) {
238-
for (int columnNum = 0; columnNum < writer.getColumnCount(); columnNum++) {
239-
int columnWidth = sheet.getColumnWidth(columnNum) / 256;
240-
for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) {
241-
SXSSFRow currentRow;
242-
if (sheet.getRow(rowNum) == null) {
243-
currentRow = sheet.createRow(rowNum);
244-
} else {
245-
currentRow = sheet.getRow(rowNum);
246-
}
247-
if (currentRow.getCell(columnNum) != null) {
248-
SXSSFCell currentCell = currentRow.getCell(columnNum);
249-
if (currentCell.getCellTypeEnum() == CellType.STRING) {
250-
int length = currentCell.getStringCellValue().getBytes().length;
251-
// 如果长度大于最大值 65280,那就取 length
252-
if (columnWidth < length || (columnWidth * 256 > 65280)) {
253-
columnWidth = length;
254-
}
255-
}
256-
}
257-
}
258-
sheet.setColumnWidth(columnNum, columnWidth * 256);
259-
}
260-
}
261-
262228
public static String getFileType(String type) {
263229
String documents = "txt doc pdf ppt pps xlsx xls docx";
264230
String music = "mp3 wav wma mpa ram ra aac aif m4a";

eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,7 @@ public void configureMessageConverters(List<HttpMessageConverter<?>> converters)
8181
config.setSerializerFeatures(
8282
SerializerFeature.DisableCircularReferenceDetect,
8383
//保留空的字段
84-
SerializerFeature.WriteMapNullValue,
85-
//String null -> ""
86-
SerializerFeature.WriteNullStringAsEmpty,
87-
//Number null -> 0
88-
SerializerFeature.WriteNullNumberAsZero,
89-
//List null-> []
90-
SerializerFeature.WriteNullListAsEmpty,
91-
//Boolean null -> false
92-
SerializerFeature.WriteNullBooleanAsFalse);
84+
SerializerFeature.WriteMapNullValue);
9385
converter.setFastJsonConfig(config);
9486
converter.setSupportedMediaTypes(supportMediaTypeList);
9587
converter.setDefaultCharset(StandardCharsets.UTF_8);

0 commit comments

Comments
 (0)