องค์ประกอบที่แสดงย่อหน้า Paragraph
อาจมีองค์ประกอบ Equation
, Footnote
, HorizontalRule
, InlineDrawing
, InlineImage
, PageBreak
และ Text
สําหรับข้อมูลเพิ่มเติมเกี่ยวกับโครงสร้างเอกสาร โปรดดูคู่มือการขยาย Google เอกสาร
Paragraphs
ต้องไม่มีอักขระขึ้นบรรทัดใหม่ อักขระบรรทัดใหม่ ("\n") จะถูกแปลงเป็นอักขระขึ้นบรรทัดใหม่ ("\r")
var body = DocumentApp.getActiveDocument().getBody(); // Append a document header paragraph. var header = body.appendParagraph("A Document"); header.setHeading(DocumentApp.ParagraphHeading.HEADING1); // Append a section header paragraph. var section = body.appendParagraph("Section 1"); section.setHeading(DocumentApp.ParagraphHeading.HEADING2); // Append a regular paragraph. body.appendParagraph("This is a typical paragraph.");
วิธีการ
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
---|---|---|
addPositionedImage(image) | PositionedImage | สร้างและแทรก PositionedImage ใหม่จาก Blob ของรูปภาพที่ระบุ |
appendHorizontalRule() | HorizontalRule | สร้างและเพิ่ม HorizontalRule ใหม่ |
appendInlineImage(image) | InlineImage | สร้างและเพิ่ม InlineImage ใหม่จาก Blob ของรูปภาพที่ระบุ |
appendInlineImage(image) | InlineImage | เพิ่ม InlineImage ที่ระบุ |
appendPageBreak() | PageBreak | สร้างและเพิ่ม PageBreak ใหม่ |
appendPageBreak(pageBreak) | PageBreak | เพิ่ม PageBreak ที่ระบุ |
appendText(text) | Text | สร้างและเพิ่มองค์ประกอบ Text ใหม่ด้วยเนื้อหาที่ระบุ |
appendText(text) | Text | เพิ่มองค์ประกอบ Text ที่ระบุ |
clear() | Paragraph | ล้างเนื้อหาขององค์ประกอบ |
copy() | Paragraph | แสดงผลสําเนาเดี่ยวที่แยกองค์ประกอบปัจจุบัน |
editAsText() | Text | รับองค์ประกอบปัจจุบัน Text เพื่อแก้ไข |
findElement(elementType) | RangeElement | ค้นหาเนื้อหาขององค์ประกอบจากองค์ประกอบสืบทอดของประเภทที่ระบุ |
findElement(elementType, from) | RangeElement | ค้นหาเนื้อหาขององค์ประกอบสืบทอดของประเภทที่ระบุ โดยเริ่มจาก RangeElement ที่ระบุ |
findText(searchPattern) | RangeElement | ค้นหาเนื้อหาของรูปแบบข้อความที่ระบุโดยใช้นิพจน์ทั่วไป |
findText(searchPattern, from) | RangeElement | ค้นหาเนื้อหาขององค์ประกอบสําหรับรูปแบบข้อความที่ระบุ เริ่มจากผลการค้นหาที่กําหนด |
getAlignment() | HorizontalAlignment | เรียกข้อมูล HorizontalAlignment |
getAttributes() | Object | เรียกข้อมูลแอตทริบิวต์ขององค์ประกอบ |
getChild(childIndex) | Element | เรียกข้อมูลองค์ประกอบย่อยที่ดัชนีย่อยที่ระบุ |
getChildIndex(child) | Integer | เรียกข้อมูลดัชนีย่อยสําหรับองค์ประกอบย่อยที่ระบุ |
getHeading() | ParagraphHeading | เรียกข้อมูล ParagraphHeading |
getIndentEnd() | Number | เรียกข้อมูลการเยื้องท้ายเป็นจุด |
getIndentFirstLine() | Number | เรียกข้อมูลการเยื้องบรรทัดแรกในจุด |
getIndentStart() | Number | เรียกข้อมูลการเยื้องเริ่มต้น |
getLineSpacing() | Number | เรียกข้อมูลระยะห่างระหว่างบรรทัดเป็นจุด |
getLinkUrl() | String | เรียก URL ของลิงก์ |
getNextSibling() | Element | เรียกองค์ประกอบข้างเคียงขององค์ประกอบถัดไป |
getNumChildren() | Integer | เรียกข้อมูลจํานวนบุตรหลาน |
getParent() | ContainerElement | เรียกองค์ประกอบระดับบนสุดขององค์ประกอบ |
getPositionedImage(id) | PositionedImage | รับ PositionedImage ตามรหัสของรูปภาพ |
getPositionedImages() | PositionedImage[] | รับออบเจ็กต์ PositionedImage ทั้งหมดซึ่งตรึงอยู่กับย่อหน้า |
getPreviousSibling() | Element | เรียกองค์ประกอบระดับข้างก่อนหน้าขององค์ประกอบ |
getSpacingAfter() | Number | เรียกระยะห่างหลังองค์ประกอบเป็นจุด |
getSpacingBefore() | Number | เรียกช่องว่างก่อนองค์ประกอบ เป็นจุด |
getText() | String | เรียกเนื้อหาขององค์ประกอบเป็นสตริงข้อความ |
getTextAlignment() | TextAlignment | รับการปรับแนวข้อความ |
getType() | ElementType | เรียกข้อมูล ElementType ขององค์ประกอบ |
insertHorizontalRule(childIndex) | HorizontalRule | สร้างและแทรก HorizontalRule ที่ดัชนีที่ระบุ |
insertInlineImage(childIndex, image) | InlineImage | สร้างและแทรก InlineImage ใหม่จาก Blob รูปภาพที่ระบุที่ดัชนีที่ระบุ |
insertInlineImage(childIndex, image) | InlineImage | แทรก InlineImage ที่ระบุที่ดัชนีที่ระบุ |
insertPageBreak(childIndex) | PageBreak | สร้างและแทรก PageBreak ใหม่ที่ดัชนีที่ระบุ |
insertPageBreak(childIndex, pageBreak) | PageBreak | แทรก PageBreak ที่ระบุที่ดัชนีที่ระบุ |
insertText(childIndex, text) | Text | สร้างและแทรกองค์ประกอบข้อความใหม่ที่ดัชนีที่ระบุ |
insertText(childIndex, text) | Text | แทรกองค์ประกอบ Text ที่ระบุที่ดัชนีที่ระบุ พร้อมด้วยเนื้อหาข้อความที่ระบุ |
isAtDocumentEnd() | Boolean | กําหนดว่าองค์ประกอบอยู่ท้าย Document หรือไม่ |
isLeftToRight() | Boolean | เรียกข้อมูลการตั้งค่าจากซ้ายไปขวา |
merge() | Paragraph | ผสานองค์ประกอบเข้ากับรายการข้างเคียงที่เป็นประเภทเดียวกัน |
removeChild(child) | Paragraph | นําองค์ประกอบย่อยที่ระบุออก |
removeFromParent() | Paragraph | นําองค์ประกอบออกจากองค์ประกอบหลัก |
removePositionedImage(id) | Boolean | นํา PositionedImage ออกจากรหัสของรูปภาพ |
replaceText(searchPattern, replacement) | Element | แทนที่รูปแบบข้อความที่ระบุทั้งหมดด้วยสตริงแทนที่ที่กําหนด โดยใช้นิพจน์ปกติ |
setAlignment(alignment) | Paragraph | ตั้งค่า HorizontalAlignment |
setAttributes(attributes) | Paragraph | ตั้งค่าแอตทริบิวต์ขององค์ประกอบ |
setHeading(heading) | Paragraph | ตั้งค่า ParagraphHeading |
setIndentEnd(indentEnd) | Paragraph | ตั้งค่าการเยื้องท้ายเป็นจุด |
setIndentFirstLine(indentFirstLine) | Paragraph | ตั้งค่าการเยื้องบรรทัดแรกในจุด |
setIndentStart(indentStart) | Paragraph | ตั้งค่าการเยื้องเริ่มต้นเป็นจุด |
setLeftToRight(leftToRight) | Paragraph | ตั้งค่าซ้ายไปขวา |
setLineSpacing(multiplier) | Paragraph | กําหนดระยะห่างของบรรทัดเป็นปริมาณที่ระบุจํานวนบรรทัดที่จะใช้ในการเว้นวรรค |
setLinkUrl(url) | Paragraph | ตั้งค่า URL ของลิงก์ |
setSpacingAfter(spacingAfter) | Paragraph | กําหนดระยะห่างหลังองค์ประกอบเป็นจุด |
setSpacingBefore(spacingBefore) | Paragraph | กําหนดระยะห่างข้างหน้าองค์ประกอบเป็นจุด |
setText(text) | void | ตั้งค่าเนื้อหาของย่อหน้าเป็นข้อความ |
setTextAlignment(textAlignment) | Paragraph | ตั้งค่าการจัดข้อความ |
เอกสารโดยละเอียด
addPositionedImage(image)
สร้างและแทรก PositionedImage
ใหม่จาก Blob ของรูปภาพที่ระบุ
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Fetches the specified image URL. const image = UrlFetchApp.fetch('https://fonts.gstatic.com/s/i/productlogos/apps_script/v10/web-24dp/logo_apps_script_color_1x_web_24dp.png'); // Adds the image to the document, anchored to the first paragraph. paragraph.addPositionedImage(image);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
image | BlobSource | ข้อมูลรูปภาพ |
ขากลับ
PositionedImage
— รูปภาพที่กําหนดตําแหน่งใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendHorizontalRule()
สร้างและเพิ่ม HorizontalRule
ใหม่
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a horizontal line under the first paragraph. paragraph.appendHorizontalRule();
ขากลับ
HorizontalRule
— กฎแนวนอนใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendInlineImage(image)
สร้างและเพิ่ม InlineImage
ใหม่จาก Blob ของรูปภาพที่ระบุ
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Fetches the image from the specified image URL. const image = UrlFetchApp .fetch('https://fonts.gstatic.com/s/i/productlogos/apps_script/v10/web-96dp/logo_apps_script_color_1x_web_96dp.png'); // Adds the image to the first paragraph. paragraph.appendInlineImage(image);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
image | BlobSource | ข้อมูลรูปภาพ |
ขากลับ
InlineImage
— รูปภาพที่ต่อท้าย
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendInlineImage(image)
เพิ่ม InlineImage
ที่ระบุ
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Makes a copy of the first image in the body. const image = body.getImages()[0].copy();; // Adds the image to the first paragraph. paragraph.appendInlineImage(image);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
image | InlineImage | ข้อมูลรูปภาพ |
ขากลับ
InlineImage
— รูปภาพที่ต่อท้าย
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendPageBreak()
สร้างและเพิ่ม PageBreak
ใหม่
หมายเหตุ: PageBreaks
ต้องไม่อยู่ใน TableCells
หากองค์ประกอบปัจจุบันอยู่ในเซลล์ของตาราง ข้อยกเว้นก็จะหายไป
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a page break after the first paragraph. paragraph.appendPageBreak();
ขากลับ
PageBreak
— องค์ประกอบใหม่สําหรับตัวแบ่งหน้า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendPageBreak(pageBreak)
เพิ่ม PageBreak
ที่ระบุ
หมายเหตุ: ไม่สามารถอยู่ใน PageBreaks
ภายใน TableCells
หากองค์ประกอบปัจจุบันอยู่ในเซลล์ของตาราง สคริปต์จะแสดงข้อยกเว้น
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a page break after the first paragraph. const pageBreak = paragraph.appendPageBreak(); // Makes a copy of the page break. const newPageBreak = pageBreak.copy(); // Adds the copied page break to the paragraph. paragraph.appendPageBreak(newPageBreak);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
pageBreak | PageBreak | ตัวแบ่งหน้าที่จะต่อท้าย |
ขากลับ
PageBreak
— องค์ประกอบตัวแบ่งหน้าต่อท้าย
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendText(text)
สร้างและเพิ่มองค์ประกอบ Text
ใหม่ด้วยเนื้อหาที่ระบุ
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Adds a string to the paragraph. paragraph.appendText('This is a new sentence.');
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
text | String | เนื้อหาข้อความ |
ขากลับ
Text
— องค์ประกอบข้อความใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
appendText(text)
เพิ่มองค์ประกอบ Text
ที่ระบุ
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the text from the first paragraph in the body. const paragraph1 = body.getParagraphs()[0]; const text = paragraph1.getText(); // Gets the third paragraph in the body. const paragraph3 = body.getParagraphs()[2]; // Adds the text from the first paragraph to the third paragraph. paragraph3.appendText(text);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
text | Text | องค์ประกอบข้อความที่จะต่อท้าย |
ขากลับ
Text
— องค์ประกอบข้อความต่อท้าย
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
clear()
copy()
แสดงผลสําเนาเดี่ยวที่แยกองค์ประกอบปัจจุบัน
ระบบจะคัดลอกองค์ประกอบย่อยที่อยู่ในองค์ประกอบนั้นด้วย องค์ประกอบใหม่ไม่มี ระดับบนสุด
ขากลับ
Paragraph
— สําเนาใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
editAsText()
รับองค์ประกอบปัจจุบัน Text
เพื่อแก้ไข
ใช้ editAsText
เพื่อบิดเบือนองค์ประกอบองค์ประกอบเป็นข้อความริชมีเดีย โหมด editAsText
จะละเว้นองค์ประกอบที่ไม่ใช่ข้อความ (เช่น InlineImage
และ HorizontalRule
)
องค์ประกอบย่อยที่อยู่ในช่วงข้อความที่ถูกลบจะถูกนําออกจากองค์ประกอบ
var body = DocumentApp.getActiveDocument().getBody(); // Insert two paragraphs separated by a paragraph containing an // horizontal rule. body.insertParagraph(0, "An editAsText sample."); body.insertHorizontalRule(0); body.insertParagraph(0, "An example."); // Delete " sample.\n\n An" removing the horizontal rule in the process. body.editAsText().deleteText(14, 25);
ขากลับ
Text
— เวอร์ชันข้อความขององค์ประกอบปัจจุบัน
findElement(elementType)
ค้นหาเนื้อหาขององค์ประกอบจากองค์ประกอบสืบทอดของประเภทที่ระบุ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
elementType | ElementType | ประเภทขององค์ประกอบที่จะค้นหา |
ขากลับ
RangeElement
— ผลการค้นหาที่ระบุตําแหน่งขององค์ประกอบการค้นหา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findElement(elementType, from)
ค้นหาเนื้อหาขององค์ประกอบสืบทอดของประเภทที่ระบุ โดยเริ่มจาก RangeElement
ที่ระบุ
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Define the search parameters. var searchType = DocumentApp.ElementType.PARAGRAPH; var searchHeading = DocumentApp.ParagraphHeading.HEADING1; var searchResult = null; // Search until the paragraph is found. while (searchResult = body.findElement(searchType, searchResult)) { var par = searchResult.getElement().asParagraph(); if (par.getHeading() == searchHeading) { // Found one, update and stop. par.setText('This is the first header.'); return; } }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
elementType | ElementType | ประเภทขององค์ประกอบที่จะค้นหา |
from | RangeElement | ผลการค้นหาที่จะค้นหา |
ขากลับ
RangeElement
— ผลการค้นหาที่ระบุตําแหน่งถัดไปขององค์ประกอบการค้นหา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern)
ค้นหาเนื้อหาของรูปแบบข้อความที่ระบุโดยใช้นิพจน์ทั่วไป
ชุดย่อยของคุณลักษณะนิพจน์ทั่วไปของ JavaScript ไม่ได้รับการสนับสนุนอย่างสมบูรณ์ เช่น แคปเจอร์กรุ๊ป และตัวแก้ไขโหมด
ระบบจะจับคู่รูปแบบนิพจน์ทั่วไปที่มีให้กับบล็อกข้อความแต่ละบล็อกที่มีอยู่ในองค์ประกอบปัจจุบัน
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
searchPattern | String | รูปแบบที่จะค้นหา |
ขากลับ
RangeElement
— ผลการค้นหาที่ระบุตําแหน่งของข้อความค้นหา หรือค่าว่างหากไม่มีรายการที่ตรงกัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
findText(searchPattern, from)
ค้นหาเนื้อหาขององค์ประกอบสําหรับรูปแบบข้อความที่ระบุ เริ่มจากผลการค้นหาที่กําหนด
ชุดย่อยของคุณลักษณะนิพจน์ทั่วไปของ JavaScript ไม่ได้รับการสนับสนุนอย่างสมบูรณ์ เช่น แคปเจอร์กรุ๊ป และตัวแก้ไขโหมด
ระบบจะจับคู่รูปแบบนิพจน์ทั่วไปที่มีให้กับบล็อกข้อความแต่ละบล็อกที่มีอยู่ในองค์ประกอบปัจจุบัน
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
searchPattern | String | รูปแบบที่จะค้นหา |
from | RangeElement | ผลการค้นหาที่จะค้นหา |
ขากลับ
RangeElement
— ผลการค้นหาที่ระบุตําแหน่งถัดไปของข้อความค้นหา หรือไม่มีข้อมูลหากไม่มีรายการที่ตรงกัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAlignment()
เรียกข้อมูล HorizontalAlignment
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first paragraph from the body. const paragraph = body.getParagraphs()[0]; // Sets the horizontal alignment to left for the first paragraph. paragraph.setAlignment(DocumentApp.HorizontalAlignment.LEFT); // Gets the horizontal alignment of the first paragraph and logs it to the console. console.log(paragraph.getAlignment().toString());
ขากลับ
HorizontalAlignment
— การปรับแนว
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getAttributes()
เรียกข้อมูลแอตทริบิวต์ขององค์ประกอบ
ผลลัพธ์จะเป็นออบเจ็กต์ที่มีพร็อพเพอร์ตี้สําหรับแอตทริบิวต์เอลิเมนต์ที่ถูกต้องแต่ละรายการ โดยที่ชื่อพร็อพเพอร์ตี้แต่ละรายการตรงกับรายการในการแจงนับ DocumentApp.Attribute
var body = DocumentApp.getActiveDocument().getBody(); // Append a styled paragraph. var par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true); // Retrieve the paragraph's attributes. var atts = par.getAttributes(); // Log the paragraph attributes. for (var att in atts) { Logger.log(att + ":" + atts[att]); }
ขากลับ
Object
— แอตทริบิวต์ขององค์ประกอบ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getChild(childIndex)
เรียกข้อมูลองค์ประกอบย่อยที่ดัชนีย่อยที่ระบุ
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Obtain the first element in the document. var firstChild = body.getChild(0); // If it's a paragraph, set its contents. if (firstChild.getType() == DocumentApp.ElementType.PARAGRAPH) { firstChild.asParagraph().setText("This is the first paragraph."); }
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
childIndex | Integer | ดัชนีขององค์ประกอบย่อยเพื่อดึง |
ขากลับ
Element
— องค์ประกอบย่อยที่ดัชนีที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getChildIndex(child)
เรียกข้อมูลดัชนีย่อยสําหรับองค์ประกอบย่อยที่ระบุ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
child | Element | องค์ประกอบย่อยที่จะดึงข้อมูลดัชนี |
ขากลับ
Integer
— ดัชนีย่อย
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getHeading()
เรียกข้อมูล ParagraphHeading
// Opens the Docs file by its ID. If you created your script from within // a Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Adds a paragraph to the body. const paragraph = body.appendParagraph('Title heading'); // Sets the paragraph heading style to 'Title.' paragraph.setHeading(DocumentApp.ParagraphHeading.TITLE); // Gets the heading style and logs it to the console. console.log(paragraph.getHeading().toString());
ขากลับ
ParagraphHeading
— ส่วนหัว
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getIndentEnd()
เรียกข้อมูลการเยื้องท้ายเป็นจุด
ขากลับ
Number
— การเยื้องท้ายเป็นจุด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getIndentFirstLine()
เรียกข้อมูลการเยื้องบรรทัดแรกในจุด
ขากลับ
Number
— การเยื้องบรรทัดแรกเป็นจุด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getIndentStart()
เรียกข้อมูลการเยื้องเริ่มต้น
ขากลับ
Number
— การเยื้องเริ่มต้น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLineSpacing()
เรียกข้อมูลระยะห่างระหว่างบรรทัดเป็นจุด
ขากลับ
Number
— ระยะห่างระหว่างบรรทัดเป็นจุด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getLinkUrl()
เรียก URL ของลิงก์
ขากลับ
String
— URL ของลิงก์ หรือ Null หากองค์ประกอบมีหลายค่าสําหรับแอตทริบิวต์นี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNextSibling()
เรียกองค์ประกอบข้างเคียงขององค์ประกอบถัดไป
พี่น้องถัดไปมีระดับบนสุดและไปตามองค์ประกอบปัจจุบัน
ขากลับ
Element
— องค์ประกอบข้างเคียงถัดไป
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getNumChildren()
เรียกข้อมูลจํานวนบุตรหลาน
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Log the number of elements in the document. Logger.log("There are " + body.getNumChildren() + " elements in the document body.");
ขากลับ
Integer
— จํานวนเด็ก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getParent()
เรียกองค์ประกอบระดับบนสุดขององค์ประกอบ
องค์ประกอบระดับบนจะมีองค์ประกอบปัจจุบัน
ขากลับ
ContainerElement
— องค์ประกอบระดับบน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPositionedImage(id)
รับ PositionedImage
ตามรหัสของรูปภาพ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
id | String | รหัสรูปภาพ |
ขากลับ
PositionedImage
— รูปภาพที่กําหนดตําแหน่ง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPositionedImages()
รับออบเจ็กต์ PositionedImage
ทั้งหมดซึ่งตรึงอยู่กับย่อหน้า
ขากลับ
PositionedImage[]
— รายการรูปภาพที่วางตําแหน่ง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPreviousSibling()
เรียกองค์ประกอบระดับข้างก่อนหน้าขององค์ประกอบ
พี่น้องก่อนหน้ามีระดับบนสุดเดียวกันอยู่ก่อนองค์ประกอบปัจจุบัน
ขากลับ
Element
— องค์ประกอบข้างเคียงก่อนหน้า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getSpacingAfter()
เรียกระยะห่างหลังองค์ประกอบเป็นจุด
ขากลับ
Number
— ระยะห่างหลังองค์ประกอบ เป็นจุด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getSpacingBefore()
เรียกช่องว่างก่อนองค์ประกอบ เป็นจุด
ขากลับ
Number
— ระยะห่างก่อนองค์ประกอบ เป็นจุด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getText()
เรียกเนื้อหาขององค์ประกอบเป็นสตริงข้อความ
ขากลับ
String
— เนื้อหาขององค์ประกอบเป็นสตริงข้อความ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getTextAlignment()
รับการปรับแนวข้อความ ประเภทการจัดข้อความที่ใช้ได้คือ DocumentApp.TextAlignment.NORMAL
, DocumentApp.TextAlignment.SUBSCRIPT
และ DocumentApp.TextAlignment.SUPERSCRIPT
ขากลับ
TextAlignment
— ประเภทการจัดข้อความ หรือ null
หากข้อความมีการจัดแนวข้อความหลายประเภท หรือหากไม่เคยตั้งค่าการปรับแนวข้อความ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getType()
เรียกข้อมูล ElementType
ขององค์ประกอบ
ใช้ getType()
เพื่อระบุประเภทขององค์ประกอบที่กําหนด
var body = DocumentApp.getActiveDocument().getBody(); // Obtain the first element in the document body. var firstChild = body.getChild(0); // Use getType() to determine the element's type. if (firstChild.getType() == DocumentApp.ElementType.PARAGRAPH) { Logger.log('The first element is a paragraph.'); } else { Logger.log('The first element is not a paragraph.'); }
ขากลับ
ElementType
— ประเภทองค์ประกอบ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertHorizontalRule(childIndex)
สร้างและแทรก HorizontalRule
ที่ดัชนีที่ระบุ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
childIndex | Integer | ดัชนีที่จะแทรกองค์ประกอบ |
ขากลับ
HorizontalRule
— องค์ประกอบกฎแนวนอนใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertInlineImage(childIndex, image)
สร้างและแทรก InlineImage
ใหม่จาก Blob รูปภาพที่ระบุที่ดัชนีที่ระบุ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
childIndex | Integer | ดัชนีที่จะแทรกองค์ประกอบ |
image | BlobSource | ข้อมูลรูปภาพ |
ขากลับ
InlineImage
— องค์ประกอบรูปภาพแบบแทรกในบรรทัดที่แทรกอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertInlineImage(childIndex, image)
แทรก InlineImage
ที่ระบุที่ดัชนีที่ระบุ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
childIndex | Integer | ดัชนีที่จะแทรกองค์ประกอบ |
image | InlineImage | ข้อมูลรูปภาพ |
ขากลับ
InlineImage
— องค์ประกอบรูปภาพแบบแทรกในบรรทัดที่แทรกอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertPageBreak(childIndex)
สร้างและแทรก PageBreak
ใหม่ที่ดัชนีที่ระบุ
หมายเหตุ: PageBreaks
ต้องไม่อยู่ใน TableCells
หากองค์ประกอบปัจจุบันอยู่ในเซลล์ของตาราง ข้อยกเว้นก็จะหายไป
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
childIndex | Integer | ดัชนีที่จะแทรกองค์ประกอบ |
ขากลับ
PageBreak
— องค์ประกอบใหม่สําหรับตัวแบ่งหน้า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertPageBreak(childIndex, pageBreak)
แทรก PageBreak
ที่ระบุที่ดัชนีที่ระบุ
หมายเหตุ: PageBreaks
ต้องไม่อยู่ใน TableCells
หากองค์ประกอบปัจจุบันอยู่ในเซลล์ของตาราง ข้อยกเว้นก็จะหายไป
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
childIndex | Integer | ดัชนีที่จะแทรกองค์ประกอบ |
pageBreak | PageBreak | แทรก [[age break] เพื่อแทรก |
ขากลับ
PageBreak
— องค์ประกอบตัวแบ่งหน้าที่แทรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertText(childIndex, text)
สร้างและแทรกองค์ประกอบข้อความใหม่ที่ดัชนีที่ระบุ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
childIndex | Integer | ดัชนีที่จะแทรกองค์ประกอบ |
text | String | เนื้อหาข้อความ |
ขากลับ
Text
— องค์ประกอบข้อความใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
insertText(childIndex, text)
แทรกองค์ประกอบ Text
ที่ระบุที่ดัชนีที่ระบุ พร้อมด้วยเนื้อหาข้อความที่ระบุ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
childIndex | Integer | ดัชนีที่จะแทรกองค์ประกอบ |
text | Text | องค์ประกอบข้อความที่จะแทรก |
ขากลับ
Text
— องค์ประกอบข้อความที่แทรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
isAtDocumentEnd()
isLeftToRight()
เรียกข้อมูลการตั้งค่าจากซ้ายไปขวา
ขากลับ
Boolean
— การตั้งค่าจากซ้ายไปขวา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
merge()
ผสานองค์ประกอบเข้ากับรายการข้างเคียงที่เป็นประเภทเดียวกัน
ผสานได้เฉพาะองค์ประกอบของ ElementType
เดียวกันเท่านั้น องค์ประกอบย่อยที่อยู่ในองค์ประกอบปัจจุบันจะย้ายไปยังองค์ประกอบข้างเคียงก่อนหน้า
องค์ประกอบปัจจุบันจะถูกนําออกจากเอกสาร
var body = DocumentApp.getActiveDocument().getBody(); // Example 1: Merge paragraphs // Append two paragraphs to the document. var par1 = body.appendParagraph('Paragraph 1.'); var par2 = body.appendParagraph('Paragraph 2.'); // Merge the newly added paragraphs into a single paragraph. par2.merge(); // Example 2: Merge table cells // Create a two-dimensional array containing the table's cell contents. var cells = [ ['Row 1, Cell 1', 'Row 1, Cell 2'], ['Row 2, Cell 1', 'Row 2, Cell 2'] ]; // Build a table from the array. var table = body.appendTable(cells); // Get the first row in the table. var row = table.getRow(0); // Get the two cells in this row. var cell1 = row.getCell(0); var cell2 = row.getCell(1); // Merge the current cell into its preceding sibling element. var merged = cell2.merge();
ขากลับ
Paragraph
— องค์ประกอบที่ผสานกัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeChild(child)
นําองค์ประกอบย่อยที่ระบุออก
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
child | Element | องค์ประกอบย่อยที่จะลบ |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removeFromParent()
นําองค์ประกอบออกจากองค์ประกอบหลัก
var body = DocumentApp.getActiveDocument().getBody(); // Remove all images in the document body. var imgs = body.getImages(); for (var i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
ขากลับ
Paragraph
— องค์ประกอบที่นําออก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
removePositionedImage(id)
นํา PositionedImage
ออกจากรหัสของรูปภาพ
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
id | String | รหัสรูปภาพ |
ขากลับ
Boolean
— ระบุว่ารูปภาพที่ระบุถูกนําออกหรือไม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
replaceText(searchPattern, replacement)
แทนที่รูปแบบข้อความที่ระบุทั้งหมดด้วยสตริงแทนที่ที่กําหนด โดยใช้นิพจน์ปกติ
ระบบจะส่งรูปแบบการค้นหาเป็นสตริง ไม่ใช่ออบเจ็กต์ของนิพจน์ทั่วไป JavaScript ด้วยเหตุนี้ คุณจึงต้องใช้ Escape กับแบ็กสแลชในรูปแบบนี้
เมธอดนี้ใช้ไลบรารีการแสดงผลปกติ RE2 ของ Google ซึ่งจํากัดไวยากรณ์ที่สนับสนุน
ระบบจะจับคู่รูปแบบนิพจน์ทั่วไปที่มีให้กับบล็อกข้อความแต่ละบล็อกที่มีอยู่ในองค์ประกอบปัจจุบัน
var body = DocumentApp.getActiveDocument().getBody(); // Clear the text surrounding "Apps Script", with or without text. body.replaceText("^.*Apps ?Script.*$", "Apps Script");
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
searchPattern | String | รูปแบบนิพจน์ทั่วไปที่จะค้นหา |
replacement | String | ข้อความที่จะใช้แทนที่ |
ขากลับ
Element
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAlignment(alignment)
ตั้งค่า HorizontalAlignment
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
alignment | HorizontalAlignment | การจัดข้อความแนวนอน |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setAttributes(attributes)
ตั้งค่าแอตทริบิวต์ขององค์ประกอบ
พารามิเตอร์แอตทริบิวต์ที่ระบุต้องเป็นออบเจ็กต์ที่มีการตั้งชื่อพร็อพเพอร์ตี้แต่ละรายการเป็นรายการที่แจกแจง DocumentApp.Attribute
และค่าพร็อพเพอร์ตี้แต่ละรายการคือค่าใหม่ที่จะนําไปใช้
var body = DocumentApp.getActiveDocument().getBody(); // Define a custom paragraph style. var style = {}; style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT; style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri'; style[DocumentApp.Attribute.FONT_SIZE] = 18; style[DocumentApp.Attribute.BOLD] = true; // Append a plain paragraph. var par = body.appendParagraph('A paragraph with custom style.'); // Apply the custom style. par.setAttributes(style);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
attributes | Object | แอตทริบิวต์ขององค์ประกอบ |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setHeading(heading)
ตั้งค่า ParagraphHeading
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
heading | ParagraphHeading | หัวเรื่อง |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setIndentEnd(indentEnd)
ตั้งค่าการเยื้องท้ายเป็นจุด
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
indentEnd | Number | การเยื้องท้ายบรรทัด |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setIndentFirstLine(indentFirstLine)
ตั้งค่าการเยื้องบรรทัดแรกในจุด
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
indentFirstLine | Number | การเยื้องบรรทัดแรก |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setIndentStart(indentStart)
ตั้งค่าการเยื้องเริ่มต้นเป็นจุด
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
indentStart | Number | การเยื้องเริ่มต้น |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLeftToRight(leftToRight)
ตั้งค่าซ้ายไปขวา
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
leftToRight | Boolean | การตั้งค่าจากซ้ายไปขวา |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLineSpacing(multiplier)
กําหนดระยะห่างของบรรทัดเป็นปริมาณที่ระบุจํานวนบรรทัดที่จะใช้ในการเว้นวรรค
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
multiplier | Number | จํานวนบรรทัด |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setLinkUrl(url)
setSpacingAfter(spacingAfter)
กําหนดระยะห่างหลังองค์ประกอบเป็นจุด
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
spacingAfter | Number | ระยะห่างหลังองค์ประกอบ |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setSpacingBefore(spacingBefore)
กําหนดระยะห่างข้างหน้าองค์ประกอบเป็นจุด
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
spacingBefore | Number | ระยะห่างก่อนองค์ประกอบ |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setText(text)
ตั้งค่าเนื้อหาของย่อหน้าเป็นข้อความ
หมายเหตุ: ระบบจะล้างเนื้อหาที่มีอยู่
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
text | String | เนื้อหาข้อความใหม่ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
setTextAlignment(textAlignment)
ตั้งค่าการจัดข้อความ ประเภทการจัดข้อความที่ใช้ได้คือ DocumentApp.TextAlignment.NORMAL
, DocumentApp.TextAlignment.SUBSCRIPT
และ DocumentApp.TextAlignment.SUPERSCRIPT
// Make the entire first paragraph be superscript. var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);
พารามิเตอร์
ชื่อ | Type | คำอธิบาย |
---|---|---|
textAlignment | TextAlignment | ประเภทของการปรับแนวข้อความที่จะใช้ |
ขากลับ
Paragraph
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents