Bug 54853 - getText on AutoShape with "-" gives null value
Summary: getText on AutoShape with "-" gives null value
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSLF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-16 09:25 UTC by Parul
Modified: 2015-11-17 00:24 UTC (History)
0 users



Attachments
Check the table cell with the value - (109.50 KB, application/vnd.ms-powerpoint)
2013-04-16 09:25 UTC, Parul
Details

Note You need to log in before you can comment on or make changes to this bug.
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();
}