Class UnsupportedElement

UnsupportedElement

องค์ประกอบที่แสดงถึงภูมิภาคที่ไม่รู้จักหรือสคริปต์ไม่สามารถส่งผลกระทบได้ เช่น หมายเลขหน้า

เมธอด

เมธอดประเภทการแสดงผลรายละเอียดแบบย่อ
copy()UnsupportedElementแสดงผลสำเนาแบบดีพที่แยกออกมาขององค์ประกอบปัจจุบัน
getAttributes()Objectดึงแอตทริบิวต์ขององค์ประกอบ
getNextSibling()Element|nullดึงองค์ประกอบพี่น้องคนถัดไปขององค์ประกอบ
getParent()ContainerElement|nullดึงองค์ประกอบหลักขององค์ประกอบ
getPreviousSibling()Element|nullดึงองค์ประกอบพี่น้องคนก่อนหน้าขององค์ประกอบ
getType()ElementTypeดึง ElementType ขององค์ประกอบ
isAtDocumentEnd()Booleanระบุว่าองค์ประกอบอยู่ที่ส่วนท้ายของ Document หรือไม่
merge()UnsupportedElement|nullผสานองค์ประกอบกับองค์ประกอบพี่น้องคนก่อนหน้าที่มีประเภทเดียวกัน
removeFromParent()UnsupportedElement|nullนำองค์ประกอบออกจากองค์ประกอบหลัก
setAttributes(attributes)UnsupportedElementตั้งค่าแอตทริบิวต์ขององค์ประกอบ

เอกสารประกอบโดยละเอียด

copy()

แสดงผลสำเนาแบบดีพที่แยกออกมาขององค์ประกอบปัจจุบัน

ระบบจะคัดลอกองค์ประกอบย่อยที่อยู่ในองค์ประกอบด้วย องค์ประกอบใหม่จะไม่มีองค์ประกอบหลัก

รีเทิร์น

UnsupportedElement \- สำเนาใหม่

การให้สิทธิ์

สคริปต์ที่ใช้เมธอดนี้ต้องมีการให้สิทธิ์ที่มี ขอบเขตต่อไปนี้อย่างน้อย 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()

ระบุว่าองค์ประกอบอยู่ที่ส่วนท้ายของ Document หรือไม่

รีเทิร์น

Boolean \- องค์ประกอบอยู่ที่ส่วนท้ายของแท็บหรือไม่

การให้สิทธิ์

สคริปต์ที่ใช้เมธอดนี้ต้องมีการให้สิทธิ์ที่มี ขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

merge()

ผสานองค์ประกอบกับองค์ประกอบพี่น้องคนก่อนหน้าที่มีประเภทเดียวกัน

ผสานได้เฉพาะองค์ประกอบที่มี ElementType เดียวกัน ระบบจะย้ายองค์ประกอบย่อยที่อยู่ในองค์ประกอบปัจจุบันไปยังองค์ประกอบพี่น้องคนก่อนหน้า

ระบบจะนำองค์ประกอบปัจจุบันออกจากเอกสาร

const doc = DocumentApp.getActiveDocument();
const documentTab = doc.getActiveTab().asDocumentTab();
const body = documentTab.getBody();

// Example 1: Merge paragraphs
// Append two paragraphs to the document's active tab.
const par1 = body.appendParagraph('Paragraph 1.');
const 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.
const cells = [
  ['Row 1, Cell 1', 'Row 1, Cell 2'],
  ['Row 2, Cell 1', 'Row 2, Cell 2'],
];
// Build a table from the array.
const table = body.appendTable(cells);
// Get the first row in the table.
const row = table.getRow(0);
// Get the two cells in this row.
const cell1 = row.getCell(0);
const cell2 = row.getCell(1);
// Merge the current cell into its preceding sibling element.
const merged = cell2.merge();

รีเทิร์น

UnsupportedElement|null \- องค์ประกอบที่ผสาน

การให้สิทธิ์

สคริปต์ที่ใช้เมธอดนี้ต้องมีการให้สิทธิ์ที่มี ขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

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();
}

รีเทิร์น

UnsupportedElement|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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
attributesObjectแอตทริบิวต์ขององค์ประกอบ

รีเทิร์น

UnsupportedElement \- องค์ประกอบปัจจุบัน

การให้สิทธิ์

สคริปต์ที่ใช้เมธอดนี้ต้องมีการให้สิทธิ์ที่มี ขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents