Skip to content

Commit 08abea5

Browse files
committed
升级POI版本到4.0.1
1 parent 7430611 commit 08abea5

File tree

5 files changed

+40
-49
lines changed

5 files changed

+40
-49
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<dependency>
1919
<groupId>com.github.matrixseven</groupId>
2020
<artifactId>ExcelReads</artifactId>
21-
<version>1.0.1</version>
21+
<version>1.0.2</version>
2222
</dependency>
2323

2424
```

pom.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.github.matrixseven</groupId>
55
<artifactId>ExcelReads</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.0.1</version>
7+
<version>1.0.2</version>
88
<name>ExcelReads</name>
99
<description>A ExcelReads Utils By Seven</description>
1010
<url>https://github.com/MatrixSeven/ExcelReads</url>
@@ -38,18 +38,18 @@
3838
</repository>
3939
</distributionManagement>
4040

41-
<dependencies>
4241

43-
<dependency>
44-
<groupId>org.apache.poi</groupId>
45-
<artifactId>poi</artifactId>
46-
<version>3.15</version>
47-
</dependency>
48-
<dependency>
49-
<groupId>org.apache.poi</groupId>
50-
<artifactId>poi-ooxml</artifactId>
51-
<version>3.15</version>
52-
</dependency>
42+
<dependencies>
43+
<dependency>
44+
<groupId>org.apache.poi</groupId>
45+
<artifactId>poi</artifactId>
46+
<version>4.0.1</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.apache.poi</groupId>
50+
<artifactId>poi-ooxml</artifactId>
51+
<version>4.0.1</version>
52+
</dependency>
5353
<dependency>
5454
<groupId>junit</groupId>
5555
<artifactId>junit</artifactId>

src/main/java/seven/wapperInt/Wrapper.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@
4141
public abstract class Wrapper<T> implements Serializable, ExcelSuperInterface {
4242
protected Config config = new Config();
4343
protected DecimalFormat df = new DecimalFormat("0");
44+
private static final String BLANK="";
4445

4546
protected String getCellFormatValue(Cell cell) {
4647
String cellValue;
4748
if (cell != null) {
4849
switch (cell.getCellType()) {
49-
case Cell.CELL_TYPE_NUMERIC:
50+
case NUMERIC:
5051
cellValue = df.format(cell.getNumericCellValue());
5152
break;
52-
case Cell.CELL_TYPE_FORMULA: {
53+
case FORMULA: {
5354
if (HSSFDateUtil.isCellDateFormatted(cell)) {
5455
Date date = cell.getDateCellValue();
5556
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@@ -59,20 +60,16 @@ protected String getCellFormatValue(Cell cell) {
5960
}
6061
break;
6162
}
62-
case Cell.CELL_TYPE_BLANK:
63-
cellValue = " ";
64-
break;
65-
case Cell.CELL_TYPE_STRING:
63+
case STRING:
6664
cellValue = cell.getStringCellValue();
6765
break;
68-
case Cell.CELL_TYPE_ERROR:
69-
cellValue = " ";
70-
break;
66+
case ERROR:
67+
case BLANK:
7168
default:
72-
cellValue = " ";
69+
cellValue = BLANK;
7370
}
7471
} else {
75-
cellValue = "";
72+
cellValue = BLANK;
7673
}
7774
return cellValue;
7875
}
@@ -88,13 +85,12 @@ public Wrapper(Consumer<Config> consumer) {
8885
* @return List
8986
* @throws Exception
9087
*/
91-
public abstract List<T> Create() throws Exception;
92-
88+
public abstract List<T> Create() throws Exception;
9389

94-
public abstract List<Map<String,String>> CreateMap() throws Exception;
9590

96-
public abstract Map<String,Map<String,String>> CreateMap(String key) throws Exception;
91+
public abstract List<Map<String, String>> CreateMap() throws Exception;
9792

93+
public abstract Map<String, Map<String, String>> CreateMap(String key) throws Exception;
9894

9995

10096
/**

src/main/java/seven/wapperInt/wapperRef/sysWppers/ResWrapperMap.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package seven.wapperInt.wapperRef.sysWppers;
22

3-
import org.apache.poi.ss.formula.functions.T;
43
import org.apache.poi.ss.usermodel.Row;
54
import org.apache.poi.ss.usermodel.Sheet;
65
import org.apache.poi.ss.usermodel.Workbook;
76
import org.slf4j.Logger;
87
import org.slf4j.LoggerFactory;
8+
import seven.config.Config;
99
import seven.util.ExcelTool;
1010
import seven.util.RegHelper;
11-
import seven.config.Config;
1211
import seven.wapperInt.wapperRef.WrapperObj;
1312

1413
import java.util.*;
@@ -106,18 +105,20 @@ protected <T> T RefResWrapper(String fs, boolean isMap, String key) throws Excep
106105
} catch (Exception e) {
107106
logger.error("列表长度小于实际列长度 startSheet:{},sheetName:{}, row:{}", start_sheet, sheet.getSheetName(), rowNum);
108107
}
109-
for (int j = 0, colNum = row.getPhysicalNumberOfCells(); j < colNum; j++) {
110-
if (require != null && !(require[j].equals("Null")) && filterColByKey.contains(titles[j])) {
108+
for (int j = 0, colNum = row.getPhysicalNumberOfCells(); j < colNum&&j<titles.length; j++) {
109+
if (require != null && !(require[j].equals("Null")) && !filterColByKey.contains(titles[j])) {
111110
if (RegHelper.require(require[j], getCellFormatValue(row.getCell((short) j)))) {
112111
map.put(titles[j], getCellFormatValue(row.getCell((short) j)));
113112
} else {
114113
}
115114
} else {
116-
map.put(titles[j], getCellFormatValue(row.getCell((short) j)));
115+
if(!filterColByKey.contains(titles[j])) {
116+
map.put(titles[j], getCellFormatValue(row.getCell((short) j)));
117+
}
117118
}
118119
}
119120
if (!isNull(map))
120-
if (this.filter.test(map)) {
121+
if (!this.filter.test(map)) {
121122
continue;
122123
}
123124
this.process.accept(map);

src/test/java/Demo.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.apache.poi.hssf.util.HSSFColor;
1818
import org.apache.poi.ss.usermodel.FillPatternType;
1919
import org.apache.poi.ss.usermodel.HorizontalAlignment;
20+
import org.apache.poi.util.StringUtil;
2021
import org.junit.Test;
2122
import org.junit.runner.RunWith;
2223
import org.junit.runners.BlockJUnit4ClassRunner;
@@ -36,18 +37,17 @@ public class Demo {
3637
@Test
3738
public void Test_01() throws Exception {
3839

39-
String filePath = System.getProperty("user.dir").concat("/测试.xls");
40-
String filePath2 = System.getProperty("user.dir").concat("/seven.xlsx");
40+
String filePath = System.getProperty("user.dir").concat("/test.xlsx");
4141

4242
List<Map<String, String>> list = ExcelFactory.getBeans(filePath, WrapperFactory
43-
.MakeMap(it -> it.vocSize(1999).title(2).content(3)))
44-
.Filter(it -> !it.get("服务IP").contains("12"))
45-
.Process(it -> it.put("add", "这个是我增加的"))
46-
.FilterCol(df -> df.add("连接类型"))
47-
.CreateMap();
43+
.MakeMap(it -> it.vocSize(1999).title(0).content(2).isLoopSheet(true)))
44+
.Filter(it->it.get("Run").equals("Y"))
45+
.Filter(it->!it.getOrDefault("Test"," ").equals(" "))
46+
.Create();
4847

4948
System.out.println(list);
5049

50+
String filePath2 = System.getProperty("user.dir").concat("/seven.xlsx");
5151
List<A> create = ExcelFactory.getBeans(filePath2, WrapperFactory.<A>MakeObj(it -> it.vocSize(1999)
5252
.title(0).content(1), A.class))
5353
.Filter(it -> it.getA().equals(""))
@@ -88,13 +88,7 @@ public void Test_02() throws Exception {
8888
ExcelFactory.saveExcel(m, System.getProperty("user.dir").concat("/SaveMap_.xlsx"))
8989
.SetCellStyle("A", cellStyle -> cellStyle
9090
.setFillPattern(FillPatternType.DIAMONDS)
91-
.setAlignment(HorizontalAlignment.RIGHT)
92-
.setFillForegroundColor(HSSFColor.WHITE.index)
93-
.setBottomBorderColor(HSSFColor.RED.index)
94-
.setFillBackgroundColor(HSSFColor.GOLD.index)
95-
.setRightBorderColor(HSSFColor.INDIGO.index))
96-
.ConvertName("A", "我的世界")
97-
.Flush();
91+
.setAlignment(HorizontalAlignment.RIGHT)).Flush();
9892

9993
}
10094
}

0 commit comments

Comments
 (0)