องค์ประกอบที่แสดงภูมิภาคที่ไม่รู้จักหรือไม่ได้รับผลกระทบจากสคริปต์ เช่น หมายเลขหน้า
เมธอด
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
---|---|---|
copy() | UnsupportedElement | แสดงผลสําเนาเดี่ยวที่แยกองค์ประกอบปัจจุบัน |
getAttributes() | Object | ดึงแอตทริบิวต์ของ' |
getNextSibling() | Element | เรียกองค์ประกอบข้างเคียงขององค์ประกอบถัดไป |
getParent() | ContainerElement | เรียกองค์ประกอบหลักขององค์ประกอบ |
getPreviousSibling() | Element | เรียกองค์ประกอบระดับก่อนหน้าขององค์ประกอบ' |
getType() | ElementType | เรียกดูองค์ประกอบ'ElementType |
isAtDocumentEnd() | Boolean | กําหนดว่าองค์ประกอบอยู่ท้าย Document หรือไม่ |
merge() | UnsupportedElement | ผสานองค์ประกอบกับองค์ประกอบข้างเคียงประเภทเดียวกัน |
removeFromParent() | UnsupportedElement | นําองค์ประกอบออกจากระดับบนสุด |
setAttributes(attributes) | UnsupportedElement | ตั้งค่าแอตทริบิวต์ขององค์ประกอบ |
เอกสารประกอบโดยละเอียด
copy()
แสดงผลสําเนาเดี่ยวที่แยกองค์ประกอบปัจจุบัน
ระบบจะคัดลอกองค์ประกอบย่อยที่แสดงในองค์ประกอบด้วย องค์ประกอบใหม่ไม่มีองค์ประกอบหลัก
ไปกลับ
UnsupportedElement
— สําเนาใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องได้รับสิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 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
getNextSibling()
เรียกองค์ประกอบข้างเคียงขององค์ประกอบถัดไป
พี่น้องถัดไปมีระดับบนสุดเดียวกันและเป็นไปตามองค์ประกอบปัจจุบัน
ไปกลับ
Element
— องค์ประกอบพี่น้องถัดไป
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องได้รับสิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 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
getPreviousSibling()
เรียกองค์ประกอบระดับก่อนหน้าขององค์ประกอบ'
พี่น้องก่อนหน้านี้มีออบเจ็กต์หลักเดียวกันและอยู่ก่อนองค์ประกอบปัจจุบัน
ไปกลับ
Element
— องค์ประกอบข้างเคียงก่อนหน้า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องได้รับสิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 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
isAtDocumentEnd()
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();
ไปกลับ
UnsupportedElement
— องค์ประกอบที่ผสาน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องได้รับสิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 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(); }
ไปกลับ
UnsupportedElement
— องค์ประกอบที่นําออก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องได้รับสิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 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);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
attributes | Object | แอตทริบิวต์'s |
ไปกลับ
UnsupportedElement
— องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องได้รับสิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents