if (packageReadOnly) {
sharedStringSource = new SharedStringsTable();
} else {
- sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, this.xssfFactory);
+ List<PackagePart> matchingParts = getPackagePart().getPackage()
+ .getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType());
+ if (matchingParts.isEmpty()) {
+ sharedStringSource = (SharedStringsTable)
+ createRelationship(XSSFRelation.SHARED_STRINGS, this.xssfFactory);
+ } else {
+ sharedStringSource = new SharedStringsTable(matchingParts.get(0));
+ }
}
}
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.model.CalculationChain;
+import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
}
}
+ @Test
+ void testBug62181() throws Exception {
+ try (XSSFWorkbook wb = openSampleWorkbook("bug62181.xlsx")) {
+ SharedStringsTable sst = wb.getSharedStringSource();
+ assertNotNull(sst);
+ assertEquals(0, sst.getCount());
+ }
+ }
+
private static void readByCommonsCompress(File temp_excel_poi) throws IOException {
/* read by commons-compress*/
try (ZipFile zipFile = new ZipFile(temp_excel_poi)) {