Thanks Jens, you beat me to it.

I took the example published on the POI website - ExampleEventUserModel -
and made a couple of changes to the startElement() and endElement() methods
there. As you have suggested Jens, I modified them to use the localName
parameter in addition to the name parameter like this;

public void startElement(String uri, String localName, String name,
    Attributes attributes) throws SAXException {
   // c => cell
   if(localName.equals("c") || 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;
    }
   }
   // Clear contents cache
   lastContents = "";
  }
  
  public void endElement(String uri, String localName, String name)
    throws SAXException {
   // Process the last contents as required.
   // Do now, as characters() may be called more than once
   if(nextIsString) {
    int idx = Integer.parseInt(lastContents);
    lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();
    nextIsString = false;
   }

   // v => contents of a cell
   // Output after we've seen the string contents
   if(localName.equals("v") || name.equals("v")) {
    System.out.println(lastContents);
   }
  }

and that seems to do the trick.

One other point worth mentioning here is that not all Excel files use the
shared strings table. Some place strings in line with the sheets' markup and
this can also trip up some content handlers. When I get the time, I will
take a look at this as well, that is once I can find an example Excel
workbook that uses inline strings, they seem to be fairly thin on the ground
so to speak.



--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Apache-POI-Streaming-API-doesn-t-recognize-Excel-xlsx-content-tp5720197p5720232.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to