add BigDecimal support

This commit is contained in:
Looly
2019-08-16 16:39:12 +08:00
parent 9e39667e5a
commit 796fac2458
2 changed files with 11 additions and 7 deletions

View File

@@ -17,6 +17,7 @@
* 【core】 增强日期工具类pr#455@Github
* 【setting】 构造Setting增加默认字符编码
* 【extra】 ServletUtil增加getHeaderMap方法
* 【poi】 CellUtil改进数字支持解决空指针问题pr#489@Github
### Bug修复
* 【cache】 修复missCount规则issue#465@Github

View File

@@ -1,5 +1,6 @@
package cn.hutool.poi.excel.cell;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
@@ -120,6 +121,7 @@ public class CellUtil {
* @param isHeader 是否为标题单元格
*/
public static void setCellValue(Cell cell, Object value, StyleSet styleSet, boolean isHeader) {
if(null != styleSet) {
final CellStyle headCellStyle = styleSet.getHeadCellStyle();
final CellStyle cellStyle = styleSet.getCellStyle();
if (isHeader && null != headCellStyle) {
@@ -127,6 +129,7 @@ public class CellUtil {
} else if (null != cellStyle) {
cell.setCellStyle(cellStyle);
}
}
if (null == value) {
cell.setCellValue(StrUtil.EMPTY);
@@ -145,7 +148,7 @@ public class CellUtil {
} else if (value instanceof RichTextString) {
cell.setCellValue((RichTextString) value);
} else if (value instanceof Number) {
if ((value instanceof Double || value instanceof Float) && null != styleSet && null != styleSet.getCellStyleForNumber()) {
if ((value instanceof Double || value instanceof Float || value instanceof BigDecimal) && null != styleSet && null != styleSet.getCellStyleForNumber()) {
cell.setCellStyle(styleSet.getCellStyleForNumber());
}
cell.setCellValue(((Number) value).doubleValue());