Browse Source

修复了int读取保留小数精度整数错误的问题

pull/2445/head
khw 3 years ago
parent
commit
578784e960
  1. 13
      src/main/java/com/alibaba/excel/util/NumberUtils.java
  2. 15
      src/test/java/com/alibaba/easyexcel/test/temp/issue2443/Issue2443.java
  3. 36
      src/test/java/com/alibaba/easyexcel/test/temp/issue2443/Issue2443Test.java
  4. BIN
      src/test/resources/temp/issue2443/date1.xlsx
  5. BIN
      src/test/resources/temp/issue2443/date2.xlsx

13
src/main/java/com/alibaba/excel/util/NumberUtils.java

@ -103,6 +103,19 @@ public class NumberUtils {
*/
public static Integer parseInteger(String string, ExcelContentProperty contentProperty) throws ParseException {
if (!hasFormat(contentProperty)) {
// CS304 Issue link: https://github.com/alibaba/easyexcel/issues/2443
int stringLength = string.length();
if(stringLength>0){
int pointer = stringLength;
for(int i=0;i<stringLength;i++){
if(string.charAt(i)=='.'){
pointer = i;
break;
}
}
string = string.substring(0,pointer);
}
return Integer.valueOf(string);
}
return parse(string, contentProperty).intValue();

15
src/test/java/com/alibaba/easyexcel/test/temp/issue2443/Issue2443.java

@ -0,0 +1,15 @@
package com.alibaba.easyexcel.test.temp.issue2443;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
@Getter
@Setter
@EqualsAndHashCode
public class Issue2443 {
private int a;
private int b;
}

36
src/test/java/com/alibaba/easyexcel/test/temp/issue2443/Issue2443Test.java

@ -0,0 +1,36 @@
package com.alibaba.easyexcel.test.temp.issue2443;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
@Ignore
@Slf4j
public class Issue2443Test {
//CS304 (manually written) Issue link: https://github.com/alibaba/easyexcel/issues/2443
@Test
public void IssueTest1() {
String fileName = TestFileUtil.getPath() + "temp/issue2443" + File.separator + "date1.xlsx";
EasyExcel.read(fileName, Issue2443.class, new PageReadListener<Issue2443>(dataList -> {
for (Issue2443 issueData : dataList) {
log.info("读取到一条数据{}", JSON.toJSONString(issueData));
}
})).sheet().doRead();
}
//CS304 (manually written) Issue link: https://github.com/alibaba/easyexcel/issues/2443
@Test
public void IssueTest2() {
String fileName = TestFileUtil.getPath() + "temp/issue2443" + File.separator + "date2.xlsx";
EasyExcel.read(fileName, Issue2443.class, new PageReadListener<Issue2443>(dataList -> {
for (Issue2443 issueData : dataList) {
log.info("读取到一条数据{}", JSON.toJSONString(issueData));
}
})).sheet().doRead();
}
}

BIN
src/test/resources/temp/issue2443/date1.xlsx

Binary file not shown.

BIN
src/test/resources/temp/issue2443/date2.xlsx

Binary file not shown.
Loading…
Cancel
Save