small refactor of XSSFReader

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896260 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-12-22 04:00:44 +00:00
parent fe4a3b7596
commit 74b08e5f51
1 changed files with 28 additions and 1 deletions

View File

@ -74,6 +74,7 @@ public class XSSFReader {
protected OPCPackage pkg;
protected PackagePart workbookPart;
protected boolean useReadOnlySharedStringsTable;
/**
* Creates a new XSSFReader, for the given package
@ -115,14 +116,40 @@ public class XSSFReader {
workbookPart = this.pkg.getPart(coreDocRelationship);
}
/**
* Controls whether {@link #getSharedStringsTable()} uses {@link SharedStringsTable}
* or {@link ReadOnlySharedStringsTable}.
* @param useReadOnlySharedStringsTable
* @since POI 5.2.0
*/
public void setUseReadOnlySharedStringsTable(boolean useReadOnlySharedStringsTable) {
this.useReadOnlySharedStringsTable = useReadOnlySharedStringsTable;
}
/**
* @return whether {@link #getSharedStringsTable()} uses {@link SharedStringsTable}
* or {@link ReadOnlySharedStringsTable}.
* @since POI 5.2.0
*/
public boolean useReadOnlySharedStringsTable(boolean useReadOnlySharedStringsTable) {
return useReadOnlySharedStringsTable;
}
/**
* Opens up the Shared Strings Table, parses it, and
* returns a handy object for working with
* shared strings.
* @see #setUseReadOnlySharedStringsTable(boolean)
*/
public SharedStrings getSharedStringsTable() throws IOException, InvalidFormatException {
ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType());
return parts.size() == 0 ? null : new SharedStringsTable(parts.get(0));
try {
return parts.size() == 0 ? null :
useReadOnlySharedStringsTable ? new ReadOnlySharedStringsTable(parts.get(0)) :
new SharedStringsTable(parts.get(0));
} catch (SAXException se) {
throw new InvalidFormatException("Failed to parse SharedStringsTable", se);
}
}
/**