如何将格式化的段落(fpar)添加到Power Point演示文稿中,右对齐,在占位符内

时间:2018-02-13 17:08:05

标签: r powerpoint officer

我在R中使用库officeR创建了以下代码来创建功率点演示。

无论我如何设置属性" text.align"对于fp_par对象(fpar),标题保持居中。

有没有办法在添加了函数add_ph_empty_at()的占位符中添加右对齐的新段落文本?

谢谢!

require(magrittr)
require(officer)

def_text <- fp_text(color = "black", italic = FALSE, font.size = 20)

lastPhId <- function(presentation) {
  index = presentation$cursor
  x <- slide_summary(presentation, index = index)
  x <- x[x$type == "body", ]
  max(as.numeric(x$id))
}

TITLE = fpar(ftext("My Title", prop = def_text))
TITLE <- update(TITLE, fp_p = fp_par(text.align = "left"))

doc <- read_pptx()
doc %<>% add_slide(layout = "Title and Content", master = "Office Theme") 
doc %<>% ph_empty_at(left = 3, top = 3, height = 1, width = 4, bg = "yellow") 
doc %<>% ph_add_fpar(value = TITLE, id_chr = lastPhId(doc))

print(doc, target = "ph_add_fpar.pptx")
system("cmd.exe", input = "ph_add_fpar.pptx")

1 个答案:

答案 0 :(得分:2)

我刚刚在Github上更新了officer,它现在已经解决了。您需要使用新的参数par_default(如果为FALSE):不使用占位符默认段落属性,而是使用fpar对象之一。

require(magrittr)
require(officer)

def_text <- fp_text(color = "black", italic = FALSE, font.size = 20)

lastPhId <- function(presentation) {
  index = presentation$cursor
  x <- slide_summary(presentation, index = index)
  x <- x[x$type == "body", ]
  max(as.numeric(x$id))
}

TITLE = fpar(ftext("My Title", prop = def_text))
TITLE <- update(TITLE, fp_p = fp_par(text.align = "left"))

doc <- read_pptx()
doc %<>% add_slide(layout = "Title and Content", master = "Office Theme") 
doc %<>% ph_empty_at(left = 3, top = 3, height = 1, width = 4, bg = "yellow") 
doc %<>% ph_add_fpar(value = TITLE, id_chr = lastPhId(doc), par_default = FALSE)

print(doc, target = "ph_add_fpar.pptx") %>% browseURL()