Class ContentService
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
콘텐츠서비스
스크립트에서 텍스트 콘텐츠를 반환하는 서비스입니다.
다양한 형식으로 텍스트를 게재할 수 있습니다. 예를 들어 이 스크립트를 웹 앱으로 게시합니다.
function doGet() {
return ContentService.createTextOutput('Hello World');
}
웹 앱 URL을 방문하면 브라우저에 'Hello World'가 표시됩니다. 보안상의 이유로 스크립트는 브라우저에 콘텐츠를 직접 반환할 수 없습니다. 대신 다른 URL에서 콘텐츠를 게재해야 합니다. 이 때문에 이 웹 앱을 통해 생성된 출력의 브라우저 URL이 원래 스크립트 URL과 다릅니다.
자세한 문서
createTextOutput()
새로운 TextOutput
객체를 만듭니다.
function doGet() {
const output = ContentService.createTextOutput();
output.append('Hello world!');
return output;
}
리턴
TextOutput
: 새 TextOutput 객체입니다.
createTextOutput(content)
지정된 콘텐츠를 게재할 수 있는 새 TextOutput
객체를 만듭니다.
function doGet() {
const output = ContentService.createTextOutput('Hello world!');
return output;
}
매개변수
이름 | 유형 | 설명 |
content | String | 콘텐츠를 게재합니다. |
리턴
TextOutput
: 새 TextOutput 객체입니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 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."]]