Author: tallison
Date: Fri Sep 27 15:45:55 2013
New Revision: 1526960

URL: http://svn.apache.org/r1526960
Log:
POI-54722 table text in ppt files

Added:
    poi/trunk/test-data/slideshow/54722.ppt   (with props)
Modified:
    
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java
    
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java?rev=1526960&r1=1526959&r2=1526960&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java
 (original)
+++ 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java
 Fri Sep 27 15:45:55 2013
@@ -252,6 +252,12 @@ public final class PowerPointExtractor e
                                // Slide text
                 textRunsToText(ret, slide.getTextRuns());
 
+                // Table text
+                for (Shape shape : slide.getShapes()){
+                    if (shape instanceof Table){
+                        extractTableText(ret, (Table)shape);
+                    }
+                }
                 // Slide footer, if set
                                if (hf != null && hf.isFooterVisible() && 
hf.getFooterText() != null) {
                                        ret.append(hf.getFooterText() + "\n");
@@ -306,6 +312,23 @@ public final class PowerPointExtractor e
                return ret.toString();
        }
 
+    private void extractTableText(StringBuffer ret, Table table) {
+        for (int row = 0; row < table.getNumberOfRows(); row++){
+            for (int col = 0; col < table.getNumberOfColumns(); col++){
+                TableCell cell = table.getCell(row, col);
+                //defensive null checks; don't know if they're necessary
+                if (cell != null){
+                    String txt = cell.getText();
+                    txt = (txt == null) ? "" : txt;
+                    ret.append(txt);
+                    if (col < table.getNumberOfColumns()-1){
+                        ret.append("\t");
+                    }
+                }
+            }
+            ret.append('\n');
+        }
+    }
     private void textRunsToText(StringBuffer ret, TextRun[] runs) {
         if (runs==null) {
             return;

Modified: 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java?rev=1526960&r1=1526959&r2=1526960&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
 (original)
+++ 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
 Fri Sep 27 15:45:55 2013
@@ -367,4 +367,23 @@ public final class TestExtractor extends
           assertEquals(expectText, extractor.getText());
        }
     }
+
+    public void testTable() throws Exception{
+        ppe = new 
PowerPointExtractor(slTests.openResourceAsStream("54111.ppt"));
+        String text = ppe.getText();
+        String target = "TH Cell 1\tTH Cell 2\tTH Cell 3\tTH Cell 4\n"+
+                         "Row 1, Cell 1\tRow 1, Cell 2\tRow 1, Cell 3\tRow 1, 
Cell 4\n"+   
+                         "Row 2, Cell 1\tRow 2, Cell 2\tRow 2, Cell 3\tRow 2, 
Cell 4\n"+
+                         "Row 3, Cell 1\tRow 3, Cell 2\tRow 3, Cell 3\tRow 3, 
Cell 4\n"+
+                         "Row 4, Cell 1\tRow 4, Cell 2\tRow 4, Cell 3\tRow 4, 
Cell 4\n"+ 
+                         "Row 5, Cell 1\tRow 5, Cell 2\tRow 5, Cell 3\tRow 5, 
Cell 4\n";
+        assertTrue(text.contains(target));
+
+        ppe = new 
PowerPointExtractor(slTests.openResourceAsStream("54722.ppt"));
+        text = ppe.getText();
+
+        target = "this\tText\tis\twithin\ta\n"+
+                "table\t1\t2\t3\t4";
+        assertTrue(text.contains(target));
+    }    
 }

Added: poi/trunk/test-data/slideshow/54722.ppt
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/54722.ppt?rev=1526960&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/slideshow/54722.ppt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



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

Reply via email to