Bug 54853

Summary: getText on AutoShape with "-" gives null value
Product: POI Reporter: Parul <gargpar>
Component: HSLFAssignee: POI Developers List <dev>
Status: RESOLVED WORKSFORME    
Severity: major    
Priority: P2    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Check the table cell with the value -

Description Parul 2013-04-16 09:25:35 UTC
Created attachment 30201 [details]
Check the table cell with the value -

I have written code to extract the text from the table in the PPT file.

Sample Code :-

//Import POI classes
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hslf.*;
import org.apache.poi.hslf.model.*;
import org.apache.poi.hslf.usermodel.*;

public class createTextFrmPPTTable
{
public static void main( String[] args )
{
String filename = args[ 0 ];
try
{

  SlideShow ppt = new SlideShow( new HSLFSlideShow( filename ) );
  Slide[] slides = ppt.getSlides();
  for( int i=0; i<slides.length; i++ )
  {
   System.out.println("\tTable Object");
   Shape[] sh = slides[i].getShapes();
   
   for (int k = 0; k < sh.length; k++) {  
     if (sh[k] instanceof ShapeGroup){ //got a table 
       ShapeGroup table = (ShapeGroup)sh[k]; 
       Shape[] ch = table.getShapes(); 
            
       for (int l=0; l<ch.length; l++){     	   
         if (ch[l] instanceof TextBox){ 
           TextBox txt = (TextBox)ch[l]; 
           String text = txt.getText(); //text in a table cell
           System.out.println("Textbox text :" + text);
         } else if (ch[l] instanceof AutoShape){
        	AutoShape t = (AutoShape)ch[l];
         	System.out.println("AutoShape text :" +t.getText());
         }  
     } 
   }
   }
  }
}
catch( Exception e )
{
  e.printStackTrace();
}
}
}

===============================

When you run this code against the given sample file , it gives "null" for the table cell where you have "-" .
Comment 1 Andreas Beeker 2015-11-17 00:24:09 UTC
In the meantime, this has been fixed - this was my test code:

@Test
public void testGetText() throws IOException {
    HSLFSlideShow ppt = 
(HSLFSlideShow)SlideShowFactory.create(_slTests.getFile("Apache_POI_Issue_1.ppt"));
    HSLFSlide slide = ppt.getSlides().get(0);
    HSLFTable tab = (HSLFTable)slide.getShapes().get(0);
    int rows = tab.getNumberOfRows();
    int cols = tab.getNumberOfColumns();
    String exp[] = { "Test", "Test1 – sadsa", "Test2", "Test3" };
    int expI = 0;
    for (int row=0; row<rows; row++) {
        for (int col=0; col<cols; col++) {
            assertEquals(exp[expI], tab.getCell(row, col).getText());
            expI++;
        }
    }
    ppt.close();
}