Skip to content

Commit

Permalink
Merge pull request #348 from liaochong/feature/4.0.0
Browse files Browse the repository at this point in the history
Feature/4.0.0
  • Loading branch information
liaochong authored Jan 15, 2022
2 parents b8e8162 + a8f7127 commit 0d82c1a
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 20 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.0.0.RC1</version>
<version>4.0.0.RC2</version>
<packaging>jar</packaging>

<name>myexcel</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
Expand All @@ -29,7 +30,7 @@
* 字符列sax读取,原理是使用Map接受值,选择指定的某一列
*
* @author liaochong
* @version 1.0
* @version 4.0.0.RC
*/
public class ColumnSaxExcelReader {

Expand All @@ -38,6 +39,10 @@ public class ColumnSaxExcelReader {
* 默认取第一列
*/
private final int columnNum;
/**
* 是否忽略空单元格
*/
private boolean ignoreBlankCell;

private ColumnSaxExcelReader(int columnNum) {
this.columnNum = columnNum;
Expand All @@ -62,8 +67,9 @@ public ColumnSaxExcelReader sheet(String sheetName) {
return this;
}

public ColumnSaxExcelReader ignoreBlankRow() {
public ColumnSaxExcelReader ignoreBlankCell() {
saxExcelReader.ignoreBlankRow();
ignoreBlankCell = true;
return this;
}

Expand Down Expand Up @@ -145,7 +151,9 @@ private List<String> mapToString(List<Map> result) {
}
return result.stream().map(map -> ((Set<Cell>) map.keySet()).stream().filter(cell -> cell.getColNum() == columnNum)
.map(((Map<Cell, String>) map)::get)
.filter(Objects::nonNull)
.findFirst().orElse(null))
.filter(v -> !ignoreBlankCell || v != null)
.collect(Collectors.toCollection(LinkedList::new));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private void setTdStyle(Tr tr) {
}

private Tr getTrFromQueue() throws InterruptedException {
Tr tr = context.trWaitQueue.poll(1, TimeUnit.HOURS);
Tr tr = context.trWaitQueue.poll(15, TimeUnit.MINUTES);
if (tr == null) {
throw new IllegalStateException("Get tr failure,timeout 1 hour.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ public void readFrom(InputStream is) throws IOException, SAXException {
int emptyTest = pis.read();
if (emptyTest > -1) {
pis.unread(emptyTest);
InputSource sheetSource = new InputSource(pis);
try {
XMLReader sheetParser = XMLHelper.newXMLReader();
sheetParser.setContentHandler(this);
sheetParser.parse(sheetSource);
sheetParser.parse(new InputSource(pis));
stringsCache.finished();
} catch (ParserConfigurationException e) {
throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,12 @@ private void processSheet(
SharedStrings strings,
XSSFSheetXMLHandler.SheetContentsHandler sheetHandler,
InputStream sheetInputStream) throws IOException, SAXException {
DataFormatter formatter = new DataFormatter();
InputSource sheetSource = new InputSource(sheetInputStream);
try {
XMLReader sheetParser = XMLHelper.newXMLReader();
ContentHandler handler = new XSSFSheetXMLHandler(
null, null, strings, sheetHandler, formatter, false);
null, null, strings, sheetHandler, new DataFormatter(), false);
sheetParser.setContentHandler(handler);
sheetParser.parse(sheetSource);
sheetParser.parse(new InputSource(sheetInputStream));
} catch (ParserConfigurationException e) {
throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public final class BackgroundStyle {
private static final Logger log = org.slf4j.LoggerFactory.getLogger(BackgroundStyle.class);

public static void setBackgroundColor(CellStyle style, Map<String, String> tdStyle, CustomColor customColor) {
if (tdStyle == null) {
return;
}
String color = tdStyle.get(BACKGROUND_COLOR);
if (color == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,14 @@ public final class BorderStyle {

private static final Pattern BORDER_PATTERN = Pattern.compile("(\\w+)");

private static Map<String, org.apache.poi.ss.usermodel.BorderStyle> borderStyleMap;
private static final Map<String, org.apache.poi.ss.usermodel.BorderStyle> borderStyleMap;

static {
borderStyleMap = Arrays.stream(org.apache.poi.ss.usermodel.BorderStyle.values())
.collect(Collectors.toMap(b -> b.toString().toLowerCase(), b -> b));
}

public static void setBorder(CellStyle cellStyle, Map<String, String> tdStyle) {
if (tdStyle == null) {
return;
}
String borderStyle = tdStyle.get(BORDER_STYLE);
if (borderStyle != null) {
Matcher matcher = BORDER_PATTERN.matcher(borderStyle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public final class TextAlignStyle {
}

public static void setTextAlign(CellStyle cellStyle, Map<String, String> tdStyle) {
if (tdStyle == null) {
return;
}
String textAlign = tdStyle.get(TEXT_ALIGN);
if (horizontalAlignmentMap.containsKey(textAlign)) {
cellStyle.setAlignment(horizontalAlignmentMap.get(textAlign));
Expand Down

0 comments on commit 0d82c1a

Please sign in to comment.