Class Paragraph

ย่อหน้า

องค์ประกอบที่แสดงย่อหน้า 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คำอธิบาย
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('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คำอธิบาย
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('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คำอธิบาย
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('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คำอธิบาย
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('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คำอธิบาย
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('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คำอธิบาย
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 เพื่อบิดเบือนองค์ประกอบองค์ประกอบเป็นข้อความริชมีเดีย โหมด 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คำอธิบาย
elementTypeElementTypeประเภทขององค์ประกอบที่จะค้นหา

ขากลับ

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คำอธิบาย
elementTypeElementTypeประเภทขององค์ประกอบที่จะค้นหา
fromRangeElementผลการค้นหาที่จะค้นหา

ขากลับ

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

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

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

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

findText(searchPattern)

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

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

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

พารามิเตอร์

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

ขากลับ

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

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

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

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

findText(searchPattern, from)

ค้นหาเนื้อหาขององค์ประกอบสําหรับรูปแบบข้อความที่ระบุ เริ่มจากผลการค้นหาที่กําหนด

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

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
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('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คำอธิบาย
childIndexIntegerดัชนีขององค์ประกอบย่อยเพื่อดึง

ขากลับ

Element — องค์ประกอบย่อยที่ดัชนีที่ระบุ

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

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

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

getChildIndex(child)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
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('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คำอธิบาย
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() เพื่อระบุประเภทขององค์ประกอบที่กําหนด

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คำอธิบาย
childIndexIntegerดัชนีที่จะแทรกองค์ประกอบ

ขากลับ

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

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

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

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

insertInlineImage(childIndex, image)

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

พารามิเตอร์

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

ขากลับ

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

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

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

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

insertInlineImage(childIndex, image)

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

พารามิเตอร์

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

ขากลับ

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

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

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

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

insertPageBreak(childIndex)

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

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

พารามิเตอร์

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

ขากลับ

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

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

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

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

insertPageBreak(childIndex, pageBreak)

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

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
childIndexIntegerดัชนีที่จะแทรกองค์ประกอบ
pageBreakPageBreakแทรก [[age break] เพื่อแทรก

ขากลับ

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

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

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

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

insertText(childIndex, text)

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

พารามิเตอร์

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

ขากลับ

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

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

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

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

insertText(childIndex, text)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
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 เดียวกันเท่านั้น องค์ประกอบย่อยที่อยู่ในองค์ประกอบปัจจุบันจะย้ายไปยังองค์ประกอบข้างเคียงก่อนหน้า

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

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คำอธิบาย
childElementองค์ประกอบย่อยที่จะลบ

ขากลับ

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คำอธิบาย
idStringรหัสรูปภาพ

ขากลับ

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คำอธิบาย
searchPatternStringรูปแบบนิพจน์ทั่วไปที่จะค้นหา
replacementStringข้อความที่จะใช้แทนที่

ขากลับ

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

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

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

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

setAlignment(alignment)

ตั้งค่า HorizontalAlignment

พารามิเตอร์

ชื่อTypeคำอธิบาย
alignmentHorizontalAlignmentการจัดข้อความแนวนอน

ขากลับ

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คำอธิบาย
attributesObjectแอตทริบิวต์ขององค์ประกอบ

ขากลับ

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

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

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

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

setHeading(heading)

ตั้งค่า ParagraphHeading

พารามิเตอร์

ชื่อTypeคำอธิบาย
headingParagraphHeadingหัวเรื่อง

ขากลับ

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

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

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

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

setIndentEnd(indentEnd)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
indentEndNumberการเยื้องท้ายบรรทัด

ขากลับ

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

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

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

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

setIndentFirstLine(indentFirstLine)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
indentFirstLineNumberการเยื้องบรรทัดแรก

ขากลับ

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

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

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

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

setIndentStart(indentStart)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
indentStartNumberการเยื้องเริ่มต้น

ขากลับ

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

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

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

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

setLeftToRight(leftToRight)

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

พารามิเตอร์

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

ขากลับ

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

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

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

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

setLineSpacing(multiplier)

กําหนดระยะห่างของบรรทัดเป็นปริมาณที่ระบุจํานวนบรรทัดที่จะใช้ในการเว้นวรรค

พารามิเตอร์

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

ขากลับ

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

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

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

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

setLinkUrl(url)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
urlStringURL ของลิงก์

ขากลับ

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

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

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

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

setSpacingAfter(spacingAfter)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
spacingAfterNumberระยะห่างหลังองค์ประกอบ

ขากลับ

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

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

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

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

setSpacingBefore(spacingBefore)

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
spacingBeforeNumberระยะห่างก่อนองค์ประกอบ

ขากลับ

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

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

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

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

setText(text)

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

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
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 be superscript.
var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

พารามิเตอร์

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

ขากลับ

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

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

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

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