Skip to content

Commit 3a1db02

Browse files
authored
Merge pull request #3916 from alibaba/bugfix
Bugfix
2 parents 4658a0e + 1cbc7da commit 3a1db02

File tree

7 files changed

+175
-28
lines changed

7 files changed

+175
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ easyexcel重写了poi对07版Excel的解析,一个3M的excel用POI sax解析
3333
<dependency>
3434
<groupId>com.alibaba</groupId>
3535
<artifactId>easyexcel</artifactId>
36-
<version>4.0.1</version>
36+
<version>4.0.2</version>
3737
</dependency>
3838
```
3939

easyexcel-core/src/main/java/com/alibaba/excel/constant/BuiltinFormats.java

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Map;
55

66
import com.alibaba.excel.util.MapUtils;
7+
import com.alibaba.excel.util.StringUtils;
78

89
/**
910
* Excel's built-in format conversion.Currently only supports Chinese.
@@ -22,6 +23,112 @@ public class BuiltinFormats {
2223

2324
public static short GENERAL = 0;
2425

26+
public static final String[] BUILTIN_FORMATS_ALL_LANGUAGES = {
27+
// 0
28+
"General",
29+
// 1
30+
"0",
31+
// 2
32+
"0.00",
33+
// 3
34+
"#,##0",
35+
// 4
36+
"#,##0.00",
37+
// 5
38+
"\"\"#,##0_);(\"\"#,##0)",
39+
// 6
40+
"\"\"#,##0_);[Red](\"\"#,##0)",
41+
// 7
42+
"\"\"#,##0.00_);(\"\"#,##0.00)",
43+
// 8
44+
"\"\"#,##0.00_);[Red](\"\"#,##0.00)",
45+
// 9
46+
"0%",
47+
// 10
48+
"0.00%",
49+
// 11
50+
"0.00E+00",
51+
// 12
52+
"# ?/?",
53+
// 13
54+
"# ??/??",
55+
// 14
56+
// The official documentation shows "m/d/yy", but the actual test is "yyyy/m/d".
57+
"yyyy/m/d",
58+
// 15
59+
"d-mmm-yy",
60+
// 16
61+
"d-mmm",
62+
// 17
63+
"mmm-yy",
64+
// 18
65+
"h:mm AM/PM",
66+
// 19
67+
"h:mm:ss AM/PM",
68+
// 20
69+
"h:mm",
70+
// 21
71+
"h:mm:ss",
72+
// 22
73+
// The official documentation shows "m/d/yy h:mm", but the actual test is "yyyy-m-d h:mm".
74+
"yyyy-m-d h:mm",
75+
// 23-36 No specific correspondence found in the official documentation.
76+
// 23
77+
null,
78+
// 24
79+
null,
80+
// 25
81+
null,
82+
// 26
83+
null,
84+
// 27
85+
null,
86+
// 28
87+
null,
88+
// 29
89+
null,
90+
// 30
91+
null,
92+
// 31
93+
null,
94+
// 32
95+
null,
96+
// 33
97+
null,
98+
// 34
99+
null,
100+
// 35
101+
null,
102+
// 36
103+
null,
104+
// 37
105+
"#,##0_);(#,##0)",
106+
// 38
107+
"#,##0_);[Red](#,##0)",
108+
// 39
109+
"#,##0.00_);(#,##0.00)",
110+
// 40
111+
"#,##0.00_);[Red](#,##0.00)",
112+
// 41
113+
"_(* #,##0_);_(* (#,##0);_(* \"-\"_);_(@_)",
114+
// 42
115+
"_(\"\"* #,##0_);_(\"\"* (#,##0);_(\"\"* \"-\"_);_(@_)",
116+
// 43
117+
"_(* #,##0.00_);_(* (#,##0.00);_(* \"-\"??_);_(@_)",
118+
// 44
119+
"_(\"\"* #,##0.00_);_(\"\"* (#,##0.00);_(\"\"* \"-\"??_);_(@_)",
120+
// 45
121+
"mm:ss",
122+
// 46
123+
"[h]:mm:ss",
124+
// 47
125+
"mm:ss.0",
126+
// 48
127+
"##0.0E+0",
128+
// 49
129+
"@",
130+
};
131+
25132
public static final String[] BUILTIN_FORMATS_CN = {
26133
// 0
27134
"General",
@@ -371,8 +478,26 @@ public class BuiltinFormats {
371478
public static final short MIN_CUSTOM_DATA_FORMAT_INDEX = 82;
372479

373480
public static String getBuiltinFormat(Short index, String defaultFormat, Locale locale) {
481+
if (index == null || index <= 0) {
482+
return defaultFormat;
483+
}
484+
485+
// Give priority to checking if it is the default value for all languages
486+
if (index < BUILTIN_FORMATS_ALL_LANGUAGES.length) {
487+
String format = BUILTIN_FORMATS_ALL_LANGUAGES[index];
488+
if (format != null) {
489+
return format;
490+
}
491+
}
492+
493+
// In other cases, give priority to using the externally provided format
494+
if (!StringUtils.isEmpty(defaultFormat) && !defaultFormat.startsWith("reserved-")) {
495+
return defaultFormat;
496+
}
497+
498+
// Finally, try using the built-in format
374499
String[] builtinFormat = switchBuiltinFormats(locale);
375-
if (index == null || index < 0 || index >= builtinFormat.length) {
500+
if (index >= builtinFormat.length) {
376501
return defaultFormat;
377502
}
378503
return builtinFormat[index];

easyexcel-core/src/main/java/com/alibaba/excel/util/DateUtils.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -470,31 +470,10 @@ public static boolean isInternalDateFormat(short format) {
470470
case 0x14:
471471
case 0x15:
472472
case 0x16:
473-
// 27-36
474-
case 0x1b:
475-
case 0x1c:
476-
case 0x1d:
477-
case 0x1e:
478-
case 0x1f:
479-
case 0x20:
480-
case 0x21:
481-
case 0x22:
482-
case 0x23:
483-
case 0x24:
484-
// 45-47
473+
// 45-47
485474
case 0x2d:
486475
case 0x2e:
487476
case 0x2f:
488-
// 50-58
489-
case 0x32:
490-
case 0x33:
491-
case 0x34:
492-
case 0x35:
493-
case 0x36:
494-
case 0x37:
495-
case 0x38:
496-
case 0x39:
497-
case 0x3a:
498477
return true;
499478
}
500479
return false;

easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/Lock2Test.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public void test() throws Exception {
5252
File file = new File("/Users/zhuangjiaju/IdeaProjects/easyexcel/src/test/resources/converter/converter07.xlsx");
5353

5454
List<Object> list = EasyExcel.read(
55-
"/Users/zhuangjiaju/IdeaProjects/easyexcel/easyexcel-test/target/test-classes"
56-
+ "/simpleWrite1674051907397.xlsx")
55+
"/Users/zhuangjiaju/Downloads/证券投资基金估值表_外贸信托-稳盈淳享37号集合资金信托计划_2024-07-23.xls")
5756
//.useDefaultListener(false)
5857
.sheet(0)
5958
.headRowNumber(0).doReadSync();
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.alibaba.easyexcel.test.temp.poi;
2+
3+
import java.io.IOException;
4+
5+
import org.apache.poi.ss.usermodel.DateUtil;
6+
import org.apache.poi.xssf.usermodel.XSSFCell;
7+
import org.apache.poi.xssf.usermodel.XSSFRow;
8+
import org.apache.poi.xssf.usermodel.XSSFSheet;
9+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
10+
import org.junit.jupiter.api.Test;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
14+
/**
15+
* 测试poi
16+
*
17+
* @author Jiaju Zhuang
18+
**/
19+
20+
public class PoiDateFormatTest {
21+
private static final Logger LOGGER = LoggerFactory.getLogger(PoiDateFormatTest.class);
22+
23+
@Test
24+
public void read() throws IOException {
25+
String file
26+
= "/Users/zhuangjiaju/IdeaProjects/easyexcel/easyexcel-test/src/test/resources/dataformat/dataformat.xlsx";
27+
XSSFWorkbook xssfWorkbook = new XSSFWorkbook( file);
28+
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
29+
LOGGER.info("一共行数:{}", xssfSheet.getLastRowNum());
30+
XSSFRow row = xssfSheet.getRow(7);
31+
XSSFCell cell = row.getCell(0);
32+
LOGGER.info("dd{}", cell.getDateCellValue());
33+
LOGGER.info("dd{}", cell.getNumericCellValue());
34+
35+
LOGGER.info("dd{}", DateUtil.isCellDateFormatted(cell));
36+
37+
38+
}
39+
40+
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
<properties>
23-
<revision>4.0.1</revision>
23+
<revision>4.0.2</revision>
2424
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2525
<jdk.version>1.8</jdk.version>
2626
<gpg.skip>true</gpg.skip>

update.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# 4.0.1
1+
# 4.0.2
2+
3+
* 兼容某些特殊的xls: 修改了内置的样式导致判断样式错误
4+
5+
* # 4.0.1
26

37
* `commons-io` 修改为依赖 `poi`的版本
48
* 修复临时目录被清理可能提示`NoSuchFileException`的异常

0 commit comments

Comments
 (0)