gpt4 book ai didi

官:编辑Word表格

转载 作者:行者123 更新时间:2023-12-04 15:59:23 24 4
gpt4 key购买 nike

使用“官员”,我正在尝试编辑 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")

关于官:编辑Word表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50927835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com