Class ContentService
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
บริการเนื้อหา
บริการแสดงผลเนื้อหาข้อความจากสคริปต์
คุณสามารถแสดงข้อความในรูปแบบต่างๆ ได้ เช่น เผยแพร่สคริปต์นี้เป็นเว็บแอป
function doGet() {
return ContentService.createTextOutput('Hello World');
}
เมื่อไปที่ URL ของเว็บแอป คุณจะเห็น "Hello World" ในเบราว์เซอร์ สคริปต์ไม่สามารถแสดงเนื้อหาไปยังเบราว์เซอร์ได้โดยตรงเนื่องจากข้อควรพิจารณาด้านความปลอดภัย แต่ต้องแสดงเนื้อหาจาก URL อื่น ด้วยเหตุนี้ URL ในเบราว์เซอร์สำหรับเอาต์พุตที่สร้างผ่านเว็บแอปนี้จะแตกต่างจาก URL ของสคริปต์เดิม
พร็อพเพอร์ตี้
พร็อพเพอร์ตี้ | ประเภท | คำอธิบาย |
MimeType | MimeType | |
เอกสารประกอบโดยละเอียด
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 ใหม่
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ 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."]]