【问题标题】:Docs Document is closed, its contents cannot be updatedDocs 文档已关闭,无法更新其内容
【发布时间】:2022-11-28 09:40:46
【问题描述】:

我试过这段代码:

var doc1 = DocumentApp.openById("ididididddddddddddidididididididi")
doc1.getBody().editAsText().appendText('hello text here')
doc1.saveAndClose()


doc1.getBody().editAsText().appendText('second text here')
doc1.saveAndClose()

但它返回错误:

异常:文档已关闭,无法更新其内容。

使用saveAndClose() func 的原因,我在文档上附加的文本太长,因此返回错误:

ScriptError:保存文档前应用了太多更改。 请使用 Document.saveAndClose() 以较小的批量保存更改, 然后使用 Document.openById() 重新打开文档。

似乎没有办法解决这个问题…………

【问题讨论】:

    标签: javascript google-apps-script google-docs


    【解决方案1】:

    你不应该重新打开文档吗?

    请使用 Document.saveAndClose() 以较小的批量保存更改, 然后使用 Document.openById() 重新打开文档。

    var doc1 = DocumentApp.openById("ididididddddddddddidididididididi")
    doc1.getBody().editAsText().appendText('hello text here')
    doc1.saveAndClose()
    
    var doc1 = DocumentApp.openById("ididididddddddddddidididididididi")
    doc1.getBody().editAsText().appendText('second text here')
    doc1.saveAndClose()
    

    【讨论】:

    • 您的答案可以通过其他支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写出好的答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 2012-06-24
    • 2018-02-20
    • 2022-06-16
    • 1970-01-01
    • 2019-09-13
    • 2016-10-16
    • 1970-01-01
    相关资源
    最近更新 更多