mirror of https://github.com/alibaba/easyexcel
Browse Source
* 修复部分数据精度和excel不匹配的bug [Issue #2805](https://github.com/alibaba/easyexcel/issues/2805) * 不创建对象的读支持读取非`String`类型的数据pull/2927/head
Jiaju Zhuang
2 years ago
29 changed files with 598 additions and 49 deletions
@ -0,0 +1,19 @@
|
||||
package com.alibaba.excel.constant; |
||||
|
||||
import java.math.MathContext; |
||||
import java.math.RoundingMode; |
||||
|
||||
/** |
||||
* Used to store constant |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public class EasyExcelConstants { |
||||
|
||||
/** |
||||
* Excel by default with 15 to store Numbers, and the double in Java can use to store number 17, led to the accuracy |
||||
* will be a problem. So you need to set up 15 to deal with precision |
||||
*/ |
||||
public static final MathContext EXCEL_MATH_CONTEXT = new MathContext(15, RoundingMode.HALF_UP); |
||||
|
||||
} |
@ -0,0 +1,40 @@
|
||||
package com.alibaba.excel.enums; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.time.LocalDateTime; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import com.alibaba.excel.metadata.data.CellData; |
||||
import com.alibaba.excel.util.StringUtils; |
||||
|
||||
/** |
||||
* Read not to {@code com.alibaba.excel.metadata.BasicParameter#clazz} value, the default will return type. |
||||
* |
||||
* @author Jiaju Zhuang |
||||
*/ |
||||
public enum ReadDefaultReturnEnum { |
||||
/** |
||||
* default.The content of cells into string, is the same as you see in the excel. |
||||
*/ |
||||
STRING, |
||||
|
||||
/** |
||||
* Returns the actual type. |
||||
* Will be automatically selected according to the cell contents what return type, will return the following class: |
||||
* <ol> |
||||
* <li>{@link BigDecimal}<li/> |
||||
* <li>{@link Boolean}<li/> |
||||
* <li>{@link String}<li/> |
||||
* <li>{@link LocalDateTime}<li/> |
||||
* <ol/> |
||||
*/ |
||||
ACTUAL_DATA, |
||||
|
||||
/** |
||||
* Return to {@link com.alibaba.excel.metadata.data.ReadCellData}, can decide which field you need. |
||||
*/ |
||||
READ_CELL_DATA, |
||||
; |
||||
|
||||
} |
@ -0,0 +1,35 @@
|
||||
package com.alibaba.easyexcel.test.temp; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.util.Date; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnore; |
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* 基础数据类 |
||||
* |
||||
* @author Jiaju Zhuang |
||||
**/ |
||||
@Getter |
||||
@Setter |
||||
@EqualsAndHashCode |
||||
public class DemoData2 { |
||||
@ExcelProperty("字符串标题") |
||||
private String string; |
||||
@ExcelProperty("日期标题") |
||||
private Date date; |
||||
@ExcelProperty("数字标题") |
||||
private Double doubleData; |
||||
@ExcelProperty("数字标题2") |
||||
private BigDecimal bigDecimal; |
||||
/** |
||||
* 忽略这个字段 |
||||
*/ |
||||
@ExcelIgnore |
||||
private String ignore; |
||||
} |
@ -0,0 +1,24 @@
|
||||
package com.alibaba.easyexcel.test.temp; |
||||
|
||||
import java.time.LocalDateTime; |
||||
import java.util.Date; |
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnore; |
||||
import com.alibaba.excel.annotation.ExcelProperty; |
||||
|
||||
import lombok.EqualsAndHashCode; |
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
/** |
||||
* 基础数据类 |
||||
* |
||||
* @author Jiaju Zhuang |
||||
**/ |
||||
@Getter |
||||
@Setter |
||||
@EqualsAndHashCode |
||||
public class DemoData3 { |
||||
@ExcelProperty("日期时间标题") |
||||
private LocalDateTime localDateTime; |
||||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue