Content Service

  • The Content Service allows scripts to serve text in various formats like text, XML, or JSON.

  • The ContentService class is used for returning text content from a script.

  • The MimeType enum defines the various mime types that can be served from a script.

  • The TextOutput object represents the text content that can be served from a script.

Content

This service allows scripts to serve text in various forms, such as text, XML, or JSON. See also the guide to Content Service. If you deploy the following script as a web app, you will see "Hello, world!" in the browser:

function doGet() {
 return ContentService.createTextOutput('Hello, world!');
}

Classes

NameBrief description
ContentService Service for returning text content from a script.
MimeType An enum for mime types that can be served from a script.
TextOutput A TextOutput object that can be served from a script.

ContentService

Properties

PropertyTypeDescription
MimeTypeMimeType

Methods

MethodReturn typeBrief description
createTextOutput() TextOutput Create a new TextOutput object.
createTextOutput(content) TextOutput Create a new TextOutput object that can serve the given content.

MimeType

Properties

PropertyTypeDescription
CSVEnumCSV Mime Type
ICALEnumICAL Mime Type
JAVASCRIPTEnumJAVASCRIPT Mime Type
JSONEnumJSON Mime Type
TEXTEnumTEXT Mime Type
VCARDEnumVCARD Mime Type

TextOutput

Methods

MethodReturn typeBrief description
append(addedContent) TextOutput Appends new content to the content that will be served.
clear() TextOutput Clears the current content.
downloadAsFile(filename) TextOutput Tells browsers to download rather than display this content.
getContent() StringGets the content that will be served.
getFileName() StringReturns the file name to download this file as, or null if it should be displayed rather than downloaded.
getMimeType() MimeType Get the mime type this content will be served with.
setContent(content) TextOutput Sets the content that will be served.
setMimeType(mimeType) TextOutput Sets the mime type for content that will be served.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年12月11日 UTC.