องค์ประกอบที่แสดงตัวแบ่งหน้า PageBreak สามารถอยู่ใน ListItem หรือ Paragraph ได้ เว้นแต่ว่า ListItem หรือ Paragraph จะอยู่ใน
Table, HeaderSection, FooterSection, หรือ FootnoteSection PageBreak ไม่สามารถมีองค์ประกอบอื่นอยู่ภายในได้ ดูข้อมูลเพิ่มเติมเกี่ยวกับโครงสร้างเอกสารได้ที่
ดู คำแนะนำเกี่ยวกับการขยาย Google
เอกสาร
เมธอด
| เมธอด | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
|---|---|---|
copy() | Page | แสดงผลสำเนาแบบแยกออกมาและสำเนาแบบละเอียดขององค์ประกอบปัจจุบัน |
get | Object | ดึงข้อมูลแอตทริบิวต์ขององค์ประกอบ |
get | Element|null | ดึงข้อมูลองค์ประกอบพี่น้องคนถัดไปขององค์ประกอบ |
get | Container | ดึงข้อมูลองค์ประกอบหลักขององค์ประกอบ |
get | Element|null | ดึงข้อมูลองค์ประกอบพี่น้องคนก่อนหน้าขององค์ประกอบ |
get | Element | ดึงข้อมูล Element ขององค์ประกอบ |
is | Boolean | ระบุว่าองค์ประกอบอยู่ที่ส่วนท้ายของ Document หรือไม่ |
remove | Page | นำองค์ประกอบออกจากองค์ประกอบหลัก |
set | Page | ตั้งค่าแอตทริบิวต์ขององค์ประกอบ |
เอกสารโดยละเอียด
copy()
แสดงผลสำเนาแบบแยกออกมาและสำเนาแบบละเอียดขององค์ประกอบปัจจุบัน
ระบบจะคัดลอกองค์ประกอบย่อยที่มีอยู่ในองค์ประกอบด้วย องค์ประกอบใหม่จะไม่มีองค์ประกอบหลัก
รีเทิร์น
PageBreak \- สำเนาใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มี ขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getAttributes()
ดึงข้อมูลแอตทริบิวต์ขององค์ประกอบ
ผลลัพธ์จะเป็นออบเจ็กต์ที่มีพร็อพเพอร์ตี้สำหรับแอตทริบิวต์ขององค์ประกอบที่ถูกต้องแต่ละรายการ โดยชื่อพร็อพเพอร์ตี้แต่ละรายการจะสอดคล้องกับรายการในการแจงนับ DocumentApp.Attribute
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Append a styled paragraph. const par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true); // Retrieve the paragraph's attributes. const atts = par.getAttributes(); // Log the paragraph attributes. for (const 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|null \- องค์ประกอบพี่น้องคนถัดไป
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มี ขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getParent()
ดึงข้อมูลองค์ประกอบหลักขององค์ประกอบ
องค์ประกอบหลักมีองค์ประกอบปัจจุบัน
รีเทิร์น
ContainerElement|null \- องค์ประกอบหลัก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มี ขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getPreviousSibling()
ดึงข้อมูลองค์ประกอบพี่น้องคนก่อนหน้าขององค์ประกอบ
องค์ประกอบระดับเดียวกันก่อนหน้ามีองค์ประกอบหลักเดียวกันและอยู่ก่อนองค์ประกอบปัจจุบัน
รีเทิร์น
Element|null \- องค์ประกอบพี่น้องคนก่อนหน้า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มี ขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
getType()
ดึงข้อมูล ElementType ขององค์ประกอบ
ใช้ getType() เพื่อกำหนดประเภทที่แน่นอนขององค์ประกอบที่ระบุ
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Obtain the first element in the active tab's body. const 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()
removeFromParent()
นำองค์ประกอบออกจากองค์ประกอบหลัก
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Remove all images in the active tab's body. const imgs = body.getImages(); for (let i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
รีเทิร์น
PageBreak|null \- องค์ประกอบที่นำออก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มี ขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents
setAttributes(attributes)
ตั้งค่าแอตทริบิวต์ขององค์ประกอบ
พารามิเตอร์แอตทริบิวต์ที่ระบุต้องเป็นออบเจ็กต์ที่ชื่อพร็อพเพอร์ตี้แต่ละรายการเป็นรายการในการแจงนับ DocumentApp.Attribute และค่าพร็อพเพอร์ตี้แต่ละรายการเป็นค่าใหม่ที่จะนำไปใช้
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Define a custom paragraph style. const 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. const par = body.appendParagraph('A paragraph with custom style.'); // Apply the custom style. par.setAttributes(style);
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
attributes | Object | แอตทริบิวต์ขององค์ประกอบ |
รีเทิร์น
PageBreak \- องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มี ขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต
-
https://www.googleapis.com/auth/documents.currentonly -
https://www.googleapis.com/auth/documents