Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with cl_pptx_document

0 Kudos

Hello together,

I'm trying to use the class "cl_pptx_document" and "cl_pptx_presentationpart" to add slides to a pptx Template.

I have a template (P1) with all the slides I needed and a second template (P2) with just the welcome page. Now I want to insert different parts from P1 into P2.

As first I loaded the document, get the presentationpart and get all parts from p1:

DATA(ppt)= cl_pptx_document=>load_document( iv_data ='xstring ppt').
DATA(presentationpart)= ppt->get_presentationpart().
DATA(slide_parts)= presentationpart->get_slideparts().

In the next step i tried to load different parts in my P2-object and try to download the modified P2.

...
presentationpart->add_part( ir_part ='Single Part from part_collection').
DATA(final_pptx)= ppt->get_package_data()
...

But that dont work...

The second way I tried, was to feed the presentationpart with xml data of a slide. When I open the Powerpoint after that, there is no new Slide. Instead, an error message appear. But when I open the pptx with notepad, I see the new xml data of the slide. I think that there are some Relations are missing.

presentationpart = ppt->get_presentationpart( ).
DATA(slide_part) = presentationpart->add_slidepart( ).
slide_part->feed_data( iv_data = ls_slide2-xdata ).

How can I set the relations?

It's possible to move parts from one Object to another? Or do I have to pay attention to something (Relationships, IDs) ?

Unfortunately, I couldn't find a any documentation or demos about that classes. So I hope somebody knows something and can help me...or give me a simple example how to add a slide.

Greetz Thimo

1 ACCEPTED SOLUTION

DoanManhQuynh
Active Contributor

you add slide2-data into slidepart, not slide2part-data then it will corrurpt, you have to get slidepart from the first one. I tried below code and i can copy slide.xml without error. Unfortunately, it still not display copied slide in new file. I checked and findout that all relationship are correctly set, but in file presentation.xml, copied slides didnt insert below slide list tag yet ( p:sldIdLst ), so i manually change this file and copied file shown in new file. i dont really famaliar with OOXML, so maybe you have to search on internet about it ( ABAP OOXML for powerpoint may not hard to find but in C#, VB...there are alot );in mean time, you could try add a missing tag to presentation.xml using transformation.

      l_package = cl_pptx_document=>load_document( iv_data = l_infile )."P2 file
      l_present = l_package->get_presentationpart( ).
      l_slide = l_present->add_slidepart( ).

      l_slide->feed_data( iv_data = cl_pptx_document=>load_document( iv_data = l_cpfile "P1 file
                                                                   )->get_presentationpart(
                                                                   )->get_slideparts(
                                                                   )->get_part( iv_index = 0 )->get_data( ) )."sample index

      l_present->get_id_for_part( ir_part = l_slide ).
      final = l_package->get_package_data( ).
5 REPLIES 5

DoanManhQuynh
Active Contributor

you add slide2-data into slidepart, not slide2part-data then it will corrurpt, you have to get slidepart from the first one. I tried below code and i can copy slide.xml without error. Unfortunately, it still not display copied slide in new file. I checked and findout that all relationship are correctly set, but in file presentation.xml, copied slides didnt insert below slide list tag yet ( p:sldIdLst ), so i manually change this file and copied file shown in new file. i dont really famaliar with OOXML, so maybe you have to search on internet about it ( ABAP OOXML for powerpoint may not hard to find but in C#, VB...there are alot );in mean time, you could try add a missing tag to presentation.xml using transformation.

      l_package = cl_pptx_document=>load_document( iv_data = l_infile )."P2 file
      l_present = l_package->get_presentationpart( ).
      l_slide = l_present->add_slidepart( ).

      l_slide->feed_data( iv_data = cl_pptx_document=>load_document( iv_data = l_cpfile "P1 file
                                                                   )->get_presentationpart(
                                                                   )->get_slideparts(
                                                                   )->get_part( iv_index = 0 )->get_data( ) )."sample index

      l_present->get_id_for_part( ir_part = l_slide ).
      final = l_package->get_package_data( ).

0 Kudos

Thank you very much! That helps me a lot.

The Insertion of a slide from another Template works fine. I insert the slide and added the ID manually in the presentation.xml. But the new silde still doesn't appear. I unpacked the modified Powerpoint and checked the Relations. Finally I found out, that the Relation (ppt/slides/_rels) wasn't set.

Now I try to find a way to set it too.

0 Kudos

That relationship nothing but between slide and theme. maybe you need to add theme too. You may see all the related file with those slides you want to copy using this program: ROPENXML_LISTER, may have some light there.

0 Kudos

I have set the relationship manually and now it works. Thank you.

0 Kudos

Hai,

I am also trying to add a new slide to ppt. But getting the same error. Could you please explain how you set the relationships manually.

Thanks ,

Lakshmi Sankergi