Page 1 of 1

Template error trying to embed Excel Document into PPTX

PostPosted: Thu Jun 26, 2014 2:30 am
by bkbonner
Getting the following error when trying to embed an excel document into a PPTX. Any thoughts?

Code: Select all
2014-06-25 11:23:38,854 ERROR [h] Missing OLE template: NIL
java.io.IOException: com/plutext/ole/templates/NIL not found via classloader.
   at com.plutext.ole.d.c.a(c.java:3)
   at com.plutext.ole.h.a(h.java:14)
   at com.plutext.ole.OleHelperPptx.a(OleHelperPptx.java:40)
   at com.plutext.ole.OleHelperPptx.embed(OleHelperPptx.java:17)
   at com.jnj.eesus.optimizer.service.analysisv2.product.totalSpend.PowerPointGenerator.generatePowerPoint(PowerPointGenerator.java:105)
   at com.jnj.eesus.optimizer.service.analysisv2.product.totalSpend.PowerPointGenerator.main(PowerPointGenerator.java:46)
com.plutext.ole.OLEException: Missing OLE template: NIL2014-06-25 11:23:38,857 ERROR [OleHelperPptx] Missing OLE template: NIL
com.plutext.ole.OLEException: Missing OLE template: NIL
   at com.plutext.ole.h.a(h.java:78)
   at com.plutext.ole.OleHelperPptx.a(OleHelperPptx.java:40)
   at com.plutext.ole.OleHelperPptx.embed(OleHelperPptx.java:17)
   at com.jnj.eesus.optimizer.service.analysisv2.product.totalSpend.PowerPointGenerator.generatePowerPoint(PowerPointGenerator.java:105)
   at com.jnj.eesus.optimizer.service.analysisv2.product.totalSpend.PowerPointGenerator.main(PowerPointGenerator.java:46)

   at com.plutext.ole.h.a(h.java:78)
   at com.plutext.ole.OleHelperPptx.a(OleHelperPptx.java:40)
   at com.plutext.ole.OleHelperPptx.embed(OleHelperPptx.java:17)
   at com.jnj.eesus.optimizer.service.analysisv2.product.totalSpend.PowerPointGenerator.generatePowerPoint(PowerPointGenerator.java:105)
   at com.jnj.eesus.optimizer.service.analysisv2.product.totalSpend.PowerPointGenerator.main(PowerPointGenerator.java:46)



[code]
   public void generatePowerPoint(Object obj) throws Pptx4jException,
         Docx4JException, JAXBException, IOException, OLEException {
      String outputfilepath = System.getProperty("user.dir")
            + "/OUT_Table.pptx";

      PresentationMLPackage presentationMLPackage = PresentationMLPackage
            .createPackage();

      EmbeddingType xlsx = EmbeddingType.XLSX;

      MainPresentationPart pp = (MainPresentationPart) presentationMLPackage
            .getParts().getParts()
            .get(new PartName("/ppt/presentation.xml"));

      SlideLayoutPart slideLayoutPart = (SlideLayoutPart) presentationMLPackage
            .getParts().getParts()
            .get(new PartName("/ppt/slideLayouts/slideLayout1.xml"));

      SlidePart slidePart = new SlidePart(new PartName(
            "/ppt/slides/slide1.xml"));
      slidePart.setContents(SlidePart.createSld());
      pp.addSlide(slidePart);
      slidePart.addTargetPart(slideLayoutPart);

      // CTGraphicalObjectFrame frame = getTable1();
      //
      //
      // slidePart.getContents().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(frame);
      //

      String table1 = System.getProperty("user.dir") + "/sheet1.xlsx";
      String temp = System.getProperty("user.dir") + "/temp.xlsx";
      FileInputStream fis = new FileInputStream(table1);
      byte[] content = IOUtils.toByteArray(fis);

      OleHelperPptx helper = new OleHelperPptx(presentationMLPackage);
      helper.embed(slidePart, 100, 200, content, null, null,
            EmbeddingType.XLSX, "Test", table1, temp);

      presentationMLPackage.save(new File(outputfilepath));[/code]

   }

Re: Template error trying to embed Excel Document into PPTX

PostPosted: Fri Jul 04, 2014 10:53 am
by jason
Per our email correspondence, Microsoft doesn't use ole for that scenario. Try it in PowerPoint and unzip the result:- the xlsx itself (as opposed to an ole file) is included in the zip. Some XML is required on the slide to point to it; we ought to be able to help you with that.

The bigger issue is generating an image of the spreadsheet to show the user on the presentation surface. Assuming that is you want an image of the spreadsheet. If you are happy with some other static image, the issue doesn't arise. Otherwise, read on...

If you look at the XML, you'll see:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
        <a:graphic>
          <a:graphicData
uri="http://schemas.openxmlformats.org/presentationml/2006/ole">
            <mc:AlternateContent
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
              <mc:Choice xmlns:v="urn:schemas-microsoft-com:vml" Requires="v">

                <p:oleObj spid="_x0000_s1026" name="Worksheet"
r:id="rId3" imgW="6105545" imgH="4010040" progId="Excel.Sheet.12">
                  <p:embed/>
                </p:oleObj>

              </mc:Choice>
              <mc:Fallback>

                <p:oleObj name="Worksheet" r:id="rId3" imgW="6105545"
imgH="4010040" progId="Excel.Sheet.12">
                  <p:embed/>
                  <p:pic>
                    <p:nvPicPr>
                      <p:cNvPr id="0" name=""/>
                      <p:cNvPicPr/>
                      <p:nvPr/>
                    </p:nvPicPr>
                    <p:blipFill>
                      <a:blip r:embed="rId4"/>
                      <a:stretch>
                        <a:fillRect/>
                      </a:stretch>
                    </p:blipFill>
                    <p:spPr>
                      <a:xfrm>
                        <a:off x="1519238" y="1423988"/>
                        <a:ext cx="6105525" cy="4010025"/>
                      </a:xfrm>
                      <a:prstGeom prst="rect">
                        <a:avLst/>
                      </a:prstGeom>
                    </p:spPr>
                  </p:pic>
                </p:oleObj>

              </mc:Fallback>
            </mc:AlternateContent>
          </a:graphicData>
        </a:graphic>
 
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


That is, there are 2 alternative ways of saying, "this is where the
xlsx appears".

The first way is:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
                <p:oleObj spid="_x0000_s1026" name="Worksheet"
r:id="rId3" imgW="6105545" imgH="4010040" progId="Excel.Sheet.12">
                  <p:embed/>
                </p:oleObj>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


The second is the longer:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
                <p:oleObj name="Worksheet" r:id="rId3" imgW="6105545"
imgH="4010040" progId="Excel.Sheet.12">
                  <p:embed/>
                  :
                      <a:blip r:embed="rId4"/>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


docx4j currently uses the second. Notice it contains @r:id pointing
to the spreadsheet, and @r:embed, which point to an image the users
sees on the sheet surface, which happens to look like the spreadsheet
contents.

So with this second representation, if you want an updated image, you
need to manually generate it somehow.

With the first representation, it looks possible that the image is
generated by Office when the pptx is opened (since there is no image).
But in fact Powerpoint does still seem to conjure the "old" image from
somewhere, and does not update it until you activate the spreadsheet
by clicking on it.

In summary, in either case, if you want an image of the
spreadsheet, you need to generate it yourself.