Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yaru
fgqyxxlr
Commits
326fe6a6
Commit
326fe6a6
authored
Jun 21, 2020
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Excel支持readConverterExp读取字符串组内容
parent
5321200c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
10 deletions
+48
-10
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
+5
-0
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+43
-10
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
View file @
326fe6a6
...
...
@@ -30,6 +30,11 @@ public @interface Excel
public
String
readConverterExp
()
default
""
;
/**
* 分隔符,读取字符串组内容
*/
public
String
separator
()
default
","
;
/**
* 导出类型(0数字 1字符串)
*/
public
ColumnType
cellType
()
default
ColumnType
.
STRING
;
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
View file @
326fe6a6
...
...
@@ -276,7 +276,7 @@ public class ExcelUtil<T>
}
else
if
(
StringUtils
.
isNotEmpty
(
attr
.
readConverterExp
()))
{
val
=
reverseByExp
(
String
.
valueOf
(
val
),
attr
.
readConverterExp
());
val
=
reverseByExp
(
String
.
valueOf
(
val
),
attr
.
readConverterExp
()
,
attr
.
separator
()
);
}
ReflectUtils
.
invokeSetter
(
entity
,
propertyName
,
val
);
}
...
...
@@ -535,13 +535,14 @@ public class ExcelUtil<T>
Object
value
=
getTargetValue
(
vo
,
field
,
attr
);
String
dateFormat
=
attr
.
dateFormat
();
String
readConverterExp
=
attr
.
readConverterExp
();
String
separator
=
attr
.
separator
();
if
(
StringUtils
.
isNotEmpty
(
dateFormat
)
&&
StringUtils
.
isNotNull
(
value
))
{
cell
.
setCellValue
(
DateUtils
.
parseDateToStr
(
dateFormat
,
(
Date
)
value
));
}
else
if
(
StringUtils
.
isNotEmpty
(
readConverterExp
)
&&
StringUtils
.
isNotNull
(
value
))
{
cell
.
setCellValue
(
convertByExp
(
String
.
valueOf
(
value
),
readConverterExp
));
cell
.
setCellValue
(
convertByExp
(
String
.
valueOf
(
value
),
readConverterExp
,
separator
));
}
else
{
...
...
@@ -619,20 +620,36 @@ public class ExcelUtil<T>
*
* @param propertyValue 参数值
* @param converterExp 翻译注解
* @param separator 分隔符
* @return 解析后值
* @throws Exception
*/
public
static
String
convertByExp
(
String
propertyValue
,
String
converterExp
)
throws
Exception
public
static
String
convertByExp
(
String
propertyValue
,
String
converterExp
,
String
separator
)
throws
Exception
{
StringBuilder
propertyString
=
new
StringBuilder
();
try
{
String
[]
convertSource
=
converterExp
.
split
(
","
);
for
(
String
item
:
convertSource
)
{
String
[]
itemArray
=
item
.
split
(
"="
);
if
(
itemArray
[
0
].
equals
(
propertyValue
))
if
(
StringUtils
.
containsAny
(
separator
,
propertyValue
))
{
return
itemArray
[
1
];
for
(
String
value
:
propertyValue
.
split
(
separator
))
{
if
(
itemArray
[
0
].
equals
(
value
))
{
propertyString
.
append
(
itemArray
[
1
]
+
separator
);
break
;
}
}
}
else
{
if
(
itemArray
[
0
].
equals
(
propertyValue
))
{
return
itemArray
[
1
];
}
}
}
}
...
...
@@ -640,7 +657,7 @@ public class ExcelUtil<T>
{
throw
e
;
}
return
propertyValue
;
return
StringUtils
.
stripEnd
(
propertyString
.
toString
(),
separator
)
;
}
/**
...
...
@@ -648,20 +665,36 @@ public class ExcelUtil<T>
*
* @param propertyValue 参数值
* @param converterExp 翻译注解
* @param separator 分隔符
* @return 解析后值
* @throws Exception
*/
public
static
String
reverseByExp
(
String
propertyValue
,
String
converterExp
)
throws
Exception
public
static
String
reverseByExp
(
String
propertyValue
,
String
converterExp
,
String
separator
)
throws
Exception
{
StringBuilder
propertyString
=
new
StringBuilder
();
try
{
String
[]
convertSource
=
converterExp
.
split
(
","
);
for
(
String
item
:
convertSource
)
{
String
[]
itemArray
=
item
.
split
(
"="
);
if
(
itemArray
[
1
].
equals
(
propertyValue
))
if
(
StringUtils
.
containsAny
(
separator
,
propertyValue
))
{
return
itemArray
[
0
];
for
(
String
value
:
propertyValue
.
split
(
separator
))
{
if
(
itemArray
[
1
].
equals
(
value
))
{
propertyString
.
append
(
itemArray
[
0
]
+
separator
);
break
;
}
}
}
else
{
if
(
itemArray
[
1
].
equals
(
propertyValue
))
{
return
itemArray
[
0
];
}
}
}
}
...
...
@@ -669,7 +702,7 @@ public class ExcelUtil<T>
{
throw
e
;
}
return
propertyValue
;
return
StringUtils
.
stripEnd
(
propertyString
.
toString
(),
separator
)
;
}
/**
...
...
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