Unpredictable behavior using regex and body_replace_all_text in officer package

随声附和 提交于 2019-12-12 05:06:06

问题


I'm using body_replace_all_text() function from officer package to find and replace some tags in a word document.

The behavior of the body_replace_all_text() function is unpredictable, working on some of the tags, but not on all of them.

It's also weird that cursor_reach() functions find the tag, but body_replace_all_text() can't.

Let's assume we have a simple word document, named "test.docx" with just these two tags:

#KS_STAT#

#TAG#
doc_file <- read_docx("test.docx")

doc_file %>%
  body_replace_all_text("#KS_STAT#", toString(Sys.Date())) %>%
  body_replace_all_text("#TAG#", "Test Value", fixed = TRUE) %>%
  print(target = "test_1.docx")

It's expected to replace both tags, but instead return these error messages:

Warning messages:
1: In x$doc_obj$replace_all_text(old_value, new_value, only_at_cursor,  :
  Found 0 instances of '#KS_STAT#' in the document.
2: In x$doc_obj$replace_all_text(old_value, new_value, only_at_cursor,  :
  Found 0 instances of '#TAG#' in the document.

来源:https://stackoverflow.com/questions/57713748/unpredictable-behavior-using-regex-and-body-replace-all-text-in-officer-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!