R主管程序包:哪个布局属性确定适当的索引以唯一标识占位符?

时间:2018-08-02 18:52:17

标签: r powerpoint officer

根据军官包文档:

  

索引在幻灯片布局中的类型不唯一时使用

但是,我找不到任何标识占位符的属性确定其索引的信息。

下面,我提供了layout_properties()的示例输出。

   master_name   name type id            ph_label     offx      offy       cx        cy
148      master layout body 14  Text Placeholder 4 7.500000 0.9791667 2.500000 0.5000000
150      master layout body 13 Text Placeholder 16 8.333333 1.6458333 1.416667 1.0000000
151      master layout body 12 Text Placeholder 13 1.583333 5.1458333 5.916667 0.4791667

我看到三种可能为每个文本占位符确定正确的索引值。

  1. 在列id中排名。从示例开始,从顶部开始,索引= 3、2、1
  2. 在列ph_label中的数值旁边。索引= 1、3、2
  3. 按行顺序排列。索引= 1、2、3

编辑

对于将来的用户,确定正确索引的是行顺序。

奇怪的是,行顺序最初是我的猜测,但是我发现该规则有些例外。这些异常的原因实际上是,即使本地代码与模板文件完全相同,本地计算机上的布局属性输出还是与闪亮服务器上的输出有所不同。现在为什么会这样?...我不知道。

1 个答案:

答案 0 :(得分:0)

据我所知,索引是用户提供的幻灯片位置,layout_properties显示了实际的幻灯片布局。我不相信那里有什么与索引位置相对应。

例如:

doc <- read_pptx() %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  ph_with_text(type = "body", str = "body (index 1) is text") %>% 
  ph_with_text(type = "body", str = "body (index 2) is also text")
print(doc, target = "C:/Foo/doc_1.pptx") # Since type is not unique, both are body, they get printed as if they are the same, at the same index position on top of each other.

> layout_properties(doc)
    master_name              name     type id                   ph_label      offx      offy       cx        cy
1  Office Theme    Section Header     body  3         Text Placeholder 2 0.7899311 3.1788200 8.500000 1.6406245
2  Office Theme        Comparison     body  5         Text Placeholder 4 5.0798611 1.6788200 4.420139 0.6996522
3  Office Theme        Comparison     body  6      Content Placeholder 5 5.0798611 2.3784722 4.420139 4.3211811
4  Office Theme        Comparison     body  4      Content Placeholder 3 0.5000000 2.3784722 4.418403 4.3211811
5  Office Theme Title and Content     body  3      Content Placeholder 2 0.5000000 1.7500000 9.000000 4.9496533
6  Office Theme       Two Content     body  3      Content Placeholder 2 0.5000000 1.7500000 4.416667 4.9496533
7  Office Theme       Two Content     body  4      Content Placeholder 3 5.0833333 1.7500000 4.416667 4.9496533
8  Office Theme        Comparison     body  3         Text Placeholder 2 0.5000000 1.6788200 4.418403 0.6996522
9  Office Theme       Title Slide       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
10 Office Theme Title and Content       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
11 Office Theme        Title Only       dt  3         Date Placeholder 2 0.5000000 6.9513889 2.333333 0.3993056
12 Office Theme       Two Content       dt  5         Date Placeholder 4 0.5000000 6.9513889 2.333333 0.3993056
13 Office Theme    Section Header       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
14 Office Theme        Comparison       dt  7         Date Placeholder 6 0.5000000 6.9513889 2.333333 0.3993056
15 Office Theme             Blank       dt  2         Date Placeholder 1 0.5000000 6.9513889 2.333333 0.3993056
16 Office Theme       Two Content      ftr  6       Footer Placeholder 5 3.4166667 6.9513889 3.166667 0.3993056
17 Office Theme       Title Slide      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
18 Office Theme        Comparison      ftr  8       Footer Placeholder 7 3.4166667 6.9513889 3.166667 0.3993056
19 Office Theme             Blank      ftr  3       Footer Placeholder 2 3.4166667 6.9513889 3.166667 0.3993056
20 Office Theme        Title Only      ftr  4       Footer Placeholder 3 3.4166667 6.9513889 3.166667 0.3993056
21 Office Theme Title and Content      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
22 Office Theme    Section Header      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
23 Office Theme        Comparison   sldNum  9 Slide Number Placeholder 8 7.1666667 6.9513889 2.333333 0.3993056
24 Office Theme        Title Only   sldNum  5 Slide Number Placeholder 4 7.1666667 6.9513889 2.333333 0.3993056
25 Office Theme Title and Content   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
26 Office Theme    Section Header   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
27 Office Theme       Title Slide   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
28 Office Theme             Blank   sldNum  4 Slide Number Placeholder 3 7.1666667 6.9513889 2.333333 0.3993056
29 Office Theme       Two Content   sldNum  7 Slide Number Placeholder 6 7.1666667 6.9513889 2.333333 0.3993056
30 Office Theme        Title Only    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
31 Office Theme Title and Content    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
32 Office Theme       Two Content    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
33 Office Theme    Section Header    title  2                    Title 1 0.7899311 4.8194444 8.500000 1.4895833
34 Office Theme        Comparison    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
35 Office Theme       Title Slide ctrTitle  2                    Title 1 0.7500000 2.3298611 8.500000 1.6076389
36 Office Theme       Title Slide subTitle  3                 Subtitle 2 1.5000000 4.2500000 7.000000 1.9166667

doc <- doc %>% ph_with_text(type = "body", str = " text at real index 2", index = 2)
print(doc, target = "C:/Foo/doc_2.pptx") # Using the same pptx layout, adds text at index = 2.

> layout_properties(doc) # Comparing them, they don't appear to have new text placeholder entries.
    master_name              name     type id                   ph_label      offx      offy       cx        cy
1  Office Theme    Section Header     body  3         Text Placeholder 2 0.7899311 3.1788200 8.500000 1.6406245
2  Office Theme        Comparison     body  5         Text Placeholder 4 5.0798611 1.6788200 4.420139 0.6996522
3  Office Theme        Comparison     body  6      Content Placeholder 5 5.0798611 2.3784722 4.420139 4.3211811
4  Office Theme        Comparison     body  4      Content Placeholder 3 0.5000000 2.3784722 4.418403 4.3211811
5  Office Theme Title and Content     body  3      Content Placeholder 2 0.5000000 1.7500000 9.000000 4.9496533
6  Office Theme       Two Content     body  3      Content Placeholder 2 0.5000000 1.7500000 4.416667 4.9496533
7  Office Theme       Two Content     body  4      Content Placeholder 3 5.0833333 1.7500000 4.416667 4.9496533
8  Office Theme        Comparison     body  3         Text Placeholder 2 0.5000000 1.6788200 4.418403 0.6996522
9  Office Theme       Title Slide       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
10 Office Theme Title and Content       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
11 Office Theme        Title Only       dt  3         Date Placeholder 2 0.5000000 6.9513889 2.333333 0.3993056
12 Office Theme       Two Content       dt  5         Date Placeholder 4 0.5000000 6.9513889 2.333333 0.3993056
13 Office Theme    Section Header       dt  4         Date Placeholder 3 0.5000000 6.9513889 2.333333 0.3993056
14 Office Theme        Comparison       dt  7         Date Placeholder 6 0.5000000 6.9513889 2.333333 0.3993056
15 Office Theme             Blank       dt  2         Date Placeholder 1 0.5000000 6.9513889 2.333333 0.3993056
16 Office Theme       Two Content      ftr  6       Footer Placeholder 5 3.4166667 6.9513889 3.166667 0.3993056
17 Office Theme       Title Slide      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
18 Office Theme        Comparison      ftr  8       Footer Placeholder 7 3.4166667 6.9513889 3.166667 0.3993056
19 Office Theme             Blank      ftr  3       Footer Placeholder 2 3.4166667 6.9513889 3.166667 0.3993056
20 Office Theme        Title Only      ftr  4       Footer Placeholder 3 3.4166667 6.9513889 3.166667 0.3993056
21 Office Theme Title and Content      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
22 Office Theme    Section Header      ftr  5       Footer Placeholder 4 3.4166667 6.9513889 3.166667 0.3993056
23 Office Theme        Comparison   sldNum  9 Slide Number Placeholder 8 7.1666667 6.9513889 2.333333 0.3993056
24 Office Theme        Title Only   sldNum  5 Slide Number Placeholder 4 7.1666667 6.9513889 2.333333 0.3993056
25 Office Theme Title and Content   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
26 Office Theme    Section Header   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
27 Office Theme       Title Slide   sldNum  6 Slide Number Placeholder 5 7.1666667 6.9513889 2.333333 0.3993056
28 Office Theme             Blank   sldNum  4 Slide Number Placeholder 3 7.1666667 6.9513889 2.333333 0.3993056
29 Office Theme       Two Content   sldNum  7 Slide Number Placeholder 6 7.1666667 6.9513889 2.333333 0.3993056
30 Office Theme        Title Only    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
31 Office Theme Title and Content    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
32 Office Theme       Two Content    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
33 Office Theme    Section Header    title  2                    Title 1 0.7899311 4.8194444 8.500000 1.4895833
34 Office Theme        Comparison    title  2                    Title 1 0.5000000 0.3003478 9.000000 1.2500000
35 Office Theme       Title Slide ctrTitle  2                    Title 1 0.7500000 2.3298611 8.500000 1.6076389
36 Office Theme       Title Slide subTitle  3                 Subtitle 2 1.5000000 4.2500000 7.000000 1.9166667

doc <- read_pptx() %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  ph_with_text(type = "body", str = "A first text", index = 1) %>%
  ph_with_text(type = "body", str = "A second text", index = 2) %>%
  ph_with_text(type = "title", str = "A title")
print(doc, target = "C:/Foo/doc_3.pptx") # Add index values for the two "body" types, and they'll print in your supplied order/place.

doc4 <- read_pptx() %>%
  add_slide(layout = "Two Content", master = "Office Theme") %>%
  ph_with_text(type = "body", str = "body (index 1) is text") %>% 
  ph_add_text(str = "Bullet text") %>% 
  ph_add_par(level = 1) %>% 
  ph_add_text(str = "Bullet text 2") %>%
  ph_add_par(level = 2) %>% 
  ph_add_text(str = "Lower level text 2")
  print(doc4, target = "C:/Foo/doc_4.pptx")
layout_properties(doc4) # Looks the same