Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
T
topology
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
姜立玮
topology
Commits
da146c2a
提交
da146c2a
authored
8月 19, 2020
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Excel注解支持设置BigDecimal精度&舍入规则
上级
7de5358d
变更
2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
26 行增加
和
3 行删除
+26
-3
Excel.java
...mmon/src/main/java/com/ruoyi/common/annotation/Excel.java
+12
-1
ExcelUtil.java
...n/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+14
-2
没有找到文件。
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
浏览文件 @
da146c2a
...
@@ -4,6 +4,7 @@ import java.lang.annotation.ElementType;
...
@@ -4,6 +4,7 @@ import java.lang.annotation.ElementType;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
java.lang.annotation.Target
;
import
java.math.BigDecimal
;
/**
/**
* 自定义导出Excel数据注解
* 自定义导出Excel数据注解
...
@@ -30,7 +31,7 @@ public @interface Excel
...
@@ -30,7 +31,7 @@ public @interface Excel
public
String
dateFormat
()
default
""
;
public
String
dateFormat
()
default
""
;
/**
/**
* 如果是字典类型,请设置字典的type值
* 如果是字典类型,请设置字典的type值
(如: sys_user_sex)
*/
*/
public
String
dictType
()
default
""
;
public
String
dictType
()
default
""
;
...
@@ -44,6 +45,16 @@ public @interface Excel
...
@@ -44,6 +45,16 @@ public @interface Excel
*/
*/
public
String
separator
()
default
","
;
public
String
separator
()
default
","
;
/**
* BigDecimal 精度 默认:-1(默认不开启BigDecimal格式化)
*/
public
int
scale
()
default
-
1
;
/**
* BigDecimal 舍入规则 默认:BigDecimal.ROUND_HALF_EVEN
*/
public
int
roundingMode
()
default
BigDecimal
.
ROUND_HALF_EVEN
;
/**
/**
* 导出类型(0数字 1字符串)
* 导出类型(0数字 1字符串)
*/
*/
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
浏览文件 @
da146c2a
...
@@ -8,6 +8,7 @@ import java.io.OutputStream;
...
@@ -8,6 +8,7 @@ import java.io.OutputStream;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.text.DecimalFormat
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Comparator
;
import
java.util.Comparator
;
...
@@ -546,10 +547,14 @@ public class ExcelUtil<T>
...
@@ -546,10 +547,14 @@ public class ExcelUtil<T>
{
{
cell
.
setCellValue
(
convertByExp
(
Convert
.
toStr
(
value
),
readConverterExp
,
separator
));
cell
.
setCellValue
(
convertByExp
(
Convert
.
toStr
(
value
),
readConverterExp
,
separator
));
}
}
else
if
(
StringUtils
.
isNotEmpty
(
dictType
))
else
if
(
StringUtils
.
isNotEmpty
(
dictType
)
&&
StringUtils
.
isNotNull
(
value
)
)
{
{
cell
.
setCellValue
(
convertDictByExp
(
Convert
.
toStr
(
value
),
dictType
,
separator
));
cell
.
setCellValue
(
convertDictByExp
(
Convert
.
toStr
(
value
),
dictType
,
separator
));
}
}
else
if
(
value
instanceof
BigDecimal
&&
-
1
!=
attr
.
scale
())
{
cell
.
setCellValue
((((
BigDecimal
)
value
).
setScale
(
attr
.
scale
(),
attr
.
roundingMode
())).
toString
());
}
else
else
{
{
// 设置列类型
// 设置列类型
...
@@ -896,7 +901,14 @@ public class ExcelUtil<T>
...
@@ -896,7 +901,14 @@ public class ExcelUtil<T>
}
}
else
else
{
{
val
=
new
BigDecimal
(
val
.
toString
());
// 浮点格式处理
if
((
Double
)
val
%
1
>
0
)
{
val
=
new
BigDecimal
(
val
.
toString
());
}
else
{
val
=
new
DecimalFormat
(
"0"
).
format
(
val
);
}
}
}
}
}
else
if
(
cell
.
getCellTypeEnum
()
==
CellType
.
STRING
)
else
if
(
cell
.
getCellTypeEnum
()
==
CellType
.
STRING
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论