Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-api-boot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-api-boot
Commits
038eaa6b
提交
038eaa6b
authored
4月 14, 2022
作者:
谭志磊
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: excel工具类修改错误
上级
ad00c1e6
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
71 行增加
和
73 行删除
+71
-73
build.gradle
basic-common/core/build.gradle
+2
-2
build.gradle
basic-common/util/build.gradle
+6
-6
Excel.java
...til/src/main/java/com/yiring/common/annotation/Excel.java
+44
-44
ExcelUtils.java
.../src/main/java/com/yiring/common/util/poi/ExcelUtils.java
+19
-21
没有找到文件。
basic-common/core/build.gradle
浏览文件 @
038eaa6b
...
@@ -9,8 +9,8 @@ dependencies {
...
@@ -9,8 +9,8 @@ dependencies {
implementation
"io.swagger:swagger-annotations:${swaggerAnnotationsVersion}"
implementation
"io.swagger:swagger-annotations:${swaggerAnnotationsVersion}"
implementation
"org.hibernate.validator:hibernate-validator:${hibernateValidatorVersion}"
implementation
"org.hibernate.validator:hibernate-validator:${hibernateValidatorVersion}"
implementation
"cn.dev33:sa-token-dao-redis-jackson:${saTokenVersion}"
implementation
"cn.dev33:sa-token-dao-redis-jackson:${saTokenVersion}"
implementation
fileTree
(
dir:
project
.
rootDir
.
getPath
()
+
'\\libs'
,
includes:
[
'*jar'
])
implementation
fileTree
(
dir:
project
.
rootDir
.
getPath
()
+
'\\libs'
,
includes:
[
'*jar'
])
}
}
basic-common/util/build.gradle
浏览文件 @
038eaa6b
dependencies
{
dependencies
{
implementation
project
(
":basic-common:core"
)
implementation
project
(
":basic-common:core"
)
implementation
'org.springframework.boot:spring-boot-starter-web'
implementation
'org.springframework.boot:spring-boot-starter-web'
implementation
'org.springframework.boot:spring-boot-starter-aop'
implementation
'org.springframework.boot:spring-boot-starter-aop'
// hutool-extra
// hutool-extra
implementation
"cn.hutool:hutool-extra:${hutoolVersion}"
implementation
"cn.hutool:hutool-extra:${hutoolVersion}"
// fastjson
// fastjson
implementation
"com.alibaba:fastjson:${fastJsonVersion}"
implementation
"com.alibaba:fastjson:${fastJsonVersion}"
}
}
basic-common/util/src/main/java/com/yiring/common/annotation/Excel.java
浏览文件 @
038eaa6b
...
@@ -15,125 +15,125 @@ import java.math.BigDecimal;
...
@@ -15,125 +15,125 @@ import java.math.BigDecimal;
*/
*/
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
ElementType
.
FIELD
)
@Target
(
ElementType
.
FIELD
)
public
@interface
Excel
{
public
@interface
Excel
{
/**
/**
* 导出时在excel中排序
* 导出时在excel中排序
*/
*/
int
sort
()
default
Integer
.
MAX_VALUE
;
int
sort
()
default
Integer
.
MAX_VALUE
;
/**
/**
* 导出到Excel中的名字.
* 导出到Excel中的名字.
*/
*/
String
name
()
default
""
;
String
name
()
default
""
;
/**
/**
* 日期格式, 如: yyyy-MM-dd
* 日期格式, 如: yyyy-MM-dd
*/
*/
String
dateFormat
()
default
""
;
String
dateFormat
()
default
""
;
/**
/**
* 如果是字典类型,请设置字典的type值 (如: user_sex)
* 如果是字典类型,请设置字典的type值 (如: user_sex)
*/
*/
String
dictType
()
default
""
;
String
dictType
()
default
""
;
/**
/**
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
*/
*/
String
readConverterExp
()
default
""
;
String
readConverterExp
()
default
""
;
/**
/**
* 分隔符,读取字符串组内容
* 分隔符,读取字符串组内容
*/
*/
String
separator
()
default
","
;
String
separator
()
default
","
;
/**
/**
* BigDecimal 精度 默认:-1(默认不开启BigDecimal格式化)
* BigDecimal 精度 默认:-1(默认不开启BigDecimal格式化)
*/
*/
int
scale
()
default
-
1
;
int
scale
()
default
-
1
;
/**
/**
* BigDecimal 舍入规则 默认:BigDecimal.ROUND_HALF_EVEN
* BigDecimal 舍入规则 默认:BigDecimal.ROUND_HALF_EVEN
*/
*/
int
roundingMode
()
default
BigDecimal
.
ROUND_HALF_EVEN
;
int
roundingMode
()
default
BigDecimal
.
ROUND_HALF_EVEN
;
/**
/**
* 导出类型(0数字 1字符串)
* 导出类型(0数字 1字符串)
*/
*/
ColumnType
cellType
()
default
ColumnType
.
STRING
;
ColumnType
cellType
()
default
ColumnType
.
STRING
;
/**
/**
* 导出时在excel中每个列的高度 单位为字符
* 导出时在excel中每个列的高度 单位为字符
*/
*/
double
height
()
default
14
;
double
height
()
default
14
;
/**
/**
* 导出时在excel中每个列的宽 单位为字符
* 导出时在excel中每个列的宽 单位为字符
*/
*/
double
width
()
default
16
;
double
width
()
default
16
;
/**
/**
* 文字后缀,如% 90 变成90%
* 文字后缀,如% 90 变成90%
*/
*/
String
suffix
()
default
""
;
String
suffix
()
default
""
;
/**
/**
* 当值为空时,字段的默认值
* 当值为空时,字段的默认值
*/
*/
String
defaultValue
()
default
""
;
String
defaultValue
()
default
""
;
/**
/**
* 提示信息
* 提示信息
*/
*/
String
prompt
()
default
""
;
String
prompt
()
default
""
;
/**
/**
* 设置只能选择不能输入的列内容.
* 设置只能选择不能输入的列内容.
*/
*/
String
[]
combo
()
default
{};
String
[]
combo
()
default
{};
/**
/**
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
*/
*/
boolean
isExport
()
default
true
;
boolean
isExport
()
default
true
;
/**
/**
* 另一个类中的属性名称,支持多级获取,以小数点隔开
* 另一个类中的属性名称,支持多级获取,以小数点隔开
*/
*/
String
targetAttr
()
default
""
;
String
targetAttr
()
default
""
;
/**
/**
* 是否自动统计数据,在最后追加一行统计数据总和
* 是否自动统计数据,在最后追加一行统计数据总和
*/
*/
boolean
isStatistics
()
default
false
;
boolean
isStatistics
()
default
false
;
/**
/**
* 导出字段对齐方式(0:默认;1:靠左;2:居中;3:靠右)
* 导出字段对齐方式(0:默认;1:靠左;2:居中;3:靠右)
*/
*/
Align
align
()
default
Align
.
AUTO
;
Align
align
()
default
Align
.
AUTO
;
/**
/**
* 自定义数据处理器
* 自定义数据处理器
*/
*/
Class
<?>
handler
()
default
ExcelHandlerAdapter
.
class
;
Class
<?>
handler
()
default
ExcelHandlerAdapter
.
class
;
/**
/**
* 自定义数据处理器参数
* 自定义数据处理器参数
*/
*/
String
[]
args
()
default
{};
String
[]
args
()
default
{};
enum
Align
{
AUTO
(
0
),
LEFT
(
1
),
CENTER
(
2
),
RIGHT
(
3
);
enum
Align
{
AUTO
(
0
),
LEFT
(
1
),
CENTER
(
2
),
RIGHT
(
3
);
private
final
int
value
;
private
final
int
value
;
Align
(
int
value
)
Align
(
int
value
)
{
{
this
.
value
=
value
;
this
.
value
=
value
;
}
}
public
int
value
()
public
int
value
()
{
{
return
this
.
value
;
return
this
.
value
;
}
}
}
}
...
@@ -143,34 +143,34 @@ import java.math.BigDecimal;
...
@@ -143,34 +143,34 @@ import java.math.BigDecimal;
*/
*/
Type
type
()
default
Type
.
ALL
;
Type
type
()
default
Type
.
ALL
;
enum
Type
enum
Type
{
{
ALL
(
0
),
ALL
(
0
),
EXPORT
(
1
),
IMPORT
(
2
);
EXPORT
(
1
),
IMPORT
(
2
);
private
final
int
value
;
private
final
int
value
;
Type
(
int
value
)
Type
(
int
value
)
{
{
this
.
value
=
value
;
this
.
value
=
value
;
}
}
int
value
()
int
value
()
{
{
return
this
.
value
;
return
this
.
value
;
}
}
}
}
enum
ColumnType
enum
ColumnType
{
{
NUMERIC
(
0
),
NUMERIC
(
0
),
STRING
(
1
),
IMAGE
(
2
);
STRING
(
1
),
IMAGE
(
2
);
private
final
int
value
;
private
final
int
value
;
ColumnType
(
int
value
)
ColumnType
(
int
value
)
{
{
this
.
value
=
value
;
this
.
value
=
value
;
}
}
int
value
()
int
value
()
{
{
return
this
.
value
;
return
this
.
value
;
}
}
}
}
...
...
basic-common/util/src/main/java/com/yiring/common/util/poi/ExcelUtils.java
浏览文件 @
038eaa6b
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
common
.
util
.
poi
;
package
com
.
yiring
.
common
.
util
.
poi
;
import
com.yiring.common.annotation.Excel
;
import
com.yiring.common.annotation.Excel
;
import
com.yiring.common.annotation.Excel.ColumnType
;
import
com.yiring.common.annotation.Excel.ColumnType
;
import
com.yiring.common.annotation.Excel.Type
;
import
com.yiring.common.annotation.Excel.Type
;
...
@@ -12,18 +12,6 @@ import com.yiring.common.util.date.DateUtils;
...
@@ -12,18 +12,6 @@ import com.yiring.common.util.date.DateUtils;
import
com.yiring.common.util.file.FileTypeUtils
;
import
com.yiring.common.util.file.FileTypeUtils
;
import
com.yiring.common.util.file.ImageUtils
;
import
com.yiring.common.util.file.ImageUtils
;
import
com.yiring.common.util.reflect.ReflectUtils
;
import
com.yiring.common.util.reflect.ReflectUtils
;
import
org.apache.commons.lang3.RegExUtils
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.ss.util.CellRangeAddressList
;
import
org.apache.poi.util.IOUtils
;
import
org.apache.poi.xssf.streaming.SXSSFWorkbook
;
import
org.apache.poi.xssf.usermodel.XSSFClientAnchor
;
import
org.apache.poi.xssf.usermodel.XSSFDataValidation
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
@@ -35,6 +23,17 @@ import java.time.LocalDate;
...
@@ -35,6 +23,17 @@ import java.time.LocalDate;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang3.RegExUtils
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.ss.util.CellRangeAddressList
;
import
org.apache.poi.util.IOUtils
;
import
org.apache.poi.xssf.streaming.SXSSFWorkbook
;
import
org.apache.poi.xssf.usermodel.XSSFClientAnchor
;
import
org.apache.poi.xssf.usermodel.XSSFDataValidation
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
/**
* Excel相关处理
* Excel相关处理
...
@@ -47,7 +46,7 @@ public class ExcelUtils<T> {
...
@@ -47,7 +46,7 @@ public class ExcelUtils<T> {
public
static
final
String
FORMULA_REGEX_STR
=
"=|-|\\+|@"
;
public
static
final
String
FORMULA_REGEX_STR
=
"=|-|\\+|@"
;
public
static
final
String
[]
FORMULA_STR
=
{
"="
,
"-"
,
"+"
,
"@"
};
public
static
final
String
[]
FORMULA_STR
=
{
"="
,
"-"
,
"+"
,
"@"
};
/**
/**
* Excel sheet最大行数,默认65536
* Excel sheet最大行数,默认65536
...
@@ -255,7 +254,7 @@ public class ExcelUtils<T> {
...
@@ -255,7 +254,7 @@ public class ExcelUtils<T> {
}
}
}
else
if
(
}
else
if
(
(
Integer
.
TYPE
==
fieldType
||
Integer
.
class
==
fieldType
)
&&
(
Integer
.
TYPE
==
fieldType
||
Integer
.
class
==
fieldType
)
&&
StrUtils
.
isNumeric
(
Convert
.
toStr
(
val
))
StrUtils
.
isNumeric
(
Convert
.
toStr
(
val
))
)
{
)
{
val
=
Convert
.
toInt
(
val
);
val
=
Convert
.
toInt
(
val
);
}
else
if
(
}
else
if
(
...
@@ -363,7 +362,7 @@ public class ExcelUtils<T> {
...
@@ -363,7 +362,7 @@ public class ExcelUtils<T> {
public
void
exportExcel
(
HttpServletResponse
response
)
{
public
void
exportExcel
(
HttpServletResponse
response
)
{
try
{
try
{
writeSheet
();
writeSheet
();
// wb.write(response.getOutputStream());
// wb.write(response.getOutputStream());
FileOutputStream
fos
=
new
FileOutputStream
(
"D:/a.xls"
);
FileOutputStream
fos
=
new
FileOutputStream
(
"D:/a.xls"
);
wb
.
write
(
fos
);
wb
.
write
(
fos
);
fos
.
close
();
fos
.
close
();
...
@@ -766,7 +765,7 @@ public class ExcelUtils<T> {
...
@@ -766,7 +765,7 @@ public class ExcelUtils<T> {
public
String
dataFormatHandlerAdapter
(
Object
value
,
Excel
excel
)
{
public
String
dataFormatHandlerAdapter
(
Object
value
,
Excel
excel
)
{
try
{
try
{
Object
instance
=
excel
.
handler
().
newInstance
();
Object
instance
=
excel
.
handler
().
newInstance
();
Method
formatMethod
=
excel
.
handler
().
getMethod
(
"format"
,
new
Class
[]
{
Object
.
class
,
String
[].
class
});
Method
formatMethod
=
excel
.
handler
().
getMethod
(
"format"
,
new
Class
[]
{
Object
.
class
,
String
[].
class
});
value
=
formatMethod
.
invoke
(
instance
,
value
,
excel
.
args
());
value
=
formatMethod
.
invoke
(
instance
,
value
,
excel
.
args
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"不能格式化数据 "
+
excel
.
handler
(),
e
.
getMessage
());
log
.
error
(
"不能格式化数据 "
+
excel
.
handler
(),
e
.
getMessage
());
...
@@ -785,8 +784,7 @@ public class ExcelUtils<T> {
...
@@ -785,8 +784,7 @@ public class ExcelUtils<T> {
}
}
try
{
try
{
temp
=
Double
.
valueOf
(
text
);
temp
=
Double
.
valueOf
(
text
);
}
catch
(
NumberFormatException
e
)
{
}
catch
(
NumberFormatException
e
)
{}
}
statistics
.
put
(
index
,
statistics
.
get
(
index
)
+
temp
);
statistics
.
put
(
index
,
statistics
.
get
(
index
)
+
temp
);
}
}
}
}
...
@@ -880,7 +878,7 @@ public class ExcelUtils<T> {
...
@@ -880,7 +878,7 @@ public class ExcelUtils<T> {
Excel
attr
=
field
.
getAnnotation
(
Excel
.
class
);
Excel
attr
=
field
.
getAnnotation
(
Excel
.
class
);
if
(
attr
!=
null
&&
(
attr
.
type
()
==
Type
.
ALL
||
attr
.
type
()
==
type
))
{
if
(
attr
!=
null
&&
(
attr
.
type
()
==
Type
.
ALL
||
attr
.
type
()
==
type
))
{
field
.
setAccessible
(
true
);
field
.
setAccessible
(
true
);
fields
.
add
(
new
Object
[]
{
field
,
attr
});
fields
.
add
(
new
Object
[]
{
field
,
attr
});
}
}
}
}
...
@@ -891,7 +889,7 @@ public class ExcelUtils<T> {
...
@@ -891,7 +889,7 @@ public class ExcelUtils<T> {
for
(
Excel
attr
:
excels
)
{
for
(
Excel
attr
:
excels
)
{
if
(
attr
!=
null
&&
(
attr
.
type
()
==
Type
.
ALL
||
attr
.
type
()
==
type
))
{
if
(
attr
!=
null
&&
(
attr
.
type
()
==
Type
.
ALL
||
attr
.
type
()
==
type
))
{
field
.
setAccessible
(
true
);
field
.
setAccessible
(
true
);
fields
.
add
(
new
Object
[]
{
field
,
attr
});
fields
.
add
(
new
Object
[]
{
field
,
attr
});
}
}
}
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论