Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MeterSphere
metersphere
提交
0fee46ce
M
metersphere
项目概览
MeterSphere
/
metersphere
上一次同步 大约 3 年
通知
25
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
metersphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0fee46ce
编写于
5月 21, 2020
作者:
C
chenjianxing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
excel国际化加锁
上级
8853b39d
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
10 deletion
+19
-10
backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java
...java/io/metersphere/excel/listener/EasyExcelListener.java
+5
-2
backend/src/main/java/io/metersphere/excel/utils/EasyExcelExporter.java
...in/java/io/metersphere/excel/utils/EasyExcelExporter.java
+12
-6
backend/src/main/java/io/metersphere/track/service/TestCaseService.java
...in/java/io/metersphere/track/service/TestCaseService.java
+2
-2
未找到文件。
backend/src/main/java/io/metersphere/excel/listener/EasyExcelListener.java
浏览文件 @
0fee46ce
...
@@ -32,8 +32,11 @@ public abstract class EasyExcelListener <T> extends AnalysisEventListener<T> {
...
@@ -32,8 +32,11 @@ public abstract class EasyExcelListener <T> extends AnalysisEventListener<T> {
public
EasyExcelListener
(){
public
EasyExcelListener
(){
Type
type
=
getClass
().
getGenericSuperclass
();
Type
type
=
getClass
().
getGenericSuperclass
();
this
.
clazz
=
(
Class
<
T
>)
((
ParameterizedType
)
type
).
getActualTypeArguments
()[
0
];
this
.
clazz
=
(
Class
<
T
>)
((
ParameterizedType
)
type
).
getActualTypeArguments
()[
0
];
this
.
easyExcelI18nTranslator
=
new
EasyExcelI18nTranslator
(
this
.
clazz
);
//防止多线程修改运行时类注解后,saveOriginalExcelProperty保存的是修改后的值
this
.
easyExcelI18nTranslator
.
translateExcelProperty
();
synchronized
(
EasyExcelI18nTranslator
.
class
)
{
this
.
easyExcelI18nTranslator
=
new
EasyExcelI18nTranslator
(
this
.
clazz
);
this
.
easyExcelI18nTranslator
.
translateExcelProperty
();
}
}
}
/**
/**
...
...
backend/src/main/java/io/metersphere/excel/utils/EasyExcelExporter.java
浏览文件 @
0fee46ce
...
@@ -24,17 +24,24 @@ public class EasyExcelExporter {
...
@@ -24,17 +24,24 @@ public class EasyExcelExporter {
EasyExcelI18nTranslator
easyExcelI18nTranslator
;
EasyExcelI18nTranslator
easyExcelI18nTranslator
;
public
EasyExcelExporter
()
{
private
Class
clazz
;
easyExcelI18nTranslator
=
new
EasyExcelI18nTranslator
(
TestCaseExcelData
.
class
);
easyExcelI18nTranslator
.
translateExcelProperty
();
public
EasyExcelExporter
(
Class
clazz
)
{
this
.
clazz
=
clazz
;
//防止多线程修改运行时类注解后,saveOriginalExcelProperty保存的是修改后的值
synchronized
(
EasyExcelI18nTranslator
.
class
)
{
easyExcelI18nTranslator
=
new
EasyExcelI18nTranslator
(
clazz
);
easyExcelI18nTranslator
.
translateExcelProperty
();
}
}
}
public
void
export
(
HttpServletResponse
response
,
Class
clazz
,
List
data
,
String
fileName
,
String
sheetName
)
{
public
void
export
(
HttpServletResponse
response
,
List
data
,
String
fileName
,
String
sheetName
)
{
response
.
setContentType
(
"application/vnd.ms-excel"
);
response
.
setContentType
(
"application/vnd.ms-excel"
);
response
.
setCharacterEncoding
(
"utf-8"
);
response
.
setCharacterEncoding
(
"utf-8"
);
try
{
try
{
response
.
setHeader
(
"Content-disposition"
,
"attachment;filename="
+
URLEncoder
.
encode
(
fileName
,
"UTF-8"
)
+
".xlsx"
);
response
.
setHeader
(
"Content-disposition"
,
"attachment;filename="
+
URLEncoder
.
encode
(
fileName
,
"UTF-8"
)
+
".xlsx"
);
EasyExcel
.
write
(
response
.
getOutputStream
(),
clazz
).
sheet
(
sheetName
).
doWrite
(
data
);
EasyExcel
.
write
(
response
.
getOutputStream
(),
this
.
clazz
).
sheet
(
sheetName
).
doWrite
(
data
);
}
catch
(
UnsupportedEncodingException
e
)
{
}
catch
(
UnsupportedEncodingException
e
)
{
LogUtil
.
error
(
e
.
getMessage
(),
e
);
LogUtil
.
error
(
e
.
getMessage
(),
e
);
throw
new
ExcelException
(
"Utf-8 encoding is not supported"
);
throw
new
ExcelException
(
"Utf-8 encoding is not supported"
);
...
@@ -42,7 +49,6 @@ public class EasyExcelExporter {
...
@@ -42,7 +49,6 @@ public class EasyExcelExporter {
LogUtil
.
error
(
e
.
getMessage
(),
e
);
LogUtil
.
error
(
e
.
getMessage
(),
e
);
throw
new
ExcelException
(
"IO exception"
);
throw
new
ExcelException
(
"IO exception"
);
}
}
}
}
public
void
close
()
{
public
void
close
()
{
...
...
backend/src/main/java/io/metersphere/track/service/TestCaseService.java
浏览文件 @
0fee46ce
...
@@ -221,8 +221,8 @@ public class TestCaseService {
...
@@ -221,8 +221,8 @@ public class TestCaseService {
public
void
testCaseTemplateExport
(
HttpServletResponse
response
)
{
public
void
testCaseTemplateExport
(
HttpServletResponse
response
)
{
EasyExcelExporter
easyExcelExporter
=
null
;
EasyExcelExporter
easyExcelExporter
=
null
;
try
{
try
{
easyExcelExporter
=
new
EasyExcelExporter
();
easyExcelExporter
=
new
EasyExcelExporter
(
TestCaseExcelData
.
class
);
easyExcelExporter
.
export
(
response
,
TestCaseExcelData
.
class
,
generateExportTemplate
(),
easyExcelExporter
.
export
(
response
,
generateExportTemplate
(),
Translator
.
get
(
"test_case_import_template_name"
),
Translator
.
get
(
"test_case_import_template_sheet"
));
Translator
.
get
(
"test_case_import_template_name"
),
Translator
.
get
(
"test_case_import_template_sheet"
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
MSException
.
throwException
(
e
);
MSException
.
throwException
(
e
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录