class DocumentApp method .setText()

DocumentApp is the Apps Script service.

.setText() is the method name you will see after a dot in your code.

What it does

Replaces the text content of a document element.

Why it's used

  • Replace a placeholder like client name with real data.
  • Mail-merge style updates from a row in your spreadsheet.

Common errors

  • Forgetting parentheses on setText. Write DocumentApp.setText(), not DocumentApp.setText or setText by itself.
  • Skipping dots between chained calls. Each step needs a dot, like DocumentApp.getActiveDocument().getBody().setText().
  • Adding spaces where they do not belong. Write DocumentApp.setText(), not DocumentApp .setText(), DocumentApp.setText (), or DocumentApp . setText().
  • Wrong capitalization. Use DocumentApp and setText, not documentapp or settext.

Explore

Related methods

Better Sheets tutorials

No tagged tutorials yet. Fetch Apps Script from the harvest table and this page fills automatically.

Related blog posts

Written guides about DocumentApp.setText().

Browse the blog