This is expected. These shapes are placeholders, not real shapes.
When you create a slide from a predefined layout, PowerPoint copies
all shapes defined in the master layout to the new slide.
The shapes are placeholders and technically speaking they are dummy
text shapes - there are no pictures/tables yet, the purpose of
placeholders is to show places where the actual shapes will be placed.
When you click on such a placeholder shape in PowerPoint, it replaces
the dummy shape with a real one (image, table, whatever)
POI should do something like this:
public static void main(String[] args) throws Exception {
XMLSlideShow pptx = new XMLSlideShow(new
FileInputStream("layout_v0.potx"));
XSLFSlideMaster master = pptx.getSlideMasters()[0];
XSLFSlideLayout[] layouts = master.getSlideLayouts();
Iterator layout_it = new ArrayList(Arrays.asList(layouts)).iterator();
while (layout_it.hasNext()) {
XSLFSlideLayout layout = (XSLFSlideLayout) layout_it.next();
XSLFSlide slide = pptx.createSlide(layout);
XSLFShape[] shapes = slide.getShapes();
Iterator shapes_it = new
ArrayList(Arrays.asList(shapes)).iterator();
while (shapes_it.hasNext()) {
XSLFShape shape = (XSLFShape) shapes_it.next();
System.out.println(shape.getShapeName());
if (shape instanceof XSLFConnectorShape) {
System.out.println("CONNECTORSHAPE");
} else if (shape instanceof XSLFTextShape) {
System.out.println("TEXTSHAPE");
CTShape sh = (CTShape)shape.getXmlObject();
CTPlaceholder ph = sh.getNvSpPr().getNvPr().getPh();
if(ph == null) {
STPlaceholderType.Enum pType = ph.getType();
if(ph.getType() == STPlaceholderType.PIC) {
// picture placeholder
Rectangle2D anchor = shape.getAnchor();
// remove the placehoder shape
slide.removeShape(shape);
// insert a picture indead
XSLFPictureShape pic = slide.createPicture(0);
pic.setAnchor(anchor);
} else if (ph.getType() ==
STPlaceholderType.TBL){ //table placeholder
Rectangle2D anchor = shape.getAnchor();
// remove the placehoder shape
slide.removeShape(shape);
// insert a table indead
XSLFTable tbl = slide.createTable();
tbl.setAnchor(anchor);
} else {
// process more placeholders
}
}
} else if (shape instanceof XSLFPictureShape) {
System.out.println("PICTURESHAPE");
}
}
}
return;
}
Cheers,
Yegor
On Fri, May 18, 2012 at 2:40 PM, Pablo Rivera | MediaSquare
<[email protected]> wrote:
> Hi,
>
> I have a potx template with some layouts created in MS Powerpoint 2010 by
> me with text, table and image placeholders.
>
> I'm trying to execute this code:
>
> ---
> import org.apache.poi.xslf.usermodel.*;
> import java.io.*;
> import java.awt.geom.*;
> import java.awt.*;
> import java.util.*;
>
> public class Powerpoint{
> public static void main(String[] args) throws Exception{
> XMLSlideShow pptx = new XMLSlideShow(new
> FileInputStream("layout_v0.potx"));
> XSLFSlideMaster master = pptx.getSlideMasters()[0];
>
> XSLFSlideLayout[] layouts = master.getSlideLayouts();
> Iterator layout_it = new ArrayList(Arrays.asList(layouts)).iterator();
> while(layout_it.hasNext()){
> XSLFSlideLayout layout = (XSLFSlideLayout) layout_it.next();
> XSLFSlide slide = pptx.createSlide(layout);
> XSLFShape[] shapes = slide.getShapes();
> Iterator shapes_it = new ArrayList(Arrays.asList(shapes)).iterator();
> while(shapes_it.hasNext()){
> XSLFShape shape = (XSLFShape) shapes_it.next();
> System.out.println(shape.getShapeName());
> if (shape instanceof XSLFConnectorShape){
> System.out.println("CONNECTORSHAPE");
> } else if (shape instanceof XSLFTextShape){
> System.out.println("TEXTSHAPE");
> } else if (shape instanceof XSLFPictureShape){
> System.out.println("PICTURESHAPE");
> }
> }
> }
>
> return;
> }
> }
> ---
>
> And the result is:
>
> $ java Powerpoint
> Title 1
> TEXTSHAPE
> Subtitle 2
> TEXTSHAPE
> Text Placeholder 20
> TEXTSHAPE
> Text Placeholder 22
> TEXTSHAPE
> Picture Placeholder 24
> TEXTSHAPE
> Table Placeholder 26
> TEXTSHAPE
>
> Obviously Picture Placeholder 24 and Table Placeholder 26 shouldn't be
> Textshapes.
>
> Am I doing anything wrong or Powerpoint saves this in a wrong format?
>
> Thanks in advance.
>
>
> -
> - *Pablo Rivera*
> - Software Engineer
> -
> - [email protected]
> - T:(+34) 902 10 83 84
> -
> -
> - www.mediasq.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]