diff --git a/README.md b/README.md
index 660af477..f0ce3ad6 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ EasyExcel
# JAVA解析Excel工具EasyExcel
Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都存在一个严重的问题就是非常的耗内存,poi有一套SAX模式的API可以一定程度的解决一些内存溢出的问题,但POI还是有一些缺陷,比如07版Excel解压缩以及解压后存储都是在内存中完成的,内存消耗依然很大。easyexcel重写了poi对07版Excel的解析,一个3M的excel用POI sax解析依然需要100M左右内存,改用easyexcel可以降低到几M,并且再大的excel也不会出现内存溢出;03版依赖POI的sax模式,在上层做了模型转换的封装,让使用者更加简单方便
-## 64M内存1分钟内读取75M(46W行25列)的Excel
+## 64M内存20秒内读取75M(46W行25列)的Excel(3.0.2+版本)
当然还有极速模式能更快,但是内存占用会在100M多一点
![img](img/readme/large.png)
@@ -41,7 +41,7 @@ Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都
com.alibaba
easyexcel
- 3.0.1
+ 3.0.2
```
diff --git a/img/readme/large.png b/img/readme/large.png
index 04195a10..48223c56 100644
Binary files a/img/readme/large.png and b/img/readme/large.png differ
diff --git a/pom.xml b/pom.xml
index 66331d1b..00bae497 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.alibaba
easyexcel
- 3.0.1
+ 3.0.2
jar
easyexcel
diff --git a/src/main/java/com/alibaba/excel/metadata/format/DataFormatter.java b/src/main/java/com/alibaba/excel/metadata/format/DataFormatter.java
index bf76404f..ba8fee47 100644
--- a/src/main/java/com/alibaba/excel/metadata/format/DataFormatter.java
+++ b/src/main/java/com/alibaba/excel/metadata/format/DataFormatter.java
@@ -111,6 +111,8 @@ public class DataFormatter {
*/
private static final Pattern alternateGrouping = Pattern.compile("([#0]([^.#0])[#0]{3})");
+ private static final Pattern E_NOTATION_PATTERN = Pattern.compile("E(\\d)");
+
/**
* Cells formatted with a date or time format and which contain invalid date or time values show 255 pound signs
* ("#").
@@ -644,8 +646,7 @@ public class DataFormatter {
*/
private String getFormattedNumberString(BigDecimal data, Short dataFormat, String dataFormatString) {
Format numberFormat = getFormat(data.doubleValue(), dataFormat, dataFormatString);
- String formatted = numberFormat.format(data);
- return formatted.replaceFirst("E(\\d)", "E+$1"); // to match Excel's E-notation
+ return E_NOTATION_PATTERN.matcher(numberFormat.format(data)).replaceFirst("E+$1");
}
/**
diff --git a/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java
index c34990fc..a438a2ee 100644
--- a/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java
+++ b/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java
@@ -32,6 +32,7 @@ public class LargeDataTest {
private static File template07;
private static File fileCsv;
private static File fileWrite07;
+ private static File fileWriteTemp07;
private static File fileWritePoi07;
private int i = 0;
@@ -40,14 +41,14 @@ public class LargeDataTest {
public static void init() {
fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx");
fileWrite07 = TestFileUtil.createNewFile("large" + File.separator + "fileWrite07.xlsx");
+ fileWriteTemp07 = TestFileUtil.createNewFile("large" + File.separator + "fileWriteTemp07.xlsx");
fileWritePoi07 = TestFileUtil.createNewFile("large" + File.separator + "fileWritePoi07.xlsx");
template07 = TestFileUtil.readFile("large" + File.separator + "fill.xlsx");
fileCsv = TestFileUtil.createNewFile("largefileCsv.csv");
}
@Test
- public void t01Read() throws Exception{
- Thread.sleep(10*1000L);
+ public void t01Read() throws Exception {
long start = System.currentTimeMillis();
EasyExcel.read(TestFileUtil.getPath() + "large" + File.separator + "large07.xlsx", LargeData.class,
new LargeDataListener()).headRowNumber(2).sheet().doRead();
@@ -86,9 +87,16 @@ public class LargeDataTest {
@Test
public void t04Write() throws Exception {
- long start = System.currentTimeMillis();
- ExcelWriter excelWriter = EasyExcel.write(fileWrite07, LargeData.class).build();
+ ExcelWriter excelWriter = EasyExcel.write(fileWriteTemp07, LargeData.class).build();
WriteSheet writeSheet = EasyExcel.writerSheet().build();
+ for (int j = 0; j < 2; j++) {
+ excelWriter.write(data(), writeSheet);
+ }
+ excelWriter.finish();
+
+ long start = System.currentTimeMillis();
+ excelWriter = EasyExcel.write(fileWrite07, LargeData.class).build();
+ writeSheet = EasyExcel.writerSheet().build();
for (int j = 0; j < 100; j++) {
excelWriter.write(data(), writeSheet);
LOGGER.info("{} write success.", j);
@@ -116,7 +124,8 @@ public class LargeDataTest {
}
long costPoi = System.currentTimeMillis() - start;
LOGGER.info("poi write cost:{}", System.currentTimeMillis() - start);
- Assert.assertTrue(costPoi * 3 > cost);
+ LOGGER.info("{} vs {}", cost, costPoi);
+ Assert.assertTrue(costPoi * 2 > cost);
}
private List data() {
diff --git a/update.md b/update.md
index 6cc837de..5d1f724c 100644
--- a/update.md
+++ b/update.md
@@ -1,5 +1,5 @@
# 3.0.2
-* 修复写入的性能问题
+* 大幅提升读写性能
# 3.0.1
* 升级到正式版