【发布时间】:2021-05-29 22:05:01
【问题描述】:
我正在尝试使用 google drive API 在 google drive 文档中更新像 {name} 这样的单个文本。例如,如果我在文档中有变量 name = 'hello world',则文本 {name} 应替换为 'hello world'。任何帮助表示赞赏。
async function replaceText() {
try {
const id = "144zvxc_xQUuEqKgS5BfjOKMQsfegFI2Vey";
drive.files.update(
{
fileId: id,
requests = [
{
replaceAllText: {
containsText: {
text: "{{firstname}}",
matchCase: true,
},
replaceText: 'hello world',
},
},
]
},
);
console.log(response);
} catch (error) {
console.log(error.message);
}
}
【问题讨论】:
-
关于
I'm trying to update a single text like {name} in a google drive docs with google drive API.,很遗憾,Drive API 的更新方法中没有replaceAllText请求。那么在这种情况下,使用 Google Docs API 怎么样?因为replaceAllText用于Docs API 中的batchUpdate 方法。 Ref -
非常感谢#Tanaike,这正是我正在寻找的东西,不幸的是我不知道应该在哪里设置这些值。你有什么想法或例子会很棒。再次感谢您的帮助。
-
感谢您的回复。从您对
Have you any idea or example could be great.的回复中,我发布了使用 Google Docs API 修改脚本的答案。你能确认一下吗?如果这不是您期望的方向,我深表歉意。