1

我在 R 中有以下代码,使用 library officeR 创建 power point 演示文稿。

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

有没有办法在使用 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")
4

1 回答 1

3

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

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()
于 2018-02-14T13:18:35.683 回答