繁体   English   中英

如何从官员删除docx开头的空白行

[英]How to delete blank line at beginning of docx from officer

我正在使用R officer来创建Word(docx)文档。 这是代码:

library(officer)
library(magrittr)

my_docx = read_docx() %>% 
  # cursor_begin() %<>% 
  body_add_par("Hello here is a test sentence to see if there is a blank line above it.", style = "Normal") %>% 
  print(target = "test.docx")

它会创建一个docx文档,该文档在句子上方的顶部带有空白行。 在字体样式中设置的字体样式前没有空格。 我没有对cursor_begin()进行注释,但是仍然保留空白行。 我该如何摆脱呢?

任何帮助表示赞赏!

要删除一个段落,您需要使用body_remove()函数。 请参阅此处的文档: https : //davidgohel.github.io/zh-CN/articles/word.html#remove-content

library(officer)
library(magrittr)

my_docx <- read_docx() %>% 
  cursor_begin() %>% body_remove() %>% 
  body_add_par("Hello here is a test sentence to see if there is a blank line above it.", 
               style = "Normal") %>% 
  print(target = "test.docx")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM