【发布时间】:2015-02-26 15:16:49
【问题描述】:
我在getCursor() 行收到错误We're sorry, a server error occurred. Please wait a bit a try again。
这是代码。很简单。
function onOpen() {
DocumentApp.getUi() // Or DocumentApp or FormApp.
.createMenu('Checkbox')
.addItem('Insert Checkbox', 'insertCheckbox')
.addToUi();
}
function insertCheckbox() {
var cursor = DocumentApp.getActiveDocument().getCursor(); // CODE BREAKS HERE
if (cursor) {
// Attempt to insert text at the cursor position. If the insertion returns null, the cursor's
// containing element doesn't allow insertions, so show the user an error message.
var element = cursor.insertText('ಠ‿ಠ');
if (element) {
element.setBold(true);
} else {
DocumentApp.getUi().alert('Cannot insert text here.');
}
} else {
DocumentApp.getUi().alert('Cannot find a cursor.');
}
}
有什么想法吗?
提前致谢。
【问题讨论】:
-
我确实尝试过相同的代码。它工作得很好。再次尝试刷新并运行该函数。
-
您的文档是否在标题中碰巧(或曾经)有图像?如果是这样,它可能与这个问题有关:code.google.com/p/google-apps-script-issues/issues/…
-
感谢 KRR 和 stmcallister 的 cmets。我的文档有一个标题,这似乎是根据该问题触发问题的原因。我假设 KRR 没有标题以及他/她成功运行它的原因。显然现在要删除一个标题。
标签: google-apps-script google-docs