0

I'm trying to bold a single word within a sentence in an unordered list bullet (in PPT). Is this possible? Putting a combination of fpar/ftext objects into the str_list within unordered_list throws an error. Thanks in advance.

EDIT, adding example of what I mean:

example

HRcode
  • 3
  • 2
  • Welcome to Stack Overflow ! You should provide a reproductible example of your code. See https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – gdevaux Nov 13 '19 at 07:31

3 Answers3

1

This is documented here:

https://davidgohel.github.io/officer/articles/offcran/powerpoint.html#unordered-lists

library(officer)
doc <- read_pptx()

ul <- unordered_list(
  level_list = c(1, 2, 2, 3, 3, 1),
  str_list = c("Level1", "Level2", "Level2", "Level3", "Level3", "Level1"),
  style = fp_text(color = "red", bold = TRUE, font.size = 25) )

doc <- add_slide(doc)
doc <- ph_with(x = doc, value = ul, location = ph_location_type(type = "body") )

print(doc, target = "ph_with_ul.pptx")

enter image description here

David Gohel
  • 9,180
  • 2
  • 16
  • 34
  • Thanks, David. I've reviewed that, but it seems like that only deals with applying a single format to all of the text. What if we want to different font colors in the same bullet? – HRcode Nov 13 '19 at 16:05
0

I have the same issue. My colleague gave me this chunk of code:

pres_1 <- read_pptx(path = template) %>%
    add_slide(layout = 'Title and Content', master = 'Office Theme') %>%
    ph_empty(type = 'body') %>%
    ph_add_par() %>%
    ph_add_text(str = 'this is a red text', style =  fp_text(color = 'red', font.size = 20)) %>%
    ph_add_text(str = ' followed by a blue text', style = fp_text(color = 'blue', font.size = 20)) %>%
    ph_add_par(level = 2) %>%
    ph_add_text(str = 'Level 2', style = shortcuts$fp_italic() ) %>%
    ph_add_par(level = 3) %>%
    ph_add_text(str = 'Level 3', style = shortcuts$fp_bold())

  print(pres_1, "test.pptx")

It still works with officer 0.3.5 but it is not documented any more on the documentation page of the current package version (https://davidgohel.github.io/officer/index.html).

I wonder what would be the intended way to implement this using the function documentation from the above site.

Daniel
  • 36
  • 1
  • Update: this worked. I did have a corrupt PPT file when opening, but that was down to some shapes I had hard-coded in the template. I removed those shapes and added them back in via ph_with_img_at instead, and that worked. It's unclear why those shapes would have interfered with the formatted text. – HRcode Nov 21 '19 at 23:44
0

You may try the following, which works for me:

library(officer)
doc <- read_pptx()

ul <- unordered_list(
  level_list = c(1, 2, 2, 3, 3, 1),
  str_list = c("Level1", "Level2", "Level2", "Level3", "Level3", "Level1"),
  style = list(fp_text(color = "red", bold = TRUE, font.size = 25),
               fp_text(color = "blue", bold = TRUE, font.size = 25)
               fp_text(color = "yellow", bold = TRUE, font.size = 25)
               fp_text(color = "red", bold = TRUE, font.size = 25)
               fp_text(color = "blue", bold = TRUE, font.size = 25)
               fp_text(color = "yellow", bold = TRUE, font.size = 25)))

doc <- add_slide(doc)
doc <- ph_with(x = doc, value = ul, location = ph_location_type(type = "body") )

print(doc, target = "ph_with_ul.pptx")
lokheart
  • 23,743
  • 39
  • 98
  • 169