问题
I am using the officer
package in R to create reproducible slides. I can add bullets in front of sentences without problem when the sentences are places in the "body" object of the powerpoint template, but when I try to assign the exact location of the sentence, no bullets are included. Please see the script as below:
library(officer)
library(dplyr)
pptx.output.st00 <- read_pptx()
pptx.content1 <- c('sample sentence #1',
'sample sentence #2',
'sample sentence #3')
pptx.content2 <- block_list(fpar(ftext(c('sample sentence #1'),
prop = fp_text(font.family = 'Calibri',font.size=32))),
fpar(ftext(c('sample sentence #2'),
prop = fp_text(font.family = 'Calibri',font.size=32))),
fpar(ftext(c('sample sentence #3'),
prop = fp_text(font.family = 'Calibri',font.size=32))))
pptx.output.st01 <- pptx.output.st00 %>%
add_slide(.,layout = 'Title and Content',master = 'Office Theme') %>%
ph_with(.,value='Background',location=ph_location_type(type='title')) %>%
ph_with(.,value=pptx.content1,location=ph_location_type(type='body',id = 1)) %>%
ph_with(.,value=pptx.content2,location=ph_location(left = 0.5,top = 5.25,width = 8.5,height = 2))
print(pptx.output.st01,'presentation.output.pptx')
I wonder if bullet can also be assigned when the sentences are placed using ph_location
instead of ph_location_type
. Thanks!
回答1:
This should help.
- ph_location_template: need to be used so that we can reuse properties from body (body has associated bullets in properties)
- if used,
level_list
mean to add bullets for each paragraph to add
library(officer)
library(dplyr)
pptx.output.st00 <- read_pptx()
pptx.content1 <- c('sample sentence #1',
'sample sentence #2',
'sample sentence #3')
pptx.content2 <- block_list(fpar(ftext(c('sample sentence #1'),
prop = fp_text(font.family = 'Calibri',font.size=32))),
fpar(ftext(c('sample sentence #2'),
prop = fp_text(font.family = 'Calibri',font.size=32))),
fpar(ftext(c('sample sentence #3'),
prop = fp_text(font.family = 'Calibri',font.size=32))))
pptx.output.st01 <- pptx.output.st00 %>%
add_slide(.,layout = 'Title and Content',master = 'Office Theme') %>%
ph_with(.,value='Background',location=ph_location_type(type='title')) %>%
ph_with(.,value=pptx.content1,location=ph_location_type(type='body',id = 1)) %>%
ph_with(.,value=pptx.content2,
location = ph_location_template(left = 0.5,top = 5.25,width = 8.5,height = 2, type="body"),
level_list = 1:3)
print(pptx.output.st01,'presentation.output.pptx')
来源:https://stackoverflow.com/questions/62170294/adding-bullet-before-statement-in-powerpoint-via-officer-in-r