mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix bug
This commit is contained in:
parent
4eaca121f3
commit
782037c4de
@ -325,15 +325,15 @@ public class EnumUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断某个值是存在枚举中
|
||||
* 判断指定名称的枚举是否存在
|
||||
*
|
||||
* @param <E> 枚举类型
|
||||
* @param enumClass 枚举类
|
||||
* @param val 需要查找的值
|
||||
* @param name 需要查找的枚举名
|
||||
* @return 是否存在
|
||||
*/
|
||||
public static <E extends Enum<E>> boolean contains(final Class<E> enumClass, final String val) {
|
||||
return EnumUtil.getEnumMap(enumClass).containsKey(val);
|
||||
public static <E extends Enum<E>> boolean contains(final Class<E> enumClass, final String name) {
|
||||
return getEnumMap(enumClass).containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,12 +19,19 @@ public class ExcelDateUtil {
|
||||
*/
|
||||
private static final int[] customFormats = new int[]{28, 30, 31, 32, 33, 55, 56, 57, 58};
|
||||
|
||||
/**
|
||||
* 是否日期格式
|
||||
*
|
||||
* @param cell 单元格
|
||||
* @return 是否日期格式
|
||||
*/
|
||||
public static boolean isDateFormat(final Cell cell) {
|
||||
return isDateFormat(cell, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否日期格式
|
||||
*
|
||||
* @param cell 单元格
|
||||
* @param cfEvaluator {@link ConditionalFormattingEvaluator}
|
||||
* @return 是否日期格式
|
||||
@ -36,6 +43,7 @@ public class ExcelDateUtil {
|
||||
|
||||
/**
|
||||
* 判断是否日期格式
|
||||
*
|
||||
* @param numFmt {@link ExcelNumberFormat}
|
||||
* @return 是否日期格式
|
||||
*/
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.hutool.poi.excel.cell.values;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.poi.excel.ExcelDateUtil;
|
||||
import cn.hutool.poi.excel.cell.CellValue;
|
||||
@ -8,7 +7,7 @@ import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.util.NumberToTextConverter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 数字类型单元格值<br>
|
||||
@ -38,13 +37,12 @@ public class NumericCellValue implements CellValue<Object> {
|
||||
if (null != style) {
|
||||
// 判断是否为日期
|
||||
if (ExcelDateUtil.isDateFormat(cell)) {
|
||||
final LocalDateTime date = cell.getLocalDateTimeCellValue();
|
||||
// 1899年写入会导致数据错乱,读取到1899年证明这个单元格的信息不关注年月日
|
||||
final Date dateCellValue = cell.getDateCellValue();
|
||||
if ("1899".equals(DateUtil.format(dateCellValue, "yyyy"))) {
|
||||
return DateUtil.format(dateCellValue, style.getDataFormatString());
|
||||
if(1899 == date.getYear()){
|
||||
return date.toLocalTime();
|
||||
}
|
||||
// 使用Hutool的DateTime包装
|
||||
return DateUtil.date(dateCellValue);
|
||||
return date;
|
||||
}
|
||||
|
||||
final String format = style.getDataFormatString();
|
||||
|
@ -1,18 +1,18 @@
|
||||
package cn.hutool.poi.excel;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IssueI5Q1TWTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void readTest() {
|
||||
final ExcelReader reader = ExcelUtil.getReader("d:/test/I5Q1TW.xlsx");
|
||||
final List<List<Object>> read = reader.read();
|
||||
Console.log(reader.readCellValue(0, 0));
|
||||
final ExcelReader reader = ExcelUtil.getReader("I5Q1TW.xlsx");
|
||||
|
||||
// 自定义时间格式1
|
||||
Assert.assertEquals("18:56", reader.readCellValue(0, 0).toString());
|
||||
|
||||
// 自定义时间格式2
|
||||
Assert.assertEquals("18:56", reader.readCellValue(1, 0).toString());
|
||||
}
|
||||
}
|
||||
|
BIN
hutool-poi/src/test/resources/I5Q1TW.xlsx
Normal file
BIN
hutool-poi/src/test/resources/I5Q1TW.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user