poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r880864 - in /poi/trunk/src: documentation/content/xdocs/status.xml examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
Date Mon, 16 Nov 2009 17:31:16 GMT
Author: yegor
Date: Mon Nov 16 17:31:16 2009
New Revision: 880864

URL: http://svn.apache.org/viewvc?rev=880864&view=rev
Log:
fixed XLSX2CSV to avoid exception when processing cells with multiple "t" elements, see Bugzilla
47757

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=880864&r1=880863&r2=880864&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Nov 16 17:31:16 2009
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.6-beta1" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">47757 - fixed XLSX2CSV to avoid
exception when processing cells with multiple "t" elements</action>
            <action dev="POI-DEVELOPERS" type="add">48195 - short-circuit evaluation
of IF() and CHOOSE()</action>
            <action dev="POI-DEVELOPERS" type="add">48161 - support for text extraction
from PPT master slides</action>
            <action dev="POI-DEVELOPERS" type="add">47970 - added a method to set arabic
mode in HSSFSheet</action>

Modified: poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java?rev=880864&r1=880863&r2=880864&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/XLSX2CSV.java Mon Nov 16
17:31:16 2009
@@ -34,6 +34,7 @@
 import org.apache.poi.openxml4j.opc.PackageRelationship;
 import org.apache.poi.ss.usermodel.BuiltinFormats;
 import org.apache.poi.ss.usermodel.DataFormatter;
+import org.apache.poi.xssf.eventusermodel.XSSFReader;
 import org.apache.poi.xssf.model.StylesTable;
 import org.apache.poi.xssf.usermodel.XSSFCellStyle;
 import org.apache.poi.xssf.usermodel.XSSFRichTextString;
@@ -60,7 +61,12 @@
  * (read-only) class is used for the shared string table
  * because the standard POI SharedStringsTable grows very
  * quickly with the number of unique strings.
- *
+ * <p/>
+ * Thanks to Eric Smith for a patch that fixes a problem
+ * triggered by cells with multiple "t" elements, which is
+ * how Excel represents different formats (e.g., one word
+ * plain and one word bold).
+ * 
  * @author Chris Lott
  */
 public class XLSX2CSV {
@@ -78,6 +84,43 @@
         NUMBER,
     }
 
+    /**
+     * Each cell is enclosed in "si".  Each cell can have multiple "t" elements.
+     * Example input
+     * 
+     * <pre>
+ 	&lt;?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+	&lt;sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="2"
uniqueCount="2">
+	  &lt;si>
+	    &lt;r>
+	      &lt;rPr>
+	        &lt;b />
+	        &lt;sz val="11" />
+	        &lt;color theme="1" />
+  	        &lt;rFont val="Calibri" />
+  	        &lt;family val="2" />
+  	        &lt;scheme val="minor" />
+  	      &lt;/rPr>
+  	      &lt;t>This:&lt;/t>
+  	    &lt;/r>
+	    &lt;r>
+	      &lt;rPr>
+  	        &lt;sz val="11" />
+	        &lt;color theme="1" />
+  	        &lt;rFont val="Calibri" />
+  	        &lt;family val="2" />
+  	        &lt;scheme val="minor" />
+  	      &lt;/rPr>
+  	      &lt;t xml:space="preserve">Causes Problems&lt;/t>
+  	    &lt;/r>
+  	  &lt;/si>
+	  &lt;si>
+  	    &lt;t>This does not&lt;/t>
+  	  &lt;/si>
+  	&lt;/sst>
+  	 * </pre>
+     *
+     */
     static class ReadonlySharedStringsTable extends DefaultHandler {
 
         /**
@@ -192,8 +235,9 @@
                 this.strings = new String[this.uniqueCount];
                 index = 0;
                 characters = new StringBuffer();
-            } else if ("t".equals(name)) {
+            } else if ("si".equals(name)) {
                 characters.setLength(0);
+            } else if ("t".equals(name)) {
                 tIsOpen = true;
             }
         }
@@ -204,9 +248,11 @@
        */
         public void endElement(String uri, String localName, String name)
                 throws SAXException {
-            if ("t".equals(name)) {
-                strings[index] = characters.toString();
+            if ("si".equals(name)) {
+                strings[index] = characters.toString();            	
                 ++index;
+            } else if ("t".equals(name)) {
+            	tIsOpen = false;
             }
         }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message