<changes>
<release version="3.8-beta1" date="2010-??-??">
+ <action dev="POI-DEVELOPERS" type="add">Added inline string support to XSSF EventModel</action>
<action dev="POI-DEVELOPERS" type="fix">50246 - Properly position GutsRecord when reading HSSF workbooks</action>
<action dev="POI-DEVELOPERS" type="add">48539 - Added implementation for MROUND(), VAR() and VARP()</action>
<action dev="POI-DEVELOPERS" type="add">50446 - Code cleanup and optimizations to keep some IDE quiet</action>
private boolean vIsOpen;
// Set when F start element is seen
private boolean fIsOpen;
+ // Set when an Inline String "is" is seen
+ private boolean isIsOpen;
// Set when a header/footer element is seen
private boolean hfIsOpen;
this(styles, strings, sheetContentsHandler, new DataFormatter(), formulasNotResults);
}
+ private boolean isTextTag(String name) {
+ if("v".equals(name)) {
+ // Easy, normal v text tag
+ return true;
+ }
+ if("inlineStr".equals(name)) {
+ // Easy inline string
+ return true;
+ }
+ if("t".equals(name) && isIsOpen) {
+ // Inline string <is><t>...</t></is> pair
+ return true;
+ }
+ // It isn't a text tag
+ return false;
+ }
+
public void startElement(String uri, String localName, String name,
Attributes attributes) throws SAXException {
- if ("inlineStr".equals(name) || "v".equals(name)) {
+ if (isTextTag(name)) {
vIsOpen = true;
// Clear contents cache
value.setLength(0);
+ } else if ("is".equals(name)) {
+ // Inline string outer tag
+ isIsOpen = true;
} else if ("f".equals(name)) {
// Clear contents cache
formula.setLength(0);
String thisStr = null;
// v => contents of a cell
- if ("v".equals(name)) {
+ if (isTextTag(name)) {
vIsOpen = false;
// Process the value contents as required, now we have it all
break;
case INLINE_STRING:
- // TODO: have seen an example of this, so it's untested.
+ // TODO: Can these ever have formatting on them?
XSSFRichTextString rtsi = new XSSFRichTextString(value.toString());
thisStr = rtsi.toString();
break;
output.cell(cellRef, thisStr);
} else if ("f".equals(name)) {
fIsOpen = false;
+ } else if ("is".equals(name)) {
+ isIsOpen = false;
} else if ("row".equals(name)) {
output.endRow();
}
));
}
+ public void testInlineStrings() throws Exception {
+ XSSFEventBasedExcelExtractor extractor = getExtractor("InlineStrings.xlsx");
+ extractor.setFormulasNotResults(true);
+ String text = extractor.getText();
+
+ // Numbers
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("43"));
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("22"));
+
+ // Strings
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("ABCDE"));
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("Long Text"));
+
+ // Inline Strings
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("1st Inline String"));
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("And More"));
+
+ // Formulas
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("A2"));
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("A5-A$2"));
+ }
+
/**
* Test that we return pretty much the same as
* ExcelExtractor does, when we're both passed
assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc"));
assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
}
+
+ public void testInlineStrings() {
+ XSSFExcelExtractor extractor = getExtractor("InlineStrings.xlsx");
+ extractor.setFormulasNotResults(true);
+ String text = extractor.getText();
+
+ // Numbers
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("43"));
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("22"));
+
+ // Strings
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("ABCDE"));
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("Long Text"));
+
+ // Inline Strings
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("1st Inline String"));
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("And More"));
+
+ // Formulas
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("A2"));
+ assertTrue("Unable to find expected word in text\n" + text, text.contains("A5-A$2"));
+ }
}