aboutsummaryrefslogtreecommitdiffstats
path: root/src/examples
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2016-03-31 14:39:11 +0000
committerDominik Stadler <centic@apache.org>2016-03-31 14:39:11 +0000
commit06ba6d5e5c5649e9d428478ddf1c0a9f74555243 (patch)
tree77441b8ce4e55024cfc26df4bdf9982b810a4d87 /src/examples
parente0d2a967eeedbd3f64b064c37f23499b64be2306 (diff)
downloadpoi-06ba6d5e5c5649e9d428478ddf1c0a9f74555243.tar.gz
poi-06ba6d5e5c5649e9d428478ddf1c0a9f74555243.zip
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
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java b/src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java
index 2f31490dc4..e82476eb3a 100644
--- a/src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java
+++ b/src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java
@@ -58,7 +58,7 @@ public class FromHowTo {
OPCPackage pkg = OPCPackage.open(filename);
XSSFReader r = new XSSFReader( pkg );
SharedStringsTable sst = r.getSharedStringsTable();
-
+
XMLReader parser = fetchSheetParser(sst);
Iterator<InputStream> sheets = r.getSheetsData();
@@ -73,45 +73,40 @@ 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;
}
- /**
- * See org.xml.sax.helpers.DefaultHandler javadocs
+ /**
+ * See org.xml.sax.helpers.DefaultHandler javadocs
*/
private static class SheetHandler extends DefaultHandler {
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 = "";
}
-
+
public void endElement(String uri, String localName, String name)
throws SAXException {
// Process the last contents as required.
@@ -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);
}
}
@@ -133,7 +128,7 @@ public class FromHowTo {
lastContents += new String(ch, start, length);
}
}
-
+
public static void main(String[] args) throws Exception {
FromHowTo howto = new FromHowTo();
howto.processFirstSheet(args[0]);