【问题标题】:How to delete blank line at beginning of docx from officer如何从官员删除docx开头的空白行
【发布时间】:2018-01-20 01:31:18
【问题描述】:

我正在使用 officerR 创建一个 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_add_par 缺少一个 pos 参数,我可以将其设置为 before,这将调整 docx 文档中文本的位置……我的错。跨度>

标签: r officer


【解决方案1】:

要删除一个段落,你需要使用函数body_remove()。请参阅此处的文档:https://davidgohel.github.io/officer/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")

【讨论】:

  • 谢谢!我不需要删除一个段落,因为我从一个空白模板开始......它只是 body_add_par 中的光标位置参数,我已经省略了,现在看起来很愚蠢,因为我没有完全阅读文档.. .感谢officer
  • 您能验证我的解决方案吗?这回答了你原来的问题。
猜你喜欢
  • 1970-01-01
  • 2023-03-31
  • 2019-01-15
  • 1970-01-01
  • 1970-01-01
  • 2020-07-09
  • 1970-01-01
  • 2011-05-30
  • 2022-01-03
相关资源
最近更新 更多