diff --git a/README.md b/README.md
index f82ffa43..c0401aea 100644
--- a/README.md
+++ b/README.md
@@ -4,13 +4,14 @@ EasyExcel
[![Maven central](https://maven-badges.herokuapp.com/maven-central/com.alibaba/easyexcel/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.alibaba/easyexcel)
[![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)
-[QQ1群(已满): 662022184](https://jq.qq.com/?_wv=1027&k=1T21jJxh)
-[QQ2群: 1097936804](https://jq.qq.com/?_wv=1027&k=j5zEy6Xl)
-[钉钉1群(已满): 21960511](https://qr.dingtalk.com/action/joingroup?code=v1,k1,cchz6k12ci9B08NNqhNRFGXocNVHrZtW0kaOtTKg/Rk=&_dt_no_comment=1&origin=11)
-[钉钉2群(已满): 32796397](https://qr.dingtalk.com/action/joingroup?code=v1,k1,jyU9GtEuNU5S0QTyklqYcYJ8qDZtUuTPMM7uPZTS8Hs=&_dt_no_comment=1&origin=11)
-[钉钉3群(已满): 33797247](https://qr.dingtalk.com/action/joingroup?code=v1,k1,3UGlEScTGQaHpW2cIRo+gkxJ9EVZ5fz26M6nW3uFP30=&_dt_no_comment=1&origin=11)
-[钉钉4群: 33491624](https://qr.dingtalk.com/action/joingroup?code=v1,k1,V14Pb65Too70rQkEaJ9ohb6lZBZbtp6jIL/q9EWh9vA=&_dt_no_comment=1&origin=11)
-[官方网站: https://yuque.com/easyexcel](https://www.yuque.com/easyexcel/doc/easyexcel)
+[QQ1群(已满): 662022184](https://jq.qq.com/?_wv=1027&k=1T21jJxh)
+[QQ2群(已满): 1097936804](https://jq.qq.com/?_wv=1027&k=j5zEy6Xl)
+[QQ3群: 453928496](https://qm.qq.com/cgi-bin/qm/qr?k=e2ULsA5A0GldhV2CXJ8sIbAyu9I6qqs7&jump_from=webapi)
+[钉钉1群(已满): 21960511](https://qr.dingtalk.com/action/joingroup?code=v1,k1,cchz6k12ci9B08NNqhNRFGXocNVHrZtW0kaOtTKg/Rk=&_dt_no_comment=1&origin=11)
+[钉钉2群(已满): 32796397](https://qr.dingtalk.com/action/joingroup?code=v1,k1,jyU9GtEuNU5S0QTyklqYcYJ8qDZtUuTPMM7uPZTS8Hs=&_dt_no_comment=1&origin=11)
+[钉钉3群(已满): 33797247](https://qr.dingtalk.com/action/joingroup?code=v1,k1,3UGlEScTGQaHpW2cIRo+gkxJ9EVZ5fz26M6nW3uFP30=&_dt_no_comment=1&origin=11)
+[钉钉4群: 33491624](https://qr.dingtalk.com/action/joingroup?code=v1,k1,V14Pb65Too70rQkEaJ9ohb6lZBZbtp6jIL/q9EWh9vA=&_dt_no_comment=1&origin=11)
+[官方网站: https://yuque.com/easyexcel](https://www.yuque.com/easyexcel/doc/easyexcel)
[常见问题](https://www.yuque.com/easyexcel/faq)
#### 因为公司不方便用QQ,所以建议加钉钉群
diff --git a/pom.xml b/pom.xml
index 641dd476..9f1a4c72 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.alibaba
easyexcel
- 2.2.7
+ 2.2.10
jar
easyexcel
diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/AbstractCellValueTagHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/AbstractCellValueTagHandler.java
index 3521e46a..580e6704 100644
--- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/AbstractCellValueTagHandler.java
+++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/AbstractCellValueTagHandler.java
@@ -7,6 +7,7 @@ import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.read.metadata.holder.xlsx.XlsxReadSheetHolder;
import com.alibaba.excel.util.BooleanUtils;
+import com.alibaba.excel.util.StringUtils;
/**
* Cell Value Handler
@@ -20,6 +21,7 @@ public abstract class AbstractCellValueTagHandler extends AbstractXlsxTagHandler
XlsxReadSheetHolder xlsxReadSheetHolder = xlsxReadContext.xlsxReadSheetHolder();
CellData tempCellData = xlsxReadSheetHolder.getTempCellData();
StringBuilder tempData = xlsxReadSheetHolder.getTempData();
+ String tempDataString = tempData.toString();
CellDataTypeEnum oldType = tempCellData.getType();
switch (oldType) {
case DIRECT_STRING:
@@ -28,12 +30,20 @@ public abstract class AbstractCellValueTagHandler extends AbstractXlsxTagHandler
tempCellData.setStringValue(tempData.toString());
break;
case BOOLEAN:
+ if(StringUtils.isEmpty(tempDataString)){
+ tempCellData.setType(CellDataTypeEnum.EMPTY);
+ break;
+ }
tempCellData.setBooleanValue(BooleanUtils.valueOf(tempData.toString()));
break;
case NUMBER:
case EMPTY:
+ if(StringUtils.isEmpty(tempDataString)){
+ tempCellData.setType(CellDataTypeEnum.EMPTY);
+ break;
+ }
tempCellData.setType(CellDataTypeEnum.NUMBER);
- tempCellData.setNumberValue(new BigDecimal(tempData.toString()));
+ tempCellData.setNumberValue(BigDecimal.valueOf(Double.parseDouble(tempDataString)));
break;
default:
throw new IllegalStateException("Cannot set values now");
diff --git a/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellValueTagHandler.java b/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellValueTagHandler.java
index 09c9264e..7e685c97 100644
--- a/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellValueTagHandler.java
+++ b/src/main/java/com/alibaba/excel/analysis/v07/handlers/CellValueTagHandler.java
@@ -3,6 +3,7 @@ package com.alibaba.excel.analysis.v07.handlers;
import com.alibaba.excel.context.xlsx.XlsxReadContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
+import com.alibaba.excel.util.StringUtils;
/**
* Cell Value Handler
@@ -17,6 +18,10 @@ public class CellValueTagHandler extends AbstractCellValueTagHandler {
CellData tempCellData = xlsxReadContext.xlsxReadSheetHolder().getTempCellData();
switch (tempCellData.getType()) {
case STRING:
+ // In some cases, although cell type is a string, it may be an empty tag
+ if(StringUtils.isEmpty(tempCellData.getStringValue())){
+ break;
+ }
String stringValue = xlsxReadContext.readWorkbookHolder().getReadCache()
.get(Integer.valueOf(tempCellData.getStringValue()));
if (stringValue != null && xlsxReadContext.currentReadHolder().globalConfiguration().getAutoTrim()) {
diff --git a/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java b/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java
index b31bc706..693c1120 100644
--- a/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java
+++ b/src/main/java/com/alibaba/excel/converters/string/StringNumberConverter.java
@@ -47,7 +47,7 @@ public class StringNumberConverter implements Converter {
}
// Excel defines formatting
if (cellData.getDataFormat() != null && !StringUtils.isEmpty(cellData.getDataFormatString())) {
- return NumberDataFormatterUtils.format(cellData.getNumberValue().doubleValue(), cellData.getDataFormat(),
+ return NumberDataFormatterUtils.format(cellData.getNumberValue(), cellData.getDataFormat(),
cellData.getDataFormatString(), globalConfiguration);
}
// Default conversion number
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 be9d2ad6..2c955ed1 100644
--- a/src/main/java/com/alibaba/excel/metadata/format/DataFormatter.java
+++ b/src/main/java/com/alibaba/excel/metadata/format/DataFormatter.java
@@ -630,8 +630,8 @@ public class DataFormatter {
* @param dataFormatString
* @return a formatted number string
*/
- private String getFormattedNumberString(Double data, Integer dataFormat, String dataFormatString) {
- Format numberFormat = getFormat(data, dataFormat, dataFormatString);
+ private String getFormattedNumberString(BigDecimal data, Integer 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
}
@@ -644,9 +644,9 @@ public class DataFormatter {
* @param dataFormatString
* @return
*/
- public String format(Double data, Integer dataFormat, String dataFormatString) {
+ public String format(BigDecimal data, Integer dataFormat, String dataFormatString) {
if (DateUtils.isADateFormat(dataFormat, dataFormatString)) {
- return getFormattedDateString(data, dataFormat, dataFormatString);
+ return getFormattedDateString(data.doubleValue(), dataFormat, dataFormatString);
}
return getFormattedNumberString(data, dataFormat, dataFormatString);
}
diff --git a/src/main/java/com/alibaba/excel/util/NumberDataFormatterUtils.java b/src/main/java/com/alibaba/excel/util/NumberDataFormatterUtils.java
index 09d149b6..b4ba5b02 100644
--- a/src/main/java/com/alibaba/excel/util/NumberDataFormatterUtils.java
+++ b/src/main/java/com/alibaba/excel/util/NumberDataFormatterUtils.java
@@ -1,5 +1,7 @@
package com.alibaba.excel.util;
+import java.math.BigDecimal;
+
import com.alibaba.excel.metadata.format.DataFormatter;
import com.alibaba.excel.metadata.GlobalConfiguration;
@@ -24,7 +26,7 @@ public class NumberDataFormatterUtils {
* @param globalConfiguration
* @return
*/
- public static String format(Double data, Integer dataFormat, String dataFormatString,
+ public static String format(BigDecimal data, Integer dataFormat, String dataFormatString,
GlobalConfiguration globalConfiguration) {
DataFormatter dataFormatter = DATA_FORMATTER_THREAD_LOCAL.get();
if (dataFormatter == null) {
diff --git a/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java b/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java
index f1de5428..d0c308aa 100644
--- a/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java
+++ b/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java
@@ -4,17 +4,16 @@ import java.io.File;
import java.util.List;
import java.util.Locale;
+import com.alibaba.easyexcel.test.util.TestFileUtil;
+import com.alibaba.excel.EasyExcel;
+
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.alibaba.easyexcel.test.util.TestFileUtil;
-import com.alibaba.excel.EasyExcel;
-
/**
- *
* @author Jiaju Zhuang
*/
public class DateFormatTest {
@@ -44,6 +43,14 @@ public class DateFormatTest {
private void readCn(File file) {
List list =
EasyExcel.read(file, DateFormatData.class, null).locale(Locale.CHINA).sheet().doReadSync();
+ for (DateFormatData data : list) {
+ if (data.getDateStringCn() != null && !data.getDateStringCn().equals(data.getDate())) {
+ LOGGER.info("date:cn:{},{}", data.getDateStringCn(), data.getDate());
+ }
+ if (data.getNumberStringCn() != null && !data.getNumberStringCn().equals(data.getNumber())) {
+ LOGGER.info("number:cn{},{}", data.getNumberStringCn(), data.getNumber());
+ }
+ }
for (DateFormatData data : list) {
Assert.assertEquals(data.getDateStringCn(), data.getDate());
Assert.assertEquals(data.getNumberStringCn(), data.getNumber());
@@ -53,6 +60,14 @@ public class DateFormatTest {
private void readUs(File file) {
List list =
EasyExcel.read(file, DateFormatData.class, null).locale(Locale.US).sheet().doReadSync();
+ for (DateFormatData data : list) {
+ if (data.getDateStringUs() != null && !data.getDateStringUs().equals(data.getDate())) {
+ LOGGER.info("date:us:{},{}", data.getDateStringUs(), data.getDate());
+ }
+ if (data.getNumberStringUs() != null && !data.getNumberStringUs().equals(data.getNumber())) {
+ LOGGER.info("number:us{},{}", data.getNumberStringUs(), data.getNumber());
+ }
+ }
for (DateFormatData data : list) {
Assert.assertEquals(data.getDateStringUs(), data.getDate());
Assert.assertEquals(data.getNumberStringUs(), data.getNumber());
diff --git a/src/test/java/com/alibaba/easyexcel/test/core/encrypt/EncryptDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/encrypt/EncryptDataTest.java
index 375f9bea..b7f63cf0 100644
--- a/src/test/java/com/alibaba/easyexcel/test/core/encrypt/EncryptDataTest.java
+++ b/src/test/java/com/alibaba/easyexcel/test/core/encrypt/EncryptDataTest.java
@@ -3,21 +3,23 @@ package com.alibaba.easyexcel.test.core.encrypt;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
import com.alibaba.easyexcel.test.core.simple.SimpleData;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
/**
- *
* @author Jiaju Zhuang
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@@ -28,6 +30,15 @@ public class EncryptDataTest {
private static File file07OutputStream;
private static File file03OutputStream;
+ @Test
+ public void testformat() {
+ DecimalFormat decimalFormat = new DecimalFormat("0.00");
+ decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
+ BigDecimal bigDecimal = new BigDecimal("0.105");
+
+ System.out.println(decimalFormat.format(bigDecimal));
+ }
+
@BeforeClass
public static void init() {
file07 = TestFileUtil.createNewFile("encrypt07.xlsx");
diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java b/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
index 938e031b..92202642 100644
--- a/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
+++ b/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java
@@ -34,7 +34,7 @@ public class Lock2Test {
@Test
public void test() throws Exception {
// File file = TestFileUtil.readUserHomeFile("test/test6.xls");
- File file = new File("D:\\test\\T85_税金入库表202010.xlsx");
+ File file = new File("/Users/zhuangjiaju/test/签到金模板-0507-v5.xlsx");
List