Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_879456671
easyexcel
提交
cf40b873
E
easyexcel
项目概览
qq_879456671
/
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,发现更多精彩内容 >>
提交
cf40b873
编写于
6月 09, 2020
作者:
庄家钜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复`@NumberFormat`注解转换double时可能会丢失精度 #1306
上级
9d60fa67
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
42 addition
and
15 deletion
+42
-15
src/main/java/com/alibaba/excel/context/WriteContextImpl.java
...main/java/com/alibaba/excel/context/WriteContextImpl.java
+2
-2
src/main/java/com/alibaba/excel/util/NumberUtils.java
src/main/java/com/alibaba/excel/util/NumberUtils.java
+1
-0
src/test/java/com/alibaba/easyexcel/test/temp/FillTempTest.java
...st/java/com/alibaba/easyexcel/test/temp/FillTempTest.java
+11
-5
src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
+12
-2
src/test/java/com/alibaba/easyexcel/test/temp/LockData.java
src/test/java/com/alibaba/easyexcel/test/temp/LockData.java
+4
-1
src/test/java/com/alibaba/easyexcel/test/temp/LockDataListener.java
...ava/com/alibaba/easyexcel/test/temp/LockDataListener.java
+3
-3
src/test/java/com/alibaba/easyexcel/test/temp/WriteV33Test.java
...st/java/com/alibaba/easyexcel/test/temp/WriteV33Test.java
+4
-1
src/test/java/com/alibaba/easyexcel/test/temp/simple/Wirte.java
...st/java/com/alibaba/easyexcel/test/temp/simple/Wirte.java
+1
-0
src/test/java/com/alibaba/easyexcel/test/temp/simple/WriteData.java
...ava/com/alibaba/easyexcel/test/temp/simple/WriteData.java
+3
-1
update.md
update.md
+1
-0
未找到文件。
src/main/java/com/alibaba/excel/context/WriteContextImpl.java
浏览文件 @
cf40b873
...
...
@@ -124,8 +124,8 @@ public class WriteContextImpl implements WriteContext {
private
boolean
selectSheetFromCache
(
WriteSheet
writeSheet
)
{
writeSheetHolder
=
null
;
Integer
sheetNo
=
null
;
if
(
writeSheet
.
getSheetNo
()
==
null
&&
StringUtils
.
isEmpty
(
writeSheet
.
getSheetName
()))
{
Integer
sheetNo
=
writeSheet
.
getSheetNo
()
;
if
(
sheetNo
==
null
&&
StringUtils
.
isEmpty
(
writeSheet
.
getSheetName
()))
{
sheetNo
=
0
;
}
if
(
sheetNo
!=
null
)
{
...
...
src/main/java/com/alibaba/excel/util/NumberUtils.java
浏览文件 @
cf40b873
...
...
@@ -167,6 +167,7 @@ public class NumberUtils {
RoundingMode
roundingMode
=
contentProperty
.
getNumberFormatProperty
().
getRoundingMode
();
DecimalFormat
decimalFormat
=
new
DecimalFormat
(
format
);
decimalFormat
.
setRoundingMode
(
roundingMode
);
decimalFormat
.
setParseBigDecimal
(
true
);
return
decimalFormat
.
parse
(
string
);
}
}
src/test/java/com/alibaba/easyexcel/test/temp/FillTempTest.java
浏览文件 @
cf40b873
...
...
@@ -13,6 +13,7 @@ import com.alibaba.easyexcel.test.temp.fill.FillData2;
import
com.alibaba.easyexcel.test.util.TestFileUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.ExcelWriter
;
import
com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy
;
import
com.alibaba.excel.write.metadata.WriteSheet
;
/**
...
...
@@ -33,16 +34,21 @@ public class FillTempTest {
public
void
complexFill
()
{
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
// {} 代表普通变量 {.} 代表是list的变量
String
templateFileName
=
"D:\\test\\simple.xlsx"
;
OnceAbsoluteMergeStrategy
onceAbsoluteMergeStrategy
=
new
OnceAbsoluteMergeStrategy
(
2
,
2
,
0
,
1
)
;
String
fileName
=
TestFileUtil
.
getPath
()
+
"complexFill"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
ExcelWriter
excelWriter
=
EasyExcel
.
write
(
fileName
).
withTemplate
(
templateFileName
).
build
();
WriteSheet
writeSheet
=
EasyExcel
.
writerSheet
().
build
();
excelWriter
.
fill
(
teamp
(),
writeSheet
);
ExcelWriter
excelWriter
=
EasyExcel
.
write
(
fileName
).
registerWriteHandler
(
onceAbsoluteMergeStrategy
).
withTemplate
(
TestFileUtil
.
readUserHomeFile
(
"test/simple.xlsx"
)).
build
();
WriteSheet
writeSheet0
=
EasyExcel
.
writerSheet
(
0
).
build
();
WriteSheet
writeSheet1
=
EasyExcel
.
writerSheet
(
1
).
build
();
excelWriter
.
fill
(
teamp
(),
writeSheet0
);
excelWriter
.
fill
(
teamp
(),
writeSheet1
);
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"date"
,
"2019年10月9日13:28:28"
);
map
.
put
(
"total"
,
1000
);
excelWriter
.
fill
(
map
,
writeSheet
);
excelWriter
.
fill
(
map
,
writeSheet0
);
excelWriter
.
finish
();
}
...
...
src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
浏览文件 @
cf40b873
...
...
@@ -28,6 +28,7 @@ import com.alibaba.fastjson.JSON;
**/
@Ignore
public
class
Lock2Test
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
Lock2Test
.
class
);
@Test
...
...
@@ -41,6 +42,15 @@ public class Lock2Test {
}
}
@Test
public
void
test33
()
throws
Exception
{
File
file
=
TestFileUtil
.
readUserHomeFile
(
"test/test6.xlsx"
);
EasyExcel
.
read
(
file
,
LockData
.
class
,
new
LockDataListener
()).
sheet
(
0
).
headRowNumber
(
0
)
.
doRead
();
}
@Test
public
void
write
()
throws
Exception
{
String
fileName
=
TestFileUtil
.
getPath
()
+
"styleWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
...
...
@@ -49,7 +59,7 @@ public class Lock2Test {
// 背景设置为红色
headWriteCellStyle
.
setFillForegroundColor
(
IndexedColors
.
RED
.
getIndex
());
WriteFont
headWriteFont
=
new
WriteFont
();
headWriteFont
.
setFontHeightInPoints
((
short
)
20
);
headWriteFont
.
setFontHeightInPoints
((
short
)
20
);
headWriteCellStyle
.
setWriteFont
(
headWriteFont
);
// 内容的策略
WriteCellStyle
contentWriteCellStyle
=
new
WriteCellStyle
();
...
...
@@ -59,7 +69,7 @@ public class Lock2Test {
contentWriteCellStyle
.
setFillForegroundColor
(
IndexedColors
.
GREEN
.
getIndex
());
WriteFont
contentWriteFont
=
new
WriteFont
();
// 字体大小
contentWriteFont
.
setFontHeightInPoints
((
short
)
20
);
contentWriteFont
.
setFontHeightInPoints
((
short
)
20
);
contentWriteCellStyle
.
setWriteFont
(
contentWriteFont
);
// 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
HorizontalCellStyleStrategy
horizontalCellStyleStrategy
=
...
...
src/test/java/com/alibaba/easyexcel/test/temp/LockData.java
浏览文件 @
cf40b873
package
com.alibaba.easyexcel.test.temp
;
import
com.alibaba.excel.annotation.format.NumberFormat
;
import
lombok.Data
;
/**
...
...
@@ -9,7 +11,8 @@ import lombok.Data;
**/
@Data
public
class
LockData
{
private
String
string0
;
@NumberFormat
(
"#.##%"
)
private
Double
string0
;
private
String
string1
;
private
String
string2
;
private
String
string3
;
...
...
src/test/java/com/alibaba/easyexcel/test/temp/LockDataListener.java
浏览文件 @
cf40b873
...
...
@@ -18,16 +18,16 @@ import com.alibaba.fastjson.JSON;
*
* @author Jiaju Zhuang
*/
public
class
LockDataListener
extends
AnalysisEventListener
<
Map
<
Integer
,
CellData
>
>
{
public
class
LockDataListener
extends
AnalysisEventListener
<
LockData
>
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DemoDataListener
.
class
);
/**
* 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
*/
private
static
final
int
BATCH_COUNT
=
5
;
List
<
Map
<
Integer
,
CellData
>>
list
=
new
ArrayList
<
Map
<
Integer
,
CellData
>
>();
List
<
LockData
>
list
=
new
ArrayList
<
LockData
>();
@Override
public
void
invoke
(
Map
<
Integer
,
CellData
>
data
,
AnalysisContext
context
)
{
public
void
invoke
(
LockData
data
,
AnalysisContext
context
)
{
LOGGER
.
info
(
"解析到一条数据:{}"
,
JSON
.
toJSONString
(
data
));
list
.
add
(
data
);
if
(
list
.
size
()
>=
BATCH_COUNT
)
{
...
...
src/test/java/com/alibaba/easyexcel/test/temp/WriteV33Test.java
浏览文件 @
cf40b873
...
...
@@ -17,6 +17,7 @@ import com.alibaba.easyexcel.test.demo.write.DemoData;
import
com.alibaba.easyexcel.test.util.TestFileUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.ExcelWriter
;
import
com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy
;
import
com.alibaba.excel.write.metadata.WriteSheet
;
import
com.alibaba.excel.write.metadata.style.WriteCellStyle
;
import
com.alibaba.excel.write.metadata.style.WriteFont
;
...
...
@@ -37,8 +38,10 @@ public class WriteV33Test {
public
void
test
()
throws
Exception
{
// 方法2 如果写到不同的sheet 同一个对象
String
fileName
=
TestFileUtil
.
getPath
()
+
"repeatedWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
OnceAbsoluteMergeStrategy
onceAbsoluteMergeStrategy
=
new
OnceAbsoluteMergeStrategy
(
2
,
2
,
0
,
1
);
// 这里 指定文件
ExcelWriter
excelWriter
=
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
build
();
ExcelWriter
excelWriter
=
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
registerWriteHandler
(
onceAbsoluteMergeStrategy
).
build
();
WriteSheet
writeSheet1
=
EasyExcel
.
writerSheet
(
1
,
"模板1"
).
build
();
WriteSheet
writeSheet2
=
EasyExcel
.
writerSheet
(
2
,
"模板2"
).
build
();
WriteSheet
writeSheet3
=
EasyExcel
.
writerSheet
(
3
,
"模板3"
).
build
();
...
...
src/test/java/com/alibaba/easyexcel/test/temp/simple/Wirte.java
浏览文件 @
cf40b873
...
...
@@ -126,6 +126,7 @@ public class Wirte {
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
WriteData
data
=
new
WriteData
();
data
.
setF
(
300.35f
);
data
.
setF1
(
33
f
);
list
.
add
(
data
);
}
return
list
;
...
...
src/test/java/com/alibaba/easyexcel/test/temp/simple/WriteData.java
浏览文件 @
cf40b873
...
...
@@ -11,6 +11,8 @@ import lombok.Data;
**/
@Data
public
class
WriteData
{
@ContentStyle
(
locked
=
true
)
//
@ContentStyle(locked = true)
private
float
f
;
// @ContentStyle(locked = false)
private
float
f1
;
}
update.md
浏览文件 @
cf40b873
...
...
@@ -9,6 +9,7 @@
*
修复xls直接读取第2页
`NPE`
的bug
[
Issue #1280
](
https://github.com/alibaba/easyexcel/issues/1280
)
*
修复填充的时候,最后一行中间有空行会创建失败的bug
*
修复
`includeColumnIndexes`
不包含第列 会无法导出数据的bug
[
Issue #1346
](
https://github.com/alibaba/easyexcel/issues/1346
)
*
修复
`@NumberFormat`
注解转换double时可能会丢失精度
[
Issue #1306
](
https://github.com/alibaba/easyexcel/issues/1306
)
# 2.2.3
*
修改填充数据空数据的bug
[
Issue #1274
](
https://github.com/alibaba/easyexcel/issues/1274
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录