首页 > 解决方案 > R 官员包:哪个布局属性确定了唯一标识占位符的正确索引?

问题描述

根据官员包裹文件:

当幻灯片布局中的类型不是唯一的时,将使用索引

但是,我找不到任何信息来识别占位符的哪个属性决定了它的索引。

下面,我提供了一个示例输出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

编辑

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

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

标签: rpowerpointofficer

解决方案


据我了解,索引是用户为幻灯片上的位置提供的,并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

推荐阅读