Skip to content

Commit

Permalink
Fixed issue dhatim#392
Browse files Browse the repository at this point in the history
  • Loading branch information
meiMingle committed Apr 9, 2024
1 parent b6503d1 commit 899f64b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ private List<String> extractFormat(String styleXml) throws XMLStreamException, I
fmtIdToFmtString = new HashMap<>();
try (SimpleXmlReader reader = new SimpleXmlReader(factory, getRequiredEntryContent(styleXml))) {
AtomicBoolean insideCellXfs = new AtomicBoolean(false);
while (reader.goTo(() -> reader.isStartElement("numFmt") ||
reader.isStartElement("cellXfs") || reader.isEndElement("cellXfs") ||
insideCellXfs.get())) {
while (reader.goTo(() -> reader.isStartElement("numFmt") || reader.isStartElement("xf") ||
reader.isStartElement("cellXfs") || reader.isEndElement("cellXfs"))) {
if (reader.isStartElement("cellXfs")) {
insideCellXfs.set(true);
} else if (reader.isEndElement("cellXfs")) {
Expand All @@ -153,7 +152,7 @@ private List<String> extractFormat(String styleXml) throws XMLStreamException, I
String formatCode = reader.getAttributeRequired("formatCode");
fmtIdToFmtString.put(reader.getAttributeRequired("numFmtId"), formatCode);
} else if (insideCellXfs.get() && reader.isStartElement("xf")) {
String numFmtId = reader.getAttribute ("numFmtId");
String numFmtId = reader.getAttribute("numFmtId");
fmtIdList.add(numFmtId);
if (IMPLICIT_NUM_FMTS.containsKey(numFmtId)) {
fmtIdToFmtString.put(numFmtId, IMPLICIT_NUM_FMTS.get(numFmtId));
Expand All @@ -166,7 +165,7 @@ private List<String> extractFormat(String styleXml) throws XMLStreamException, I

private InputStream getRequiredEntryContent(String name) throws IOException {
return Optional.ofNullable(getEntryContent(name))
.orElseThrow(() -> new ExcelReaderException(name + " not found"));
.orElseThrow(() -> new ExcelReaderException(name + " not found"));
}

static OPCPackage open(File inputFile) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.dhatim.fastexcel.reader;

import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.stream.Stream;

import static org.dhatim.fastexcel.reader.Resources.open;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class ExcelFileWithCRLFTest {

@Test
public void testFileWithCRLF() throws IOException {
try (InputStream inputStream = open("/xlsx/withStyleCRLF.xlsx");
ReadableWorkbook excel = new ReadableWorkbook(inputStream, new ReadingOptions(true, true))) {
Sheet firstSheet = excel.getFirstSheet();
try (Stream<Row> rows = firstSheet.openStream()) {
rows.forEach(r -> {
if (r.getRowNum() > 1) {
r.forEach(c -> {
if (c != null) {
assertNotNull(c.getDataFormatString());
}
});
}
});
}
}
}

}
Binary file not shown.

0 comments on commit 899f64b

Please sign in to comment.