Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
JAVA小学生-王铁柱
eladmin
提交
cbaa49fb
E
eladmin
项目概览
JAVA小学生-王铁柱
/
eladmin
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
eladmin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
cbaa49fb
编写于
12月 13, 2020
作者:
Z
zhengjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[代码优化](v2.6):序列化优化,Excel 导出优化
上级
112c7b3e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
1 addition
and
43 deletion
+1
-43
eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
+0
-34
eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java
...m/src/main/java/me/zhengjie/config/ConfigurerAdapter.java
+1
-9
未找到文件。
eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
浏览文件 @
cbaa49fb
...
...
@@ -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"
;
...
...
eladmin-system/src/main/java/me/zhengjie/config/ConfigurerAdapter.java
浏览文件 @
cbaa49fb
...
...
@@ -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
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录