Skip to content

Commit

Permalink
more changes for poi-shared-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Jul 11, 2024
1 parent 986882b commit 7f9b6ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.github.pjfanning.poi.xssf.streaming.CommentsTableBase;
import com.github.pjfanning.poi.xssf.streaming.MapBackedCommentsTable;
import com.github.pjfanning.poi.xssf.streaming.MapBackedSharedStringsTable;
import com.github.pjfanning.poi.xssf.streaming.SharedStringsTableBase;
import com.github.pjfanning.poi.xssf.streaming.TempFileCommentsTable;
import com.github.pjfanning.poi.xssf.streaming.TempFileSharedStringsTable;
import com.github.pjfanning.xlsx.StreamingReader;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.model.Comments;
import org.apache.poi.xssf.model.SharedStrings;
import org.apache.poi.xssf.model.SharedStringsTable;

import java.io.IOException;
Expand Down Expand Up @@ -60,6 +62,13 @@ public static void readComments(final Comments comments, final InputStream input
}
}

public static String getSharedString(final SharedStrings sst, final int index) {
if (sst instanceof SharedStringsTableBase) {
return ((SharedStringsTableBase) sst).getString(index);
}
return sst.getItemAt(index).getString();
}

private PoiSharedStringsSupport() {
// no-op
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.pjfanning.xlsx.impl;

import com.github.pjfanning.poi.xssf.streaming.SharedStringsTableBase;
import com.github.pjfanning.xlsx.CloseableIterator;
import com.github.pjfanning.xlsx.SharedFormula;
import com.github.pjfanning.xlsx.StreamingReader;
Expand Down Expand Up @@ -55,6 +54,7 @@ class StreamingRowIterator implements CloseableIterator<Row> {

private final StreamingSheetReader streamingSheetReader;
private final SharedStrings sst;
private final boolean usesPoiSharedStrings;
private final StylesTable stylesTable;
private final XMLEventReader parser;
private final boolean use1904Dates;
Expand Down Expand Up @@ -91,6 +91,7 @@ class StreamingRowIterator implements CloseableIterator<Row> {
final StreamingSheet sheet) throws ParseException {
this.streamingSheetReader = streamingSheetReader;
this.sst = sst;
this.usesPoiSharedStrings = sst != null && sst.getClass().getName().startsWith("com.github.pjfanning.poi.xssf");
this.stylesTable = stylesTable;
this.parser = parser;
this.use1904Dates = use1904Dates;
Expand Down Expand Up @@ -510,8 +511,11 @@ private Supplier getFormatterForType(String type) {
case "s": //string stored in shared table
if (!lastContents.isEmpty()) {
final int idx = parseInt(lastContents);
if (!getBuilder().fullFormatRichText() && sst instanceof SharedStringsTableBase) {
return new LazySupplier<>(() -> ((SharedStringsTableBase)sst).getString(idx));
if (!getBuilder().fullFormatRichText()) {
if (usesPoiSharedStrings) {
return new LazySupplier<>(() -> PoiSharedStringsSupport.getSharedString(sst, idx));
}
return new LazySupplier<>(() -> sst.getItemAt(idx).getString());
}
return new LazySupplier<>(() -> sst.getItemAt(idx));
}
Expand Down Expand Up @@ -591,8 +595,8 @@ private String unformattedContents(Supplier formattedContentSupplier) throws POI
if (!lastContents.isEmpty()) {
final int idx = parseInt(lastContents);
if (sst == null) throw new NullPointerException("sst is null");
if (sst instanceof SharedStringsTableBase) {
return ((SharedStringsTableBase)sst).getString(idx);
if (usesPoiSharedStrings) {
return PoiSharedStringsSupport.getSharedString(sst, idx);
}
return sst.getItemAt(idx).getString();
}
Expand Down

0 comments on commit 7f9b6ea

Please sign in to comment.