Bug 57930: Add support for inlineString in FromHowTo
Also do not require an Apache Xerces Parser, let the JDK choose an available one instead git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1737247 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
12f99cc9d5
commit
316c1fe307
@ -73,10 +73,7 @@ public class FromHowTo {
|
||||
}
|
||||
|
||||
public XMLReader fetchSheetParser(SharedStringsTable sst) throws SAXException {
|
||||
XMLReader parser =
|
||||
XMLReaderFactory.createXMLReader(
|
||||
"org.apache.xerces.parsers.SAXParser"
|
||||
);
|
||||
XMLReader parser = XMLReaderFactory.createXMLReader();
|
||||
ContentHandler handler = new SheetHandler(sst);
|
||||
parser.setContentHandler(handler);
|
||||
return parser;
|
||||
@ -89,24 +86,22 @@ public class FromHowTo {
|
||||
private SharedStringsTable sst;
|
||||
private String lastContents;
|
||||
private boolean nextIsString;
|
||||
private boolean inlineStr;
|
||||
|
||||
private SheetHandler(SharedStringsTable sst) {
|
||||
this.sst = sst;
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String name,
|
||||
Attributes attributes) throws SAXException {
|
||||
Attributes attributes) throws SAXException {
|
||||
// c => cell
|
||||
if(name.equals("c")) {
|
||||
// Print the cell reference
|
||||
System.out.print(attributes.getValue("r") + " - ");
|
||||
// Figure out if the value is an index in the SST
|
||||
String cellType = attributes.getValue("t");
|
||||
if(cellType != null && cellType.equals("s")) {
|
||||
nextIsString = true;
|
||||
} else {
|
||||
nextIsString = false;
|
||||
}
|
||||
nextIsString = cellType != null && cellType.equals("s");
|
||||
inlineStr = cellType != null && cellType.equals("inlineStr");
|
||||
}
|
||||
// Clear contents cache
|
||||
lastContents = "";
|
||||
@ -119,12 +114,12 @@ public class FromHowTo {
|
||||
if(nextIsString) {
|
||||
int idx = Integer.parseInt(lastContents);
|
||||
lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();
|
||||
nextIsString = false;
|
||||
nextIsString = false;
|
||||
}
|
||||
|
||||
// v => contents of a cell
|
||||
// Output after we've seen the string contents
|
||||
if(name.equals("v")) {
|
||||
if(name.equals("v") || (inlineStr && name.equals("c"))) {
|
||||
System.out.println(lastContents);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user