mirror of https://github.com/apache/poi.git
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:
parent
fe4a3b7596
commit
74b08e5f51
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue