使用officer创建的word文档中的页码
与官员创建文档时,我使用 body_end_section_portrait() 和 body_end_section_landscape() 来设置方向。
library(officer)
doc <- officer::read_docx()
doc <- officer::body_add_par(doc, "bla1", style = "Normal")
doc <- officer::body_end_section_portrait(doc)
doc <- officer::body_add_par(doc, "bla2", style = "Normal")
doc <- officer::body_end_section_landscape(doc)
doc <- officer::body_add_par(doc, "bla3", style = "Normal")
doc <- officer::body_end_section_portrait(doc)
print(doc, target = "bb.docx")
当我将页码放入创建的文档中时,它们的顺序不正确。例如,在提供的示例中,创建的文档中的数字为 1、3、5、6。
我做错了什么?
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=Croatian_Croatia.1250 LC_CTYPE=Croatian_Croatia.1250
[3] LC_MONETARY=Croatian_Croatia.1250 LC_NUMERIC=C
[5] LC_TIME=Croatian_Croatia.1250
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] officer_0.4.1 rJava_1.0-6
when creating documents with officer I am using body_end_section_portrait() and body_end_section_landscape() to set up orientations.
library(officer)
doc <- officer::read_docx()
doc <- officer::body_add_par(doc, "bla1", style = "Normal")
doc <- officer::body_end_section_portrait(doc)
doc <- officer::body_add_par(doc, "bla2", style = "Normal")
doc <- officer::body_end_section_landscape(doc)
doc <- officer::body_add_par(doc, "bla3", style = "Normal")
doc <- officer::body_end_section_portrait(doc)
print(doc, target = "bb.docx")
When I put page numbers in the created document they are not in the right order. E.g. in the provided example the numbers in the created document go 1, 3, 5, 6.
What am I doing wrong?
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)
Matrix products: default
locale:
[1] LC_COLLATE=Croatian_Croatia.1250 LC_CTYPE=Croatian_Croatia.1250
[3] LC_MONETARY=Croatian_Croatia.1250 LC_NUMERIC=C
[5] LC_TIME=Croatian_Croatia.1250
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] officer_0.4.1 rJava_1.0-6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,似乎要走的路是使用
body_end_block_section()
,您可以在其中定义分节符类型。首先,我定义了我的部分的外观
现在的代码是(我用
body_end_block_section()
更改了body_end_section_landscape()
/portrait()
):Ok, it seems that the way to go is by using
body_end_block_section()
where you can define the section break type.First I defined how my sections will look like
Now the code is (I changed
body_end_section_landscape()
/portrait()
withbody_end_block_section()
):