Browse Source

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

Merge pull request !14 from 席有芳/FixExcelImportDateType
4.1.3.A
席有芳 7 years ago
committed by jueyue
parent
commit
6c85fd24ab
3 changed files with 30 additions and 0 deletions
  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 View File

@@ -28,7 +28,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.lang3.StringUtils; 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.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.DateUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -68,12 +70,21 @@ public class CellValueServer {
if ("class java.util.Date".equals(xclass) || "class java.sql.Date".equals(xclass) if ("class java.util.Date".equals(xclass) || "class java.sql.Date".equals(xclass)
|| ("class java.sql.Time").equals(xclass) || ("class java.sql.Time").equals(xclass)
|| ("class java.sql.Timestamp").equals(xclass)) { || ("class java.sql.Timestamp").equals(xclass)) {
/*
if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
// 日期格式 // 日期格式
result = cell.getDateCellValue(); result = cell.getDateCellValue();
} else { } else {
cell.setCellType(Cell.CELL_TYPE_STRING); cell.setCellType(Cell.CELL_TYPE_STRING);
result = getDateData(entity, cell.getStringCellValue()); 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)) { if (("class java.sql.Date").equals(xclass)) {
result = new java.sql.Date(((Date) result).getTime()); result = new java.sql.Date(((Date) result).getTime());


+ 4
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/ExcelImportServer.java View File

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


+ 15
- 0
pom.xml View File

@@ -203,6 +203,21 @@
<goals>deploy</goals> <goals>deploy</goals>
</configuration> </configuration>
</plugin> </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> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>


Loading…
Cancel
Save