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 个修改的文件
包含
41 行增加
和
43 行删除
+41
-43
build.gradle
basic-common/core/build.gradle
+0
-0
build.gradle
basic-common/util/build.gradle
+0
-0
Excel.java
...til/src/main/java/com/yiring/common/annotation/Excel.java
+23
-23
ExcelUtils.java
.../src/main/java/com/yiring/common/util/poi/ExcelUtils.java
+18
-20
没有找到文件。
basic-common/core/build.gradle
浏览文件 @
038eaa6b
basic-common/util/build.gradle
浏览文件 @
038eaa6b
basic-common/util/src/main/java/com/yiring/common/annotation/Excel.java
浏览文件 @
038eaa6b
...
...
@@ -15,7 +15,7 @@ import java.math.BigDecimal;
*/
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
ElementType
.
FIELD
)
public
@interface
Excel
{
public
@interface
Excel
{
/**
* 导出时在excel中排序
*/
...
...
@@ -36,7 +36,6 @@ import java.math.BigDecimal;
*/
String
dictType
()
default
""
;
/**
* 读取内容转表达式 (如: 0=男,1=女,2=未知)
*/
...
...
@@ -122,18 +121,19 @@ import java.math.BigDecimal;
*/
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
;
Align
(
int
value
)
{
Align
(
int
value
)
{
this
.
value
=
value
;
}
public
int
value
()
{
public
int
value
()
{
return
this
.
value
;
}
}
...
...
@@ -143,34 +143,34 @@ import java.math.BigDecimal;
*/
Type
type
()
default
Type
.
ALL
;
enum
Type
{
ALL
(
0
),
EXPORT
(
1
),
IMPORT
(
2
);
enum
Type
{
ALL
(
0
),
EXPORT
(
1
),
IMPORT
(
2
);
private
final
int
value
;
Type
(
int
value
)
{
Type
(
int
value
)
{
this
.
value
=
value
;
}
int
value
()
{
int
value
()
{
return
this
.
value
;
}
}
enum
ColumnType
{
NUMERIC
(
0
),
STRING
(
1
),
IMAGE
(
2
);
enum
ColumnType
{
NUMERIC
(
0
),
STRING
(
1
),
IMAGE
(
2
);
private
final
int
value
;
ColumnType
(
int
value
)
{
ColumnType
(
int
value
)
{
this
.
value
=
value
;
}
int
value
()
{
int
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
;
import
com.yiring.common.annotation.Excel
;
import
com.yiring.common.annotation.Excel.ColumnType
;
import
com.yiring.common.annotation.Excel.Type
;
...
...
@@ -12,18 +12,6 @@ import com.yiring.common.util.date.DateUtils;
import
com.yiring.common.util.file.FileTypeUtils
;
import
com.yiring.common.util.file.ImageUtils
;
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.IOException
;
import
java.io.InputStream
;
...
...
@@ -35,6 +23,17 @@ import java.time.LocalDate;
import
java.time.LocalDateTime
;
import
java.util.*
;
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相关处理
...
...
@@ -47,7 +46,7 @@ public class ExcelUtils<T> {
public
static
final
String
FORMULA_REGEX_STR
=
"=|-|\\+|@"
;
public
static
final
String
[]
FORMULA_STR
=
{
"="
,
"-"
,
"+"
,
"@"
};
public
static
final
String
[]
FORMULA_STR
=
{
"="
,
"-"
,
"+"
,
"@"
};
/**
* Excel sheet最大行数,默认65536
...
...
@@ -363,7 +362,7 @@ public class ExcelUtils<T> {
public
void
exportExcel
(
HttpServletResponse
response
)
{
try
{
writeSheet
();
// wb.write(response.getOutputStream());
// wb.write(response.getOutputStream());
FileOutputStream
fos
=
new
FileOutputStream
(
"D:/a.xls"
);
wb
.
write
(
fos
);
fos
.
close
();
...
...
@@ -766,7 +765,7 @@ public class ExcelUtils<T> {
public
String
dataFormatHandlerAdapter
(
Object
value
,
Excel
excel
)
{
try
{
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
());
}
catch
(
Exception
e
)
{
log
.
error
(
"不能格式化数据 "
+
excel
.
handler
(),
e
.
getMessage
());
...
...
@@ -785,8 +784,7 @@ public class ExcelUtils<T> {
}
try
{
temp
=
Double
.
valueOf
(
text
);
}
catch
(
NumberFormatException
e
)
{
}
}
catch
(
NumberFormatException
e
)
{}
statistics
.
put
(
index
,
statistics
.
get
(
index
)
+
temp
);
}
}
...
...
@@ -880,7 +878,7 @@ public class ExcelUtils<T> {
Excel
attr
=
field
.
getAnnotation
(
Excel
.
class
);
if
(
attr
!=
null
&&
(
attr
.
type
()
==
Type
.
ALL
||
attr
.
type
()
==
type
))
{
field
.
setAccessible
(
true
);
fields
.
add
(
new
Object
[]
{
field
,
attr
});
fields
.
add
(
new
Object
[]
{
field
,
attr
});
}
}
...
...
@@ -891,7 +889,7 @@ public class ExcelUtils<T> {
for
(
Excel
attr
:
excels
)
{
if
(
attr
!=
null
&&
(
attr
.
type
()
==
Type
.
ALL
||
attr
.
type
()
==
type
))
{
field
.
setAccessible
(
true
);
fields
.
add
(
new
Object
[]
{
field
,
attr
});
fields
.
add
(
new
Object
[]
{
field
,
attr
});
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论