Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sts网站
Project
Project
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
liyang
sts网站
Commits
61034d4d
Commit
61034d4d
authored
Mar 27, 2022
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化导出excel单元格验证,包含变更为开头.防止正常内容被替换
parent
6605bf35
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
2 deletions
+5
-2
ExcelUtil.java
...n/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+5
-2
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
View file @
61034d4d
...
@@ -22,6 +22,7 @@ import java.util.Set;
...
@@ -22,6 +22,7 @@ import java.util.Set;
import
java.util.UUID
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang3.RegExUtils
;
import
org.apache.poi.hssf.usermodel.HSSFClientAnchor
;
import
org.apache.poi.hssf.usermodel.HSSFClientAnchor
;
import
org.apache.poi.hssf.usermodel.HSSFPicture
;
import
org.apache.poi.hssf.usermodel.HSSFPicture
;
import
org.apache.poi.hssf.usermodel.HSSFPictureData
;
import
org.apache.poi.hssf.usermodel.HSSFPictureData
;
...
@@ -88,6 +89,8 @@ public class ExcelUtil<T>
...
@@ -88,6 +89,8 @@ public class ExcelUtil<T>
{
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ExcelUtil
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ExcelUtil
.
class
);
public
static
final
String
FORMULA_REGEX_STR
=
"=|-|\\+|@"
;
public
static
final
String
[]
FORMULA_STR
=
{
"="
,
"-"
,
"+"
,
"@"
};
public
static
final
String
[]
FORMULA_STR
=
{
"="
,
"-"
,
"+"
,
"@"
};
/**
/**
...
@@ -714,9 +717,9 @@ public class ExcelUtil<T>
...
@@ -714,9 +717,9 @@ public class ExcelUtil<T>
{
{
String
cellValue
=
Convert
.
toStr
(
value
);
String
cellValue
=
Convert
.
toStr
(
value
);
// 对于任何以表达式触发字符 =-+@开头的单元格,直接使用tab字符作为前缀,防止CSV注入。
// 对于任何以表达式触发字符 =-+@开头的单元格,直接使用tab字符作为前缀,防止CSV注入。
if
(
StringUtils
.
contains
Any
(
cellValue
,
FORMULA_STR
))
if
(
StringUtils
.
startsWith
Any
(
cellValue
,
FORMULA_STR
))
{
{
cellValue
=
StringUtils
.
replaceEach
(
cellValue
,
FORMULA_STR
,
new
String
[]
{
"\t="
,
"\t-"
,
"\t+"
,
"\t@"
}
);
cellValue
=
RegExUtils
.
replaceFirst
(
cellValue
,
FORMULA_REGEX_STR
,
"\t$0"
);
}
}
cell
.
setCellValue
(
StringUtils
.
isNull
(
cellValue
)
?
attr
.
defaultValue
()
:
cellValue
+
attr
.
suffix
());
cell
.
setCellValue
(
StringUtils
.
isNull
(
cellValue
)
?
attr
.
defaultValue
()
:
cellValue
+
attr
.
suffix
());
}
}
...
...
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