Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
50ba7049
Unverified
Commit
50ba7049
authored
Oct 13, 2020
by
chanxindiaolong
Committed by
GitHub
Oct 13, 2020
Browse files
update:导出excel时设置列宽自适应。 (#506)
parent
0c6ad747
Changes
1
Hide whitespace changes
Inline
Side-by-side
eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
View file @
50ba7049
...
...
@@ -21,6 +21,7 @@ import cn.hutool.poi.excel.BigExcelWriter;
import
cn.hutool.poi.excel.ExcelUtil
;
import
me.zhengjie.exception.BadRequestException
;
import
org.apache.poi.util.IOUtils
;
import
org.apache.poi.xssf.streaming.SXSSFSheet
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.web.multipart.MultipartFile
;
...
...
@@ -208,6 +209,11 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
BigExcelWriter
writer
=
ExcelUtil
.
getBigWriter
(
file
);
// 一次性写出内容,使用默认样式,强制输出标题
writer
.
write
(
list
,
true
);
SXSSFSheet
sheet
=
(
SXSSFSheet
)
writer
.
getSheet
();
//上面需要强转SXSSFSheet 不然没有trackAllColumnsForAutoSizing方法
sheet
.
trackAllColumnsForAutoSizing
();
//列宽自适应
writer
.
autoSizeColumnAll
();
//response为HttpServletResponse对象
response
.
setContentType
(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
);
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment