Skip to content

Commit

Permalink
Merge pull request #398 from liaochong/feature/4.3.2
Browse files Browse the repository at this point in the history
Feature/4.3.2
  • Loading branch information
liaochong authored Jul 28, 2023
2 parents 2537bcc + f97e1f3 commit 18066ce
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.github.liaochong</groupId>
<artifactId>myexcel</artifactId>
<version>4.3.1</version>
<version>4.3.2</version>
<packaging>jar</packaging>

<name>myexcel</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public DefaultExcelReader<T> noTrim() {
return this;
}

public DefaultExcelReader<T> trimToNull() {
this.trim = StringUtil::trimToNull;
return this;
}

public DefaultExcelReader<T> startSheet(Consumer<Sheet> startSheetConsumer) {
this.startSheetConsumer = startSheetConsumer;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.github.liaochong.myexcel.exception.SaxReadException;
import com.github.liaochong.myexcel.exception.StopReadException;
import com.github.liaochong.myexcel.utils.ReflectUtil;
import com.github.liaochong.myexcel.utils.StringUtil;
import com.github.liaochong.myexcel.utils.TempFileOperator;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
Expand Down Expand Up @@ -142,6 +143,11 @@ public SaxExcelReader<T> noTrim() {
return this;
}

public SaxExcelReader<T> trimToNull() {
this.readConfig.trim = StringUtil::trimToNull;
return this;
}

public SaxExcelReader<T> readAllSheet() {
this.readConfig.readAllSheet = true;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

import com.github.liaochong.myexcel.core.constant.Constants;
import com.github.liaochong.myexcel.core.style.FontStyle;
import com.github.liaochong.myexcel.utils.*;
import com.github.liaochong.myexcel.utils.ImageUtil;
import com.github.liaochong.myexcel.utils.RegexpUtil;
import com.github.liaochong.myexcel.utils.StringUtil;
import com.github.liaochong.myexcel.utils.StyleUtil;
import com.github.liaochong.myexcel.utils.TdUtil;
import org.apache.commons.codec.CharEncoding;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.jsoup.Jsoup;
Expand All @@ -28,7 +32,13 @@

import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -304,6 +314,10 @@ private void setTdContent(Element tdElement, Td td) {
td.tdContentType = href.startsWith("mailto:") ? ContentTypeEnum.LINK_EMAIL : ContentTypeEnum.LINK_URL;
return;
}
if (tdElement.hasAttr("blank")) {
td.content = null;
return;
}
String content = this.parseContent(tdElement, td);
if (tdElement.hasAttr("string")) {
td.content = content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public static boolean isNotBlank(String content) {
return content != null && content.trim().length() > 0;
}

public static String trimToNull(String content) {
String ts = content == null ? null : content.trim();
return ts == null || ts.length() == 0 ? null : ts;
}

}

0 comments on commit 18066ce

Please sign in to comment.