我正在尝试使用Google Apps脚本为Google文档制作实时自动更正的附加内容 [英] I am trying to make a real-time auto-correct sort of add-on for Google Docs using Google Apps Script
问题描述
我试图使用Google Apps脚本为Google文档制作实时自动更正的附加内容。我写了很多代码,但无法弄清楚为什么fixWords函数不起作用。每当我输入一个单词时,它都不会自动更正。这是我的代码:
function fixWords(){
var body = DocumentApp.getActiveDocument()。getBody() ;
//开始替换...
body.replaceText(accomodate,adapt);
body.replaceText(accomodation,accommodation);
body.replaceText(acheive,达到);
body.replaceText(accross,across);
body.replaceText(agressive,aggressive);
body.replaceText(agression,aggression);
body.replaceText(显然,显然);
body.replaceText(appearence,appearance);
body.replaceText(arguement,argument);
body.replaceText(assasination,暗杀);
body.replaceText(基本上,基本上);
}
有什么建议吗?我是Apps Script的新手,但有三年的编程时间。 解决方案
在工具菜单下,点击偏好设置。您还可以添加个人字典。
如果您可以从代码添加个人字典,那可能会起作用,但我没有办法做到这一点。
没有任何触发器或方法可以针对每个按键进行监控Google文档。请参阅文档:
有些东西需要触发你的函数在每次击键时运行。在电子表格中, 是 onEdit()
简单触发器,用于监视对单元格的每次更改。但是Google Docs没有这种功能。
Google文档中唯一可用的事件类型是 open
。
I am trying to make a real-time auto-correct sort of add-on for Google Docs using Google Apps Script. I have written a lot of code, yet cannot figure out why the fixWords function does not work. Whenever I type a word, it does not auto-correct. This is my code:
function fixWords() {
var body = DocumentApp.getActiveDocument().getBody();
//The start of replacing...
body.replaceText("accomodate","accommodate");
body.replaceText("accomodation","accommodation");
body.replaceText("acheive","achieve");
body.replaceText("accross","across");
body.replaceText("agressive","aggressive");
body.replaceText("agression","aggression");
body.replaceText("apparantly","apparently");
body.replaceText("appearence","appearance");
body.replaceText("arguement","argument");
body.replaceText("assasination","assassination");
body.replaceText("basicly","basically");
}
Any suggestions? I am a newbie to Apps Script but have programming for three years.
There is something in Docs for automatic substitution. Under the tools, menu, click preferences. You can also add a personal dictionary.
If you could add a personal dictionary from code, that would probably work, but I don't see a way to do that.
There is no trigger or way to monitor a Google doc for every keystroke made. See the documentation:
Something would need to trigger your function to run on every keystroke. In a spreadsheet, there is an onEdit()
simple trigger that monitors every change to a cell. But there is nothing like that for Google Docs.
The only event type available to a Google Doc is open
.
这篇关于我正在尝试使用Google Apps脚本为Google文档制作实时自动更正的附加内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!