ph_add_text: append text

Description Usage Arguments Usage Note Examples

View source: R/ppt_ph_manipulate.R

Description

append text in a placeholder. The function let you add text to an existing content in an exiisting shape, existing text will be preserved.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
ph_add_text(
  x,
  str,
  type = "body",
  id = 1,
  id_chr = NULL,
  ph_label = NULL,
  style = fp_text(font.size = 0),
  pos = "after",
  href = NULL,
  slide_index = NULL
)

Arguments

x

an rpptx object

str

text to add

type

placeholder type

id

placeholder index (integer) for a duplicated type. This is to be used when a placeholder type is not unique in the layout of the current slide, e.g. two placeholders with type 'body'. To add onto the first, use id = 1 and id = 2 for the second one. Values can be read from slide_summary.

id_chr

deprecated.

ph_label

label associated to the placeholder. Use column ph_label of result returned by slide_summary.

style

text style, a fp_text object

pos

where to add the new element relative to the cursor, "after" or "before".

href

hyperlink to reach when clicking the text

slide_index

slide index to reach when clicking the text. It will be ignored if href is not NULL.

Usage

If your goal is to add formatted text in a new shape, use ph_with with a block_list instead of this function.

Note

This function will be deprecated in a next release because it is not efficient and make users write complex code. Use instead fpar() to build formatted paragraphs.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fileout <- tempfile(fileext = ".pptx")
my_pres <- read_pptx()
my_pres <- add_slide(my_pres)
my_pres <- ph_with(my_pres, "",
  location = ph_location_type(type = "body"))

small_red <- fp_text(color = "red", font.size = 14)

my_pres <- ph_add_text(my_pres, str = "A small red text.",
  style = small_red)
my_pres <- ph_add_par(my_pres, level = 2)
my_pres <- ph_add_text(my_pres, str = "Level 2")

print(my_pres, target = fileout)

# another example ----
fileout <- tempfile(fileext = ".pptx")

doc <- read_pptx()
doc <- add_slide(doc)
doc <- ph_with(doc, "Un titre 2",
  location = ph_location_type(type = "title"))
doc <- ph_with(doc, "",
  location = ph_location(rotation = 90, bg = "red",
      newlabel = "myph"))
doc <- ph_add_text(doc, str = "dummy text",
  ph_label = "myph")

print(doc, target = fileout)

Example output



officer documentation built on July 21, 2021, 5:07 p.m.