Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finance-manage
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
finance-oa
finance-manage
Commits
da146c2a
Commit
da146c2a
authored
Aug 19, 2020
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Excel注解支持设置BigDecimal精度&舍入规则
parent
7de5358d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
3 deletions
+26
-3
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
...mmon/src/main/java/com/ruoyi/common/annotation/Excel.java
+12
-1
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
...n/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+14
-2
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
View file @
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
View file @
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
)
...
...
Write
Preview
Markdown
is supported
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