Class ContentService
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Serviço de conteúdo
Serviço para retornar conteúdo de texto de um script.
É possível exibir texto de várias formas. Por exemplo, publique este script como um app da Web.
function doGet() {
return ContentService.createTextOutput('Hello World');
}
Ao acessar o URL do app da Web, você vai encontrar a mensagem "Hello World" no navegador. Por motivos de segurança, os scripts não podem retornar conteúdo diretamente a um navegador. Em vez disso, eles precisam exibir o
conteúdo de um URL diferente. É por isso que o URL no navegador para a saída criada por esse app da Web será diferente do URL do script original.
Propriedades
Propriedade | Tipo | Descrição |
MimeType | MimeType | |
Documentação detalhada
createTextOutput()
Crie um novo objeto TextOutput
.
function doGet() {
const output = ContentService.createTextOutput();
output.append('Hello world!');
return output;
}
Retornar
TextOutput
: o novo objeto TextOutput.
createTextOutput(content)
Crie um novo objeto TextOutput
que possa veicular o conteúdo fornecido.
function doGet() {
const output = ContentService.createTextOutput('Hello world!');
return output;
}
Parâmetros
Nome | Tipo | Descrição |
content | String | o conteúdo a ser veiculado. |
Retornar
TextOutput
: o novo objeto TextOutput.
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
Última atualização 2025-07-26 UTC.
[null,null,["Última atualização 2025-07-26 UTC."],[[["\u003cp\u003eContentService allows scripts to return text content, which can be served as a web app.\u003c/p\u003e\n"],["\u003cp\u003eDue to security, content is served from a different URL than the original script URL.\u003c/p\u003e\n"],["\u003cp\u003eIt provides methods like \u003ccode\u003ecreateTextOutput()\u003c/code\u003e to generate and manipulate text output objects.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ecreateTextOutput()\u003c/code\u003e can be used with or without initial content, enabling flexible content creation.\u003c/p\u003e\n"]]],[],null,["# Class ContentService\n\nContentService\n\nService for returning text content from a script.\n\nYou can serve up text in various forms. For example, publish this script as a web app.\n\n```javascript\nfunction doGet() {\n return ContentService.createTextOutput('Hello World');\n}\n```\nWhen visiting the web app URL you will see \"Hello World\" in the browser. Due to security considerations, scripts cannot directly return content to a browser. Instead, they must serve the content from a different URL. This is why the URL in the browser for output created via this web app will be different than the original script URL. \n\n### Properties\n\n| Property | Type | Description |\n|--------------|------------------------------------------------------|-------------|\n| `Mime``Type` | [MimeType](/apps-script/reference/content/mime-type) | |\n\n### Methods\n\n| Method | Return type | Brief description |\n|--------------------------------------------------------|----------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|\n| [createTextOutput()](#createTextOutput()) | [TextOutput](/apps-script/reference/content/text-output) | Create a new [TextOutput](/apps-script/reference/content/text-output) object. |\n| [createTextOutput(content)](#createTextOutput(String)) | [TextOutput](/apps-script/reference/content/text-output) | Create a new [TextOutput](/apps-script/reference/content/text-output) object that can serve the given content. |\n\nDetailed documentation\n----------------------\n\n### `create``Text``Output()`\n\nCreate a new [TextOutput](/apps-script/reference/content/text-output) object.\n\n```javascript\nfunction doGet() {\n const output = ContentService.createTextOutput();\n output.append('Hello world!');\n return output;\n}\n```\n\n#### Return\n\n\n[TextOutput](/apps-script/reference/content/text-output) --- the new TextOutput object.\n\n*** ** * ** ***\n\n### `create``Text``Output(content)`\n\nCreate a new [TextOutput](/apps-script/reference/content/text-output) object that can serve the given content.\n\n```javascript\nfunction doGet() {\n const output = ContentService.createTextOutput('Hello world!');\n return output;\n}\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------|----------|-----------------------|\n| `content` | `String` | the content to serve. |\n\n#### Return\n\n\n[TextOutput](/apps-script/reference/content/text-output) --- the new TextOutput object."]]