Class Paragraph

ย่อหน้า

องค์ประกอบที่แสดงย่อหน้า Paragraph อาจมีองค์ประกอบ Equation, Footnote, HorizontalRule, InlineDrawing, InlineImage, PageBreak และ Text ดูข้อมูลเพิ่มเติมเกี่ยวกับโครงสร้างเอกสารได้ที่คู่มือการขยาย Google เอกสาร

Paragraphs ต้องไม่มีอักขระบรรทัดใหม่ ระบบจะแปลงอักขระบรรทัดใหม่ ("\n") เป็นอักขระขึ้นบรรทัดใหม่ ("\r")

const body =     DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();  // Append a tab header paragraph. const header = body.appendParagraph('A Document'); header.setHeading(DocumentApp.ParagraphHeading.HEADING1);  // Append a section header paragraph. const 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('123abc');  // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().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 tab, anchored to the first paragraph. paragraph.addPositionedImage(image);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
imageBlobSourceข้อมูลรูปภาพ

รีเทิร์น

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('123abc');  // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().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('123abc');  // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
imageBlobSourceข้อมูลรูปภาพ

รีเทิร์น

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('123abc');  // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
imageInlineImageข้อมูลรูปภาพ

รีเทิร์น

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('123abc');  // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().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('123abc');  // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
pageBreakPageBreakตัวแบ่งหน้าที่จะเพิ่มต่อท้าย

รีเทิร์น

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('123abc');  // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().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.');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
textStringเนื้อหาข้อความ

รีเทิร์น

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('123abc');  // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
textTextองค์ประกอบข้อความที่จะต่อท้าย

รีเทิร์น

Text — องค์ประกอบข้อความต่อท้าย

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

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

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

clear()

ล้างเนื้อหาขององค์ประกอบ

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน


copy()

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

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

รีเทิร์น

Paragraph — สำเนาใหม่

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

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

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

editAsText()

รับองค์ประกอบปัจจุบันเวอร์ชัน Text เพื่อแก้ไข

ใช้ editAsText เพื่อจัดการเนื้อหาขององค์ประกอบเป็น Rich Text โหมด editAsText ไม่สนใจองค์ประกอบที่ไม่ใช่ข้อความ (เช่น InlineImage และ HorizontalRule)

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

const body =     DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().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)

ค้นหาเนื้อหาขององค์ประกอบเพื่อหารายการที่สืบทอดมาจากประเภทที่ระบุ

พารามิเตอร์

ชื่อประเภทคำอธิบาย
elementTypeElementTypeประเภทองค์ประกอบที่จะค้นหา

รีเทิร์น

RangeElement — ผลการค้นหาที่ระบุตําแหน่งขององค์ประกอบการค้นหา

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

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

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

findElement(elementType, from)

ค้นหาเนื้อหาขององค์ประกอบเพื่อหารายการที่สืบทอดของประเภทที่ระบุ โดยเริ่มจาก RangeElement ที่ระบุ

const body =     DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();  // Define the search parameters.  let searchResult = null;  // Search until the paragraph is found. while (     (searchResult = body.findElement(          DocumentApp.ElementType.PARAGRAPH,          searchResult,          ))) {   const par = searchResult.getElement().asParagraph();   if (par.getHeading() === DocumentApp.ParagraphHeading.HEADING1) {     // Found one, update and stop.     par.setText('This is the first header.');     break;   } }

พารามิเตอร์

ชื่อประเภทคำอธิบาย
elementTypeElementTypeประเภทองค์ประกอบที่จะค้นหา
fromRangeElementผลการค้นหาที่จะค้นหา

รีเทิร์น

RangeElement — ผลการค้นหาที่ระบุตำแหน่งถัดไปขององค์ประกอบการค้นหา

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

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

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

findText(searchPattern)

ค้นหาเนื้อหาขององค์ประกอบเพื่อหารูปแบบข้อความที่ระบุโดยใช้นิพจน์ทั่วไป

ระบบไม่รองรับฟีเจอร์นิพจน์ทั่วไปของ JavaScript บางรายการ เช่น กลุ่มที่จับและตัวแก้ไขโหมด

ระบบจะจับคู่รูปแบบนิพจน์ทั่วไปที่ระบุกับบล็อกข้อความแต่ละรายการในองค์ประกอบปัจจุบันแยกกัน

พารามิเตอร์

ชื่อประเภทคำอธิบาย
searchPatternStringรูปแบบที่จะค้นหา

รีเทิร์น

RangeElement — ผลการค้นหาที่ระบุตําแหน่งของข้อความค้นหา หรือเป็นค่าว่างหากไม่พบการจับคู่

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

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

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

findText(searchPattern, from)

ค้นหาเนื้อหาขององค์ประกอบเพื่อหารูปแบบข้อความที่ระบุ โดยเริ่มจากผลการค้นหาหนึ่งๆ

ระบบไม่รองรับฟีเจอร์นิพจน์ทั่วไปของ JavaScript บางรายการ เช่น กลุ่มที่จับและตัวแก้ไขโหมด

ระบบจะจับคู่รูปแบบนิพจน์ทั่วไปที่ระบุกับบล็อกข้อความแต่ละรายการในองค์ประกอบปัจจุบันแยกกัน

พารามิเตอร์

ชื่อประเภทคำอธิบาย
searchPatternStringรูปแบบที่จะค้นหา
fromRangeElementผลการค้นหาที่จะค้นหา

รีเทิร์น

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('123abc');  // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().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

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

getChild(childIndex)

ดึงข้อมูลองค์ประกอบย่อยที่ดัชนีย่อยที่ระบุ

const body =     DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();  // Obtain the first element in the tab. const 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.'); }

พารามิเตอร์

ชื่อประเภทคำอธิบาย
childIndexIntegerดัชนีขององค์ประกอบย่อยที่จะดึงข้อมูล

รีเทิร์น

Element — องค์ประกอบย่อยที่อยู่ที่อินเด็กซ์ที่ระบุ

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

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

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

getChildIndex(child)

ดึงข้อมูลดัชนีย่อยสําหรับองค์ประกอบย่อยที่ระบุ

พารามิเตอร์

ชื่อประเภทคำอธิบาย
childElementองค์ประกอบย่อยที่จะดึงข้อมูลดัชนี

รีเทิร์น

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('123abc');  // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().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 ของลิงก์ หรือเป็นค่าว่างหากองค์ประกอบมีค่าหลายค่าสำหรับแอตทริบิวต์นี้

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

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

ดึงข้อมูลจํานวนเด็ก

const body =     DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();  // Log the number of elements in the tab. Logger.log(`There are ${body.getNumChildren()} elements in the tab's 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 ตามรหัสของรูปภาพ

พารามิเตอร์

ชื่อประเภทคำอธิบาย
idStringรหัสรูปภาพ

รีเทิร์น

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() เพื่อระบุประเภทที่แน่นอนขององค์ประกอบหนึ่งๆ

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

insertHorizontalRule(childIndex)

สร้างและแทรก HorizontalRule ที่ดัชนีที่ระบุ

พารามิเตอร์

ชื่อประเภทคำอธิบาย
childIndexIntegerดัชนีที่จะแทรกองค์ประกอบ

รีเทิร์น

HorizontalRule — องค์ประกอบเส้นแนวนอนใหม่

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

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

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

insertInlineImage(childIndex, image)

สร้างและแทรก InlineImage ใหม่จาก Blob รูปภาพที่ระบุ ณ ดัชนีที่ระบุ

พารามิเตอร์

ชื่อประเภทคำอธิบาย
childIndexIntegerดัชนีที่จะแทรกองค์ประกอบ
imageBlobSourceข้อมูลรูปภาพ

รีเทิร์น

InlineImage — องค์ประกอบรูปภาพในบรรทัดแทรก

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

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

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

insertInlineImage(childIndex, image)

แทรก InlineImage ที่ระบุไว้ที่ดัชนีที่ระบุ

พารามิเตอร์

ชื่อประเภทคำอธิบาย
childIndexIntegerดัชนีที่จะแทรกองค์ประกอบ
imageInlineImageข้อมูลรูปภาพ

รีเทิร์น

InlineImage — องค์ประกอบรูปภาพในบรรทัดแทรก

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

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

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

insertPageBreak(childIndex)

สร้างและแทรก PageBreak ใหม่ ณ ดัชนีที่ระบุ

หมายเหตุ: PageBreaks ต้องไม่อยู่ภายใน TableCells หากองค์ประกอบปัจจุบันอยู่ในเซลล์ตาราง ระบบจะแสดงข้อยกเว้น

พารามิเตอร์

ชื่อประเภทคำอธิบาย
childIndexIntegerดัชนีที่จะแทรกองค์ประกอบ

รีเทิร์น

PageBreak — องค์ประกอบตัวแบ่งหน้าใหม่

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

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

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

insertPageBreak(childIndex, pageBreak)

แทรก PageBreak ที่ระบุไว้ที่ดัชนีที่ระบุ

หมายเหตุ: PageBreaks ต้องไม่อยู่ภายใน TableCells หากองค์ประกอบปัจจุบันอยู่ในเซลล์ตาราง ระบบจะแสดงข้อยกเว้น

พารามิเตอร์

ชื่อประเภทคำอธิบาย
childIndexIntegerดัชนีที่จะแทรกองค์ประกอบ
pageBreakPageBreakp[page break to insert

รีเทิร์น

PageBreak — องค์ประกอบตัวแบ่งหน้าที่แทรก

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

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

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

insertText(childIndex, text)

สร้างและแทรกองค์ประกอบข้อความใหม่ ณ ดัชนีที่ระบุ

พารามิเตอร์

ชื่อประเภทคำอธิบาย
childIndexIntegerดัชนีที่จะแทรกองค์ประกอบ
textStringเนื้อหาข้อความ

รีเทิร์น

Text — องค์ประกอบข้อความใหม่

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

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

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

insertText(childIndex, text)

แทรกองค์ประกอบ Text ที่ระบุ ณ ดัชนีที่ระบุพร้อมเนื้อหาข้อความที่ระบุ

พารามิเตอร์

ชื่อประเภทคำอธิบาย
childIndexIntegerดัชนีที่จะแทรกองค์ประกอบ
textTextองค์ประกอบข้อความที่จะแทรก

รีเทิร์น

Text — องค์ประกอบข้อความที่แทรก

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

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

isLeftToRight()

ดึงข้อมูลการตั้งค่าจากซ้ายไปขวา

รีเทิร์น

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

รีเทิร์น

Paragraph — องค์ประกอบที่ผสาน

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

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

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

removeChild(child)

นำองค์ประกอบย่อยที่ระบุออก

พารามิเตอร์

ชื่อประเภทคำอธิบาย
childElementองค์ประกอบย่อยที่จะนําออก

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

รีเทิร์น

Paragraph — องค์ประกอบที่ถูกนำออก

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

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

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

removePositionedImage(id)

นำ PositionedImage ออกตามรหัสของรูปภาพ

พารามิเตอร์

ชื่อประเภทคำอธิบาย
idStringรหัสรูปภาพ

รีเทิร์น

Boolean — ระบุว่ารูปภาพที่ระบุถูกนำออกหรือไม่

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

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

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

replaceText(searchPattern, replacement)

แทนที่รายการทั้งหมดของรูปแบบข้อความหนึ่งๆ ด้วยสตริงการแทนที่หนึ่งๆ โดยใช้นิพจน์ทั่วไป

ระบบจะส่งรูปแบบการค้นหาเป็นสตริง ไม่ใช่ออบเจ็กต์นิพจน์ทั่วไปของ JavaScript คุณจึงต้องยกเว้นเครื่องหมายแบ็กสแลชในนิพจน์

วิธีนี้ใช้ไลบรารีนิพจน์ทั่วไป RE2 ของ Google ซึ่งจํากัดไวยากรณ์ที่รองรับ

ระบบจะจับคู่รูปแบบนิพจน์ทั่วไปที่ระบุกับบล็อกข้อความแต่ละรายการในองค์ประกอบปัจจุบันแยกกัน

const body =     DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();  // Clear the text surrounding "Apps Script", with or without text. body.replaceText('^.*Apps ?Script.*$', 'Apps Script');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
searchPatternStringรูปแบบนิพจน์ทั่วไปที่จะค้นหา
replacementStringข้อความที่จะใช้แทนที่

รีเทิร์น

Element — องค์ประกอบปัจจุบัน

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

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

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

setAlignment(alignment)

ตั้งค่า HorizontalAlignment

พารามิเตอร์

ชื่อประเภทคำอธิบาย
alignmentHorizontalAlignmentการจัดแนวนอน

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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แอตทริบิวต์ขององค์ประกอบ

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

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

setHeading(heading)

ตั้งค่า ParagraphHeading

พารามิเตอร์

ชื่อประเภทคำอธิบาย
headingParagraphHeadingส่วนหัว

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

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

setIndentEnd(indentEnd)

ตั้งค่าการเยื้องท้ายบรรทัดเป็นจุด

พารามิเตอร์

ชื่อประเภทคำอธิบาย
indentEndNumberการเยื้องท้ายในจุด

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

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

setIndentFirstLine(indentFirstLine)

ตั้งค่าการเยื้องบรรทัดแรกเป็นจุด

พารามิเตอร์

ชื่อประเภทคำอธิบาย
indentFirstLineNumberการเยื้องบรรทัดแรกเป็นจุด

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

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

setIndentStart(indentStart)

ตั้งค่าการเยื้องต้นบรรทัดเป็นจุด

พารามิเตอร์

ชื่อประเภทคำอธิบาย
indentStartNumberการเยื้องเริ่มต้นเป็นจุด

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

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

setLeftToRight(leftToRight)

ตั้งค่าจากซ้ายไปขวา

พารามิเตอร์

ชื่อประเภทคำอธิบาย
leftToRightBooleanการตั้งค่าจากซ้ายไปขวา

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

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

setLineSpacing(multiplier)

กำหนดระยะห่างบรรทัดเป็นจำนวนที่ระบุจำนวนบรรทัดที่จะใช้สำหรับระยะห่าง

พารามิเตอร์

ชื่อประเภทคำอธิบาย
multiplierNumberจํานวนบรรทัด

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

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

setLinkUrl(url)

ตั้งค่า URL ของลิงก์

พารามิเตอร์

ชื่อประเภทคำอธิบาย
urlStringURL ของลิงก์

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

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

setSpacingAfter(spacingAfter)

กำหนดระยะห่างหลังองค์ประกอบเป็นจุด

พารามิเตอร์

ชื่อประเภทคำอธิบาย
spacingAfterNumberระยะห่างหลังองค์ประกอบเป็นพอยต์

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

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

setSpacingBefore(spacingBefore)

ตั้งค่าระยะห่างก่อนองค์ประกอบเป็นจุด

พารามิเตอร์

ชื่อประเภทคำอธิบาย
spacingBeforeNumberระยะห่างก่อนองค์ประกอบเป็นพอยต์

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

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

setText(text)

ตั้งค่าเนื้อหาของย่อหน้าเป็นข้อความ

หมายเหตุ: ระบบจะล้างเนื้อหาที่มีอยู่

พารามิเตอร์

ชื่อประเภทคำอธิบาย
textStringเนื้อหาข้อความใหม่

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

สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 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 in the active tab be superscript. const documentTab =     DocumentApp.getActiveDocument().getActiveTab().asDocumentTab(); const text = documentTab.getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
textAlignmentTextAlignmentประเภทการจัดแนวข้อความที่จะใช้

รีเทิร์น

Paragraph — องค์ประกอบปัจจุบัน

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

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

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