Skip to content

Commit e2237b6

Browse files
committed
Add Excel export width auto size
1 parent f77237c commit e2237b6

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
* Add questionnaire system
2424
* Add compute string width method
25+
* Add `Excel` export width auto size
2526

2627
## 1.6.6
2728

tang-commons/src/main/kotlin/com/tang/commons/utils/poi/Excels.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.tang.commons.constants.ContentType
66
import com.tang.commons.constants.FileType
77
import com.tang.commons.enumeration.poi.Type
88
import com.tang.commons.exception.file.FileTypeMismatchException
9+
import com.tang.commons.kotlin.extensions.width
910
import com.tang.commons.utils.Assert
1011
import com.tang.commons.utils.DictUtils
1112
import com.tang.commons.utils.LogUtils
@@ -396,7 +397,8 @@ object Excels {
396397
cell.cellStyle = cellStyle
397398

398399
// 设置列宽
399-
sheet.setColumnWidth(lastCellNum, excel.width * 256)
400+
val width = if (excel.width == -1) excel.name.width() + 1 else excel.width
401+
sheet.setColumnWidth(lastCellNum, width * 256)
400402

401403
// 设置行高
402404
titleRow.height = (excel.titleHeight * 20).toShort()

0 commit comments

Comments
 (0)