Home > Net >  Apps script Docs Document is closed, its contents cannot be updated
Apps script Docs Document is closed, its contents cannot be updated

Time:11-25

i tried this code:

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


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

but it return error:

Exception: Document is closed, its contents cannot be updated.

Reason why use saveAndClose() func, the text that i append on doc too long so it return error:

ScriptError: Too many changes applied before saving document. 
Please save changes in smaller batches using Document.saveAndClose(), 
then reopen the document with Document.openById().

There doesn't seem to be a way to fix this............

CodePudding user response:

Shouldn't you reopen the document?

Please save changes in smaller batches using Document.saveAndClose(), then reopen the document with 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()
  • Related