我正在尝试使用“officer”编辑Word表格的值。
非常简单地找到包含它的“段落”
library(officer)
doc = read_docx('template.docx')
doc = cursor_begin(doc)
doc = cursor_reach(doc,"Some text")
print(doc)
我得到一个如下所示的文档:
* Content at cursor location:
row_id is_header cell_id text col_span row_span
1.1 1 FALSE 1 D 1 1
1.5 2 FALSE 1 1 1
1.9 3 FALSE 1 Some text 1 1
1.13 4 FALSE 1 1 1
2.2 1 FALSE 2 More text 1 1
但是,然后呢?似乎没有任何方法可以直接更改该表的内容......
您可以使用body_replace_all_text
为了那个任务。
library(officer)
doc <- read_docx()
doc <- body_add_table(doc, iris, style = "table_template")
doc = cursor_reach(doc, "setosa")
doc <- body_replace_all_text(doc, old_value = "setosa",
new_value = "coco", only_at_cursor = TRUE)
print(doc, target = "test.docx")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)