Skip to content

Commit 18066ce

Browse files
authored
Merge pull request #398 from liaochong/feature/4.3.2
Feature/4.3.2
2 parents 2537bcc + f97e1f3 commit 18066ce

5 files changed

Lines changed: 33 additions & 3 deletions

File tree

pom.xml

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

1212
<groupId>com.github.liaochong</groupId>
1313
<artifactId>myexcel</artifactId>
14-
<version>4.3.1</version>
14+
<version>4.3.2</version>
1515
<packaging>jar</packaging>
1616

1717
<name>myexcel</name>

src/main/java/com/github/liaochong/myexcel/core/DefaultExcelReader.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ public DefaultExcelReader<T> noTrim() {
165165
return this;
166166
}
167167

168+
public DefaultExcelReader<T> trimToNull() {
169+
this.trim = StringUtil::trimToNull;
170+
return this;
171+
}
172+
168173
public DefaultExcelReader<T> startSheet(Consumer<Sheet> startSheetConsumer) {
169174
this.startSheetConsumer = startSheetConsumer;
170175
return this;

src/main/java/com/github/liaochong/myexcel/core/SaxExcelReader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.github.liaochong.myexcel.exception.SaxReadException;
2323
import com.github.liaochong.myexcel.exception.StopReadException;
2424
import com.github.liaochong.myexcel.utils.ReflectUtil;
25+
import com.github.liaochong.myexcel.utils.StringUtil;
2526
import com.github.liaochong.myexcel.utils.TempFileOperator;
2627
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
2728
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
@@ -142,6 +143,11 @@ public SaxExcelReader<T> noTrim() {
142143
return this;
143144
}
144145

146+
public SaxExcelReader<T> trimToNull() {
147+
this.readConfig.trim = StringUtil::trimToNull;
148+
return this;
149+
}
150+
145151
public SaxExcelReader<T> readAllSheet() {
146152
this.readConfig.readAllSheet = true;
147153
return this;

src/main/java/com/github/liaochong/myexcel/core/parser/HtmlTableParser.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717

1818
import com.github.liaochong.myexcel.core.constant.Constants;
1919
import com.github.liaochong.myexcel.core.style.FontStyle;
20-
import com.github.liaochong.myexcel.utils.*;
20+
import com.github.liaochong.myexcel.utils.ImageUtil;
21+
import com.github.liaochong.myexcel.utils.RegexpUtil;
22+
import com.github.liaochong.myexcel.utils.StringUtil;
23+
import com.github.liaochong.myexcel.utils.StyleUtil;
24+
import com.github.liaochong.myexcel.utils.TdUtil;
2125
import org.apache.commons.codec.CharEncoding;
2226
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
2327
import org.jsoup.Jsoup;
@@ -28,7 +32,13 @@
2832

2933
import java.io.File;
3034
import java.io.IOException;
31-
import java.util.*;
35+
import java.util.ArrayList;
36+
import java.util.Collections;
37+
import java.util.HashMap;
38+
import java.util.LinkedList;
39+
import java.util.List;
40+
import java.util.Map;
41+
import java.util.Objects;
3242
import java.util.concurrent.ConcurrentHashMap;
3343
import java.util.regex.Pattern;
3444
import java.util.stream.Collectors;
@@ -304,6 +314,10 @@ private void setTdContent(Element tdElement, Td td) {
304314
td.tdContentType = href.startsWith("mailto:") ? ContentTypeEnum.LINK_EMAIL : ContentTypeEnum.LINK_URL;
305315
return;
306316
}
317+
if (tdElement.hasAttr("blank")) {
318+
td.content = null;
319+
return;
320+
}
307321
String content = this.parseContent(tdElement, td);
308322
if (tdElement.hasAttr("string")) {
309323
td.content = content;

src/main/java/com/github/liaochong/myexcel/utils/StringUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ public static boolean isNotBlank(String content) {
2929
return content != null && content.trim().length() > 0;
3030
}
3131

32+
public static String trimToNull(String content) {
33+
String ts = content == null ? null : content.trim();
34+
return ts == null || ts.length() == 0 ? null : ts;
35+
}
36+
3237
}

0 commit comments

Comments
 (0)