Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
不停的脚步
easyexcel
提交
da2182de
E
easyexcel
项目概览
不停的脚步
/
easyexcel
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
easyexcel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
da2182de
编写于
10月 23, 2019
作者:
庄家钜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改读错别字
上级
8515b60c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
17 deletion
+17
-17
src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
...java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
+17
-17
未找到文件。
src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
浏览文件 @
da2182de
...
...
@@ -50,13 +50,13 @@ public class WriteTest {
public
void
simpleWrite
()
{
// 写法1
String
fileName
=
TestFileUtil
.
getPath
()
+
"simpleWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 如果这里想使用03 则 传入excelType参数即可
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
sheet
(
"模板"
).
doWrite
(
data
());
// 写法2
fileName
=
TestFileUtil
.
getPath
()
+
"simpleWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去
读
// 这里 需要指定写用哪个class去
写
ExcelWriter
excelWriter
=
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
build
();
WriteSheet
writeSheet
=
EasyExcel
.
writerSheet
(
"模板"
).
build
();
excelWriter
.
write
(
data
(),
writeSheet
);
...
...
@@ -80,7 +80,7 @@ public class WriteTest {
// 根据用户传入字段 假设我们要忽略 date
Set
<
String
>
excludeColumnFiledNames
=
new
HashSet
<
String
>();
excludeColumnFiledNames
.
add
(
"date"
);
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
excludeColumnFiledNames
(
excludeColumnFiledNames
).
sheet
(
"模板"
)
.
doWrite
(
data
());
...
...
@@ -88,7 +88,7 @@ public class WriteTest {
// 根据用户传入字段 假设我们只要导出 date
Set
<
String
>
includeColumnFiledNames
=
new
HashSet
<
String
>();
includeColumnFiledNames
.
add
(
"date"
);
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
includeColumnFiledNames
(
includeColumnFiledNames
).
sheet
(
"模板"
)
.
doWrite
(
data
());
}
...
...
@@ -105,7 +105,7 @@ public class WriteTest {
@Test
public
void
indexWrite
()
{
String
fileName
=
TestFileUtil
.
getPath
()
+
"indexWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
IndexData
.
class
).
sheet
(
"模板"
).
doWrite
(
data
());
}
...
...
@@ -121,7 +121,7 @@ public class WriteTest {
@Test
public
void
complexHeadWrite
()
{
String
fileName
=
TestFileUtil
.
getPath
()
+
"complexHeadWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
ComplexHeadData
.
class
).
sheet
(
"模板"
).
doWrite
(
data
());
}
...
...
@@ -138,7 +138,7 @@ public class WriteTest {
public
void
repeatedWrite
()
{
// 方法1 如果写到同一个sheet
String
fileName
=
TestFileUtil
.
getPath
()
+
"repeatedWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去
读
// 这里 需要指定写用哪个class去
写
ExcelWriter
excelWriter
=
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
build
();
// 这里注意 如果同一个sheet只要创建一次
WriteSheet
writeSheet
=
EasyExcel
.
writerSheet
(
"模板"
).
build
();
...
...
@@ -194,7 +194,7 @@ public class WriteTest {
@Test
public
void
converterWrite
()
{
String
fileName
=
TestFileUtil
.
getPath
()
+
"converterWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
ConverterData
.
class
).
sheet
(
"模板"
).
doWrite
(
data
());
}
...
...
@@ -236,7 +236,7 @@ public class WriteTest {
* <p>
* 2. 使用{@link ExcelProperty}注解指定写入的列
* <p>
* 3. 使用withTemplate
读
取模板
* 3. 使用withTemplate
写
取模板
* <p>
* 4. 直接写即可
*/
...
...
@@ -244,7 +244,7 @@ public class WriteTest {
public
void
templateWrite
()
{
String
templateFileName
=
TestFileUtil
.
getPath
()
+
"demo"
+
File
.
separator
+
"demo.xlsx"
;
String
fileName
=
TestFileUtil
.
getPath
()
+
"templateWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
withTemplate
(
templateFileName
).
sheet
().
doWrite
(
data
());
}
...
...
@@ -260,7 +260,7 @@ public class WriteTest {
@Test
public
void
widthAndHeightWrite
()
{
String
fileName
=
TestFileUtil
.
getPath
()
+
"widthAndHeightWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
WidthAndHeightData
.
class
).
sheet
(
"模板"
).
doWrite
(
data
());
}
...
...
@@ -297,7 +297,7 @@ public class WriteTest {
HorizontalCellStyleStrategy
horizontalCellStyleStrategy
=
new
HorizontalCellStyleStrategy
(
headWriteCellStyle
,
contentWriteCellStyle
);
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
registerWriteHandler
(
horizontalCellStyleStrategy
).
sheet
(
"模板"
)
.
doWrite
(
data
());
}
...
...
@@ -316,7 +316,7 @@ public class WriteTest {
String
fileName
=
TestFileUtil
.
getPath
()
+
"mergeWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 每隔2行会合并 把eachColumn 设置成 3 也就是我们数据的长度,所以就第一列会合并。当然其他合并策略也可以自己写
LoopMergeStrategy
loopMergeStrategy
=
new
LoopMergeStrategy
(
2
,
0
);
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
registerWriteHandler
(
loopMergeStrategy
).
sheet
(
"模板"
).
doWrite
(
data
());
}
...
...
@@ -331,7 +331,7 @@ public class WriteTest {
public
void
tableWrite
()
{
String
fileName
=
TestFileUtil
.
getPath
()
+
"tableWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里直接写多个table的案例了,如果只有一个 也可以直一行代码搞定,参照其他案例
// 这里 需要指定写用哪个class去
读
// 这里 需要指定写用哪个class去
写
ExcelWriter
excelWriter
=
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
build
();
// 把sheet设置为不需要头 不然会输出sheet的头 这样看起来第一个table 就有2个头了
WriteSheet
writeSheet
=
EasyExcel
.
writerSheet
(
"模板"
).
needHead
(
Boolean
.
FALSE
).
build
();
...
...
@@ -385,7 +385,7 @@ public class WriteTest {
public
void
longestMatchColumnWidthWrite
()
{
String
fileName
=
TestFileUtil
.
getPath
()
+
"longestMatchColumnWidthWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
LongestMatchColumnWidthData
.
class
)
.
registerWriteHandler
(
new
LongestMatchColumnWidthStyleStrategy
()).
sheet
(
"模板"
).
doWrite
(
dataLong
());
}
...
...
@@ -404,7 +404,7 @@ public class WriteTest {
@Test
public
void
customHandlerWrite
()
{
String
fileName
=
TestFileUtil
.
getPath
()
+
"customHandlerWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
registerWriteHandler
(
new
CustomSheetWriteHandler
())
.
registerWriteHandler
(
new
CustomCellWriteHandler
()).
sheet
(
"模板"
).
doWrite
(
data
());
}
...
...
@@ -416,7 +416,7 @@ public class WriteTest {
public
void
noModleWrite
()
{
// 写法1
String
fileName
=
TestFileUtil
.
getPath
()
+
"noModleWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去
读
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 这里 需要指定写用哪个class去
写
,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
).
head
(
head
()).
sheet
(
"模板"
).
doWrite
(
dataList
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录