瀏覽代碼

!14 修复单元格yyyyMMdd数字时解析出来的日期错误

Merge pull request !14 from 席有芳/FixExcelImportDateType
4.1.3.A
席有芳 7 年之前
committed by jueyue
父節點
當前提交
6c85fd24ab
共有 3 個文件被更改,包括 30 次插入0 次删除
  1. +11
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/CellValueServer.java
  2. +4
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java
  3. +15
    -0
      pom.xml

+ 11
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/CellValueServer.java 查看文件

@@ -28,7 +28,9 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -68,12 +70,21 @@ public class CellValueServer {
if ("class java.util.Date".equals(xclass) || "class java.sql.Date".equals(xclass)
|| ("class java.sql.Time").equals(xclass)
|| ("class java.sql.Timestamp").equals(xclass)) {
/*
if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
// 日期格式
result = cell.getDateCellValue();
} else {
cell.setCellType(Cell.CELL_TYPE_STRING);
result = getDateData(entity, cell.getStringCellValue());
}*/
//FIX: 单元格yyyyMMdd数字时候使用 cell.getDateCellValue() 解析出的日期错误
if (HSSFDateUtil.isCellDateFormatted(cell)){
result = HSSFDateUtil.getJavaDate(cell.getNumericCellValue());
}
else {
cell.setCellType(CellType.STRING);
result = getDateData(entity, cell.getStringCellValue());
}
if (("class java.sql.Date").equals(xclass)) {
result = new java.sql.Date(((Date) result).getTime());


+ 4
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java 查看文件

@@ -197,6 +197,10 @@ public class ExcelImportServer extends ImportBaseService {
break;
}
row = rows.next();
// Fix 如果row为无效行时候跳出
if(sheet.getLastRowNum() - row.getRowNum() < params.getLastOfInvalidRow() ){
break;
}
// 判断是集合元素还是不是集合元素,如果是就继续加入这个集合,不是就创建新的对象
// keyIndex 如果为空就不处理,仍然处理这一行
if (params.getKeyIndex() != null


+ 15
- 0
pom.xml 查看文件

@@ -203,6 +203,21 @@
<goals>deploy</goals>
</configuration>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>


Loading…
取消
儲存