Skip to content

Commit

Permalink
解决导出Date格式空指针问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwengeek committed Oct 15, 2018
1 parent 36726cb commit cea1e6a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/alibaba/excel/util/TypeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ private static boolean isNumeric(String str) {
return true;
}

public static String fromadDateToString(Date date,String format){
public static String fromatDateToString(Date date,String format){
if (date == null){
return "";
}
if (SAFE_SDF.get().get(format) == null){
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
SAFE_SDF.get().put(format,dateFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void addOneRowOfDataToExcel(Object oneRowData, Row row) {
format = "yyyy-MM-dd HH:mm:ss";
}
Date nestedProperty = (Date)BeanUtilsBean.getInstance().getPropertyUtils().getNestedProperty(oneRowData, excelHeadProperty.getField().getName());
cellValue = TypeUtil.fromadDateToString(nestedProperty,format);
cellValue = TypeUtil.fromatDateToString(nestedProperty,format);
}else {
cellValue = BeanUtils.getProperty(oneRowData, excelHeadProperty.getField().getName());
}
Expand Down

0 comments on commit cea1e6a

Please sign in to comment.