1

I am trying to produce some powerpoint reports with OfficeR, but am having trouble saving the results to a file.

I am able to process the data and fill the placeholders. The content that is intended for the placeholders is shown when I use slide_summary(), but it is not visible in the output file.

My code looks like this:

# read template
pptx <- read_pptx("sample_pptx.pptx")
# open slide 5
slide <- on_slide(pptx, 5)
# add text to pre-existing placeholder
ph_add_text(slide, str = "sample_text", ph_label = "sample_ph")
# check content of slide
slide_summary(slide)
# save presentation
print(pptx, target = "outfile.pptx")

Output:

> slide_summary(slide)
  type id                             ph_label offx offy cx cy        text
1  body  2                            sample_ph   NA   NA NA NA sample_text

> print(pptx, target = "outfile.pptx")
[1] "C:/Users/mhuber/OfficeR/outfile.pptx"

What ever I do, the text never shows up in my outfile.

David Gohel
  • 9,180
  • 2
  • 16
  • 34
DataWiz
  • 401
  • 6
  • 14
  • I am not able tu run the code because sample_pptx.pptx is missing. Can you make the code reproducible? – David Gohel Jul 12 '19 at 09:48
  • Hi David, great to hear from you so quickly! sample_pptx.pptx is just an empty file with 5 slides and a placeholder on slide 5. [You can download it here](https://www.dropbox.com/s/tumvv0cpzd9x0ga/sample_pptx.pptx?dl=1) – DataWiz Jul 12 '19 at 09:53
  • There may be a bug there... I will need more time to understand. Can't you use ph_with instead and get rid of existing empty slides? In your template, your slides are all empty, ph_add_text is only useful to add text into an existing shape/ph. – David Gohel Jul 12 '19 at 10:18
  • This is just a minimal example, my real powerpoint input files already have content before and after slide 5 unfortunately. I might try to work around the issue with move_slide, but of course I'd prefer to get my original idea to work. – DataWiz Jul 12 '19 at 10:24
  • 1
    sure, I understand. I will soon improve doc et hopefully find time to solve that. Sorry for the inconvenience – David Gohel Jul 12 '19 at 10:27

1 Answers1

0

Until David figures this out, the following workaround functions just fine and doesn't seem to affect performance much (obviously instead of accessing an existing slide, a new one needs to be created from an existing layout, in which the placeholder needs to be present):

# read template
pptx <- read_pptx("sample_pptx.pptx")
# create new slide
pptx <- add_slide(pptx, layout="sample_layout", master="sample_master")
# add text to pre-existing placeholder
ph_with(pptx, value = "sample_text", location = ph_location_label(ph_label = "sample_ph"))
# move slide from end to desired position ( in this case 5)
move_slide(pptx, index=length(pptx), to=5)
# save presentation
print(pptx, target = "outfile.pptx")

It gets more tricky if you don't have an existing layout that suits your needs, but this worked for my case and hopefully it does for others as well.

DataWiz
  • 401
  • 6
  • 14