R :: officer无法在powerpoint幻灯片中找到行或ID

问题描述 投票:0回答:1

R包官员无法写入powerpoint幻灯片。 Layout_properties确认字段ctrTitle存在但slide_summary报告零行。

> pres<-read_pptx()
> add_slide(x=pres,layout='Title Slide', master="Office Theme")
pptx document with 1 slide(s)
Available layouts and their associated master(s) are:
             layout       master
1       Title Slide Office Theme
2 Title and Content Office Theme
3    Section Header Office Theme
4       Two Content Office Theme
5        Comparison Office Theme
6        Title Only Office Theme
7             Blank Office Theme
> ph_add_text(x=pres, type="ctrTitle", str= "This is the title")
Error: unvalid id 0 (1 slide(s))
> 

字段在layout_properties中退出。

> layout_properties(x=pres, layout="Title Slide", master="Office Theme")
    master_name        name     type id                   ph_label
9  Office Theme Title Slide       dt  4         Date Placeholder 3
17 Office Theme Title Slide      ftr  5       Footer Placeholder 4
27 Office Theme Title Slide   sldNum  6 Slide Number Placeholder 5
35 Office Theme Title Slide ctrTitle  2                    Title 1
36 Office Theme Title Slide subTitle  3                 Subtitle 2
                                            ph     offx     offy       cx
9         <p:ph type="dt" sz="half" idx="10"/> 0.500000 6.951389 2.333333
17    <p:ph type="ftr" sz="quarter" idx="11"/> 3.416667 6.951389 3.166667
27 <p:ph type="sldNum" sz="quarter" idx="12"/> 7.166667 6.951389 2.333333
35                     <p:ph type="ctrTitle"/> 0.750000 2.329861 8.500000
36             <p:ph type="subTitle" idx="1"/> 1.500000 4.250000 7.000000
          cy
9  0.3993056
17 0.3993056
27 0.3993056
35 1.6076389
36 1.9166667
> 

我试图链接命令;错误消息不同。

>     pres<-read_pptx()
>     add_slide(x=pres,layout="Title Slide", master="Office Theme") %>%
+     ph_add_text(type='ctrTitle',str="This is the title")
Error: selection does not match any row in slide_summary. Use function slide_summary.
> 

这给了我一个线索。

> slide_summary(pres, index=1)
[1] type     id       ph_label offx     offy     cx       cy       text    
<0 rows> (or 0-length row.names)
>

slide_summary报告零行。有人可以帮忙吗?

r powerpoint officer
1个回答
1
投票

这是我的工作代码。

pres <- read_pptx()
pres <- add_slide(pres, layout = "Title and Content", master = "Office Theme")
pres <- ph_empty(pres, type = "body")
pres <- ph_add_par(pres, level = 1)
pres <- ph_add_text(pres, str = "这里是文字")

而且我认为你应该考虑库magrittr。然后它可以写成如下:

library("magrittr")
pres <- read_pptx() %>%
    add_slide(layout = "Title and Content", master = "Office Theme") %>%
    ph_empty(type = "body") %>%
    ph_add_par(level = 1) %>%
    ph_add_text(str = "这里是文字")

我看到你想要Title Slide,然后你可以简单地这样写:

pres <- read_pptx() %>%
    add_slide(layout = "Title Slide", master = "Office Theme") %>%
    ph_with_text(type = "ctrTitle", str = "这里是文字")
© www.soinside.com 2019 - 2024. All rights reserved.