Class Text

Text

องค์ประกอบที่แสดงถึงพื้นที่ Rich Text ข้อความทั้งหมดใน Document อยู่ภายในองค์ประกอบ Text องค์ประกอบ Text สามารถอยู่ใน Equation, EquationFunction, ListItem หรือ Paragraph แต่ต้องไม่มีองค์ประกอบอื่นในตัวเอง สำหรับข้อมูลเพิ่มเติม ข้อมูลเกี่ยวกับโครงสร้างเอกสาร โปรดดูคำแนะนำในการขยาย Google เอกสาร

// Gets the body contents of the active tab.
var body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody();

// Use editAsText to obtain a single text element containing
// all the characters in the tab.
var text = body.editAsText();

// Insert text at the beginning of the tab.
text.insertText(0, 'Inserted text.\n');

// Insert text at the end of the tab.
text.appendText('\nAppended text.');

// Make the first half of the tab blue.
text.setForegroundColor(0, text.getText().length / 2, '#00FFFF');

เมธอด

วิธีการประเภทการแสดงผลรายละเอียดแบบย่อ
appendText(text)Textเพิ่มข้อความที่ต้องการต่อท้ายเขตข้อความนี้
copy()Textแสดงผลสำเนาที่แยกส่วนลึกขององค์ประกอบปัจจุบัน
deleteText(startOffset, endOffsetInclusive)Textลบข้อความจำนวนหนึ่ง
editAsText()Textรับองค์ประกอบปัจจุบันเวอร์ชันText เพื่อแก้ไข
findText(searchPattern)RangeElementค้นหาเนื้อหาขององค์ประกอบสำหรับรูปแบบข้อความที่ระบุโดยใช้นิพจน์ทั่วไป
findText(searchPattern, from)RangeElementค้นหาเนื้อหาขององค์ประกอบสำหรับรูปแบบข้อความที่ระบุ โดยเริ่มต้นจาก ผลการค้นหา
getAttributes()Objectดึงแอตทริบิวต์ขององค์ประกอบ
getAttributes(offset)Objectเรียกแอตทริบิวต์ในการชดเชยอักขระที่ระบุ
getBackgroundColor()Stringเรียกดูการตั้งค่าสีพื้นหลัง
getBackgroundColor(offset)Stringดึงสีพื้นหลังตามออฟเซ็ตอักขระที่ระบุ
getFontFamily()Stringเรียกข้อมูลการตั้งค่าชุดแบบอักษร
getFontFamily(offset)Stringดึงชุดแบบอักษรตามออฟเซ็ตอักขระที่ระบุ
getFontSize()Numberเรียกข้อมูลการตั้งค่าขนาดแบบอักษร
getFontSize(offset)Numberดึงขนาดแบบอักษรตามออฟเซ็ตอักขระที่ระบุ
getForegroundColor()Stringดึงข้อมูลการตั้งค่าสีพื้นหน้า
getForegroundColor(offset)Stringดึงสีพื้นหน้าตามออฟเซ็ตอักขระที่ระบุ
getLinkUrl()Stringดึงข้อมูล URL ของลิงก์
getLinkUrl(offset)Stringเรียก URL ของลิงก์ตามออฟเซ็ตอักขระที่ระบุ
getNextSibling()Elementเรียกข้อมูลองค์ประกอบข้างเคียงถัดไปขององค์ประกอบ
getParent()ContainerElementเรียกข้อมูลองค์ประกอบหลักขององค์ประกอบ
getPreviousSibling()Elementดึงองค์ประกอบระดับเดียวกันก่อนหน้านี้ขององค์ประกอบ
getText()Stringเรียกคืนเนื้อหาขององค์ประกอบเป็นสตริงข้อความ
getTextAlignment()TextAlignmentปรับการจัดข้อความ
getTextAlignment(offset)TextAlignmentปรับข้อความสำหรับอักขระตัวเดียว
getTextAttributeIndices()Integer[]ดึงชุดดัชนีข้อความที่สอดคล้องกับการเริ่มต้นการจัดรูปแบบข้อความที่แตกต่างกัน วิ่งได้
getType()ElementTypeเรียกข้อมูล ElementType ขององค์ประกอบ
insertText(offset, text)Textแทรกข้อความที่ระบุที่ค่าออฟเซ็ตอักขระที่ระบุ
isAtDocumentEnd()Booleanกำหนดว่าองค์ประกอบอยู่ที่ส่วนท้ายของ Document หรือไม่
isBold()Booleanดึงข้อมูลการตั้งค่าตัวหนา
isBold(offset)Booleanดึงการตั้งค่าตัวหนาที่ออฟเซ็ตอักขระที่ระบุ
isItalic()Booleanดึงข้อมูลการตั้งค่าตัวเอียง
isItalic(offset)Booleanดึงการตั้งค่าตัวเอียงในออฟเซ็ตอักขระที่ระบุ
isStrikethrough()Booleanเรียกข้อมูลการตั้งค่าขีดทับ
isStrikethrough(offset)Booleanเรียกการตั้งค่าขีดทับที่ออฟเซ็ตอักขระที่ระบุ
isUnderline()Booleanดึงข้อมูลการตั้งค่าขีดเส้นใต้
isUnderline(offset)Booleanเรียกการตั้งค่าขีดเส้นใต้ที่ออฟเซ็ตอักขระที่ระบุ
merge()Textผสานองค์ประกอบกับรายการข้างเคียงที่อยู่ก่อนหน้าประเภทเดียวกัน
removeFromParent()Textนำองค์ประกอบออกจากระดับบนสุด
replaceText(searchPattern, replacement)Elementแทนที่ทุกรายการของรูปแบบข้อความที่ระบุด้วยสตริงการแทนที่ที่กำหนด โดยใช้ข้อความปกติ นิพจน์
setAttributes(startOffset, endOffsetInclusive, attributes)Textใช้แอตทริบิวต์ที่ระบุกับช่วงอักขระที่ระบุ
setAttributes(attributes)Textตั้งค่าแอตทริบิวต์ขององค์ประกอบ
setBackgroundColor(startOffset, endOffsetInclusive, color)Textกำหนดสีพื้นหลังสำหรับช่วงอักขระที่ระบุ
setBackgroundColor(color)Textตั้งค่าสีพื้นหลัง
setBold(bold)Textกำหนดการตั้งค่าตัวหนา
setBold(startOffset, endOffsetInclusive, bold)Textกำหนดการตั้งค่าตัวหนาสำหรับช่วงอักขระที่ระบุ
setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)Textตั้งค่าชุดแบบอักษรสำหรับช่วงอักขระที่ระบุ
setFontFamily(fontFamilyName)Textตั้งค่าชุดแบบอักษร
setFontSize(startOffset, endOffsetInclusive, size)Textตั้งค่าขนาดแบบอักษรสำหรับช่วงอักขระที่ระบุ
setFontSize(size)Textตั้งค่าขนาดแบบอักษร
setForegroundColor(startOffset, endOffsetInclusive, color)Textกำหนดสีพื้นหน้าสำหรับช่วงอักขระที่ระบุ
setForegroundColor(color)Textตั้งค่าสีพื้นหน้า
setItalic(italic)Textตั้งค่าตัวเอียง
setItalic(startOffset, endOffsetInclusive, italic)Textกำหนดการตั้งค่าตัวเอียงสำหรับช่วงอักขระที่ระบุ
setLinkUrl(startOffset, endOffsetInclusive, url)Textตั้งค่า URL ของลิงก์สำหรับช่วงอักขระที่ระบุ
setLinkUrl(url)Textตั้งค่า URL ของลิงก์
setStrikethrough(strikethrough)Textกำหนดการตั้งค่าขีดทับ
setStrikethrough(startOffset, endOffsetInclusive, strikethrough)Textกำหนดการตั้งค่าขีดทับสำหรับช่วงอักขระที่ระบุ
setText(text)Textตั้งค่าเนื้อหาข้อความ
setTextAlignment(startOffset, endOffsetInclusive, textAlignment)Textตั้งค่าการจัดข้อความสำหรับช่วงอักขระที่ระบุ
setTextAlignment(textAlignment)Textตั้งค่าการจัดข้อความ
setUnderline(underline)Textตั้งค่าการขีดเส้นใต้
setUnderline(startOffset, endOffsetInclusive, underline)Textตั้งค่าการขีดเส้นใต้สำหรับช่วงอักขระที่ระบุ

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

appendText(text)

เพิ่มข้อความที่ต้องการต่อท้ายเขตข้อความนี้

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Adds the text, 'Sample body text,' to the end of the tab body.
const text = body.editAsText().appendText('Sample body text');

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

copy()

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

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

รีเทิร์น

Text — สำเนาใหม่

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

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

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

deleteText(startOffset, endOffsetInclusive)

ลบข้อความจำนวนหนึ่ง

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Deletes the first 10 characters in the body.
 const text = body.editAsText().deleteText(0, 9);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerระยะห่างของอักขระของอักขระตัวแรกที่จะลบ
endOffsetInclusiveIntegerระยะห่างของอักขระของอักขระตัวสุดท้ายที่จะลบ

รีเทิร์น

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

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

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

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

editAsText()

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

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

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

var 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 — เวอร์ชันข้อความขององค์ประกอบปัจจุบัน


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

getAttributes()

ดึงแอตทริบิวต์ขององค์ประกอบ

ผลลัพธ์คือออบเจ็กต์ที่มีพร็อพเพอร์ตี้สำหรับแอตทริบิวต์ขององค์ประกอบที่ถูกต้องแต่ละรายการ โดยที่แต่ละรายการ ชื่อพร็อพเพอร์ตี้สอดคล้องกับรายการในการแจกแจง DocumentApp.Attribute

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.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

getAttributes(offset)

เรียกแอตทริบิวต์ในการชดเชยอักขระที่ระบุ

ผลลัพธ์คือออบเจ็กต์ที่มีพร็อพเพอร์ตี้สำหรับแอตทริบิวต์ข้อความที่ถูกต้องแต่ละรายการ โดยที่แต่ละรายการ ชื่อพร็อพเพอร์ตี้สอดคล้องกับรายการในการแจกแจง DocumentApp.Attribute

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Declares style attributes.
const style = {}
style[DocumentApp.Attribute.BOLD] = true;
style[DocumentApp.Attribute.ITALIC] = true;
style[DocumentApp.Attribute.FONT_SIZE] = 29;

// Sets the style attributes to the tab's body.
const text = body.editAsText();
text.setAttributes(style);

// Gets the style attributes applied to the eleventh character in the
// body and logs them to the console.
const attributes = text.getAttributes(10);
console.log(attributes);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
offsetIntegerระยะห่างของอักขระ

รีเทิร์น

Object — แอตทริบิวต์ขององค์ประกอบ

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

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

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

getBackgroundColor()

เรียกดูการตั้งค่าสีพื้นหลัง

รีเทิร์น

String — สีพื้นหลัง ซึ่งมีการจัดรูปแบบในรูปแบบ CSS (เช่น '#ffffff') หรือ Null หากองค์ประกอบมีค่าหลายค่าสำหรับแอตทริบิวต์นี้

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

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

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

getBackgroundColor(offset)

ดึงสีพื้นหลังตามออฟเซ็ตอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the background color of the first 3 characters in the body.
const text = body.editAsText().setBackgroundColor(0, 2, '#FFC0CB');

// Gets the background color of the first character in the body.
const backgroundColor = text.getBackgroundColor(0);

// Logs the background color to the console.
console.log(backgroundColor);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
offsetIntegerระยะห่างของอักขระ

รีเทิร์น

String — สีพื้นหลัง ซึ่งอยู่ในรูปแบบ CSS (เช่น '#ffffff')

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

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

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

getFontFamily()

เรียกข้อมูลการตั้งค่าชุดแบบอักษร ชื่ออาจเป็นแบบอักษรใดก็ได้จากเมนูแบบอักษรในเอกสารหรือ Google Fonts และคำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่ ขณะนี้เมธอด getFontFamily() และ setFontFamily(fontFamilyName) ใช้ชื่อสตริงสำหรับแบบอักษรแทน enum FontFamily แม้ว่า Enum นี้จะ เลิกใช้งานแล้ว แต่จะยังเข้ากันได้กับสคริปต์เวอร์ชันเก่ากว่า

รีเทิร์น

String — ชุดแบบอักษร หรือค่าว่างหากองค์ประกอบมีค่าหลายค่าสำหรับแอตทริบิวต์นี้

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

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

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

getFontFamily(offset)

ดึงชุดแบบอักษรตามออฟเซ็ตอักขระที่ระบุ ชื่อสามารถเป็นแบบอักษรใดก็ได้จาก เมนูแบบอักษรในเอกสารหรือ Google Fonts และ คำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่ เมธอด getFontFamily() และ setFontFamily(fontFamilyName) แต่ตอนนี้ให้ใช้ชื่อสตริงสำหรับแบบอักษรแทน enum ของ FontFamily แม้ว่า Enum นี้จะ เลิกใช้งานแล้ว แต่จะยังเข้ากันได้กับสคริปต์เวอร์ชันเก่ากว่า

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the font of the first 16 characters to Impact.
const text = body.editAsText().setFontFamily(0, 15, 'Impact');

// Gets the font family of the 16th character in the tab body.
const fontFamily = text.getFontFamily(15);

// Logs the font family to the console.
console.log(fontFamily);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
offsetIntegerระยะห่างของอักขระ

รีเทิร์น

String — ชุดแบบอักษร

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

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

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

getFontSize()

เรียกข้อมูลการตั้งค่าขนาดแบบอักษร

รีเทิร์น

Number — ขนาดแบบอักษร หรือค่าว่างหากองค์ประกอบมีหลายค่าสำหรับแอตทริบิวต์นี้

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

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

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

getFontSize(offset)

ดึงขนาดแบบอักษรตามออฟเซ็ตอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the font size of the first 13 characters to 15.
const text = body.editAsText().setFontSize(0, 12, 15);

// Gets the font size of the first character.
const fontSize = text.getFontSize(0);

// Logs the font size to the console.
console.log(fontSize);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
offsetIntegerระยะห่างของอักขระ

รีเทิร์น

Number — ขนาดแบบอักษร

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

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

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

getForegroundColor()

ดึงข้อมูลการตั้งค่าสีพื้นหน้า

รีเทิร์น

String — สีพื้นหน้า ซึ่งมีการจัดรูปแบบในรูปแบบ CSS (เช่น '#ffffff') หรือ Null หากองค์ประกอบมีค่าหลายค่าสำหรับแอตทริบิวต์นี้

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

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

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

getForegroundColor(offset)

ดึงสีพื้นหน้าตามออฟเซ็ตอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the foreground color of the first 3 characters in the tab body.
const text = body.editAsText().setForegroundColor(0, 2, '#0000FF');

// Gets the foreground color of the first character in the tab body.
const foregroundColor = text.getForegroundColor(0);

// Logs the foreground color to the console.
console.log(foregroundcolor);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
offsetIntegerระยะห่างของอักขระ

รีเทิร์น

String — สีพื้นหน้า ซึ่งมีการจัดรูปแบบในรูปแบบ CSS (เช่น '#ffffff')

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

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

getLinkUrl(offset)

เรียก URL ของลิงก์ตามออฟเซ็ตอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Applies a link to the first 10 characters in the body.
const text = body.editAsText().setLinkUrl(0, 9, 'https://www.example.com/');

// Gets the URL of the link from the first character.
const link = text.getLinkUrl(0);

// Logs the link URL to the console.
console.log(link);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
offsetIntegerระยะห่างของอักขระ

รีเทิร์น

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

getParent()

เรียกข้อมูลองค์ประกอบหลักขององค์ประกอบ

องค์ประกอบหลักมีองค์ประกอบปัจจุบัน

รีเทิร์น

ContainerElement — องค์ประกอบระดับบนสุด

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

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

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

getPreviousSibling()

ดึงองค์ประกอบระดับเดียวกันก่อนหน้านี้ขององค์ประกอบ

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

รีเทิร์น

Element — องค์ประกอบข้างเคียงก่อนหน้า

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

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

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

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

getTextAlignment(offset)

ปรับข้อความสำหรับอักขระตัวเดียว ประเภทการตรวจสอบความสอดคล้องที่ใช้ได้ ได้แก่ DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPT และ DocumentApp.TextAlignment.SUPERSCRIPT

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the text alignment of the tab's body to NORMAL.
const text = body.editAsText().setTextAlignment(DocumentApp.TextAlignment.NORMAL);

// Gets the text alignment of the ninth character.
const alignment = text.getTextAlignment(8);

// Logs the text alignment to the console.
console.log(alignment.toString());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
offsetIntegerระยะห่างของอักขระ

รีเทิร์น

TextAlignment — ประเภทการจัดข้อความ หรือ null หากไม่เคยมีการตั้งค่าการจัดข้อความไว้

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

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

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

getTextAttributeIndices()

ดึงชุดดัชนีข้อความที่สอดคล้องกับการเริ่มต้นการจัดรูปแบบข้อความที่แตกต่างกัน วิ่งได้

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Gets the text indices at which text formatting changes.
const indices = body.editAsText().getTextAttributeIndices();

// Logs the indices to the console.
console.log(indices.toString());

รีเทิร์น

Integer[] — ชุดดัชนีข้อความที่การจัดรูปแบบข้อความมีการเปลี่ยนแปลง

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

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

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

getType()

เรียกข้อมูล ElementType ขององค์ประกอบ

ใช้ getType() เพื่อระบุประเภทที่แน่นอนขององค์ประกอบที่ระบุ

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

// Obtain the first element in the active tab's 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

insertText(offset, text)

แทรกข้อความที่ระบุที่ค่าออฟเซ็ตอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Inserts the text, 'Sample inserted text', at the start of the body content.
const text = body.editAsText().insertText(0, 'Sample inserted text');

พารามิเตอร์

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

รีเทิร์น

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

isBold()

ดึงข้อมูลการตั้งค่าตัวหนา

รีเทิร์น

Boolean — จะบอกว่าข้อความเป็นตัวหนาหรือ Null หากองค์ประกอบมีหลายค่า แอตทริบิวต์

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

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

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

isBold(offset)

ดึงการตั้งค่าตัวหนาที่ออฟเซ็ตอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Bolds the first 4 characters in the tab body.
const text = body.editAsText().setBold(0, 3, true);

// Gets whether or not the text is bold.
const bold = text.editAsText().isBold(0);

// Logs the text's bold setting to the console
console.log(bold);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
offsetIntegerระยะห่างของอักขระ

รีเทิร์น

Boolean — การตั้งค่าตัวหนา

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

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

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

isItalic()

ดึงข้อมูลการตั้งค่าตัวเอียง

รีเทิร์น

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

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

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

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

isItalic(offset)

ดึงการตั้งค่าตัวเอียงในออฟเซ็ตอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 13 characters of the tab body to italic.
const text = body.editAsText().setItalic(0, 12, true);

// Gets whether the fifth character in the tab body is set to
// italic and logs it to the console.
const italic = text.isItalic(4);
console.log(italic);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
offsetIntegerระยะห่างของอักขระ

รีเทิร์น

Boolean — การตั้งค่าตัวเอียง

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

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

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

isStrikethrough()

เรียกข้อมูลการตั้งค่าขีดทับ

รีเทิร์น

Boolean — ข้อความมีขีดทับหรือค่าว่างหากองค์ประกอบมีค่าหลายค่าสำหรับ แอตทริบิวต์นี้

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

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

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

isStrikethrough(offset)

เรียกการตั้งค่าขีดทับที่ออฟเซ็ตอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 17 characters of the tab body to strikethrough.
const text = body.editAsText().setStrikethrough(0, 16, true);

// Gets whether the first character in the tab body is set to
// strikethrough and logs it to the console.
const strikethrough = text.isStrikethrough(0);
console.log(strikethrough);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
offsetIntegerระยะห่างของอักขระ

รีเทิร์น

Boolean — การตั้งค่าขีดทับ

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

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

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

isUnderline()

ดึงข้อมูลการตั้งค่าขีดเส้นใต้

รีเทิร์น

Boolean — ข้อความจะได้รับการขีดเส้นใต้หรือเป็นค่าว่างหากองค์ประกอบมีค่าหลายค่าสำหรับ แอตทริบิวต์นี้

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

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

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

isUnderline(offset)

เรียกการตั้งค่าขีดเส้นใต้ที่ออฟเซ็ตอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 13 characters of the tab body to underline.
const text = body.editAsText().setUnderline(0, 12, false);

// Gets whether the first character in the tab body is set to
// underline and logs it to the console
const underline = text.editAsText().isUnderline(0);
console.log(underline);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
offsetIntegerระยะห่างของอักขระ

รีเทิร์น

Boolean — การตั้งค่าการขีดเส้นใต้

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

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

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

merge()

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

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

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

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

// Example 1: Merge paragraphs
// Append two paragraphs to the document's active tab.
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();

รีเทิร์น

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

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

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

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

removeFromParent()

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

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

// Remove all images in the active tab's body.
var imgs = body.getImages();
for (var i = 0; i < imgs.length; i++) {
  imgs[i].removeFromParent();
}

รีเทิร์น

Text — องค์ประกอบที่นำออก

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

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

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

replaceText(searchPattern, replacement)

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

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

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

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

var 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

setAttributes(startOffset, endOffsetInclusive, attributes)

ใช้แอตทริบิวต์ที่ระบุกับช่วงอักขระที่ระบุ

พารามิเตอร์แอตทริบิวต์ที่ระบุต้องเป็นออบเจ็กต์ที่ชื่อพร็อพเพอร์ตี้แต่ละชื่อเป็นรายการใน การแจงนับ DocumentApp.Attribute และค่าพร็อพเพอร์ตี้แต่ละค่าคือค่าใหม่ ใช้แล้ว

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Declares style attributes for font size and font family.
const style = {}
style[DocumentApp.Attribute.FONT_SIZE] = 20 ;
style[DocumentApp.Attribute.FONT_FAMILY] = 'Impact';

// Sets the style attributes to the first 9 characters in the tab's body.
const text = body.setAttributes(0, 8, style);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerออฟเซ็ตเริ่มต้นของช่วงข้อความ
endOffsetInclusiveIntegerออฟเซ็ตสิ้นสุดของช่วงข้อความ
attributesObjectแอตทริบิวต์ขององค์ประกอบ

รีเทิร์น

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

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

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

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

setAttributes(attributes)

ตั้งค่าแอตทริบิวต์ขององค์ประกอบ

พารามิเตอร์แอตทริบิวต์ที่ระบุต้องเป็นออบเจ็กต์ที่ชื่อพร็อพเพอร์ตี้แต่ละชื่อเป็นรายการใน การแจงนับ DocumentApp.Attribute และค่าพร็อพเพอร์ตี้แต่ละค่าคือค่าใหม่ ใช้แล้ว

var doc = DocumentApp.getActiveDocument();
var documentTab = doc.getActiveTab().asDocumentTab();
var body = documentTab.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);

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

setBackgroundColor(startOffset, endOffsetInclusive, color)

กำหนดสีพื้นหลังสำหรับช่วงอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the background color of the first 3 characters in the
// tab body to hex color #0000FF.
const text = body.editAsText().setBackgroundColor(0, 2, '#0000FF');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerออฟเซ็ตเริ่มต้นของช่วงข้อความ
endOffsetInclusiveIntegerออฟเซ็ตสิ้นสุดของช่วงข้อความ
colorStringสีพื้นหลังในรูปแบบ CSS (เช่น '#ffffff')

รีเทิร์น

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

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

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

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

setBackgroundColor(color)

ตั้งค่าสีพื้นหลัง

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorStringสีพื้นหลัง โดยมีรูปแบบเป็น CSS (เช่น '#ffffff')

รีเทิร์น

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

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

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

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

setBold(bold)

กำหนดการตั้งค่าตัวหนา

พารามิเตอร์

ชื่อประเภทคำอธิบาย
boldBooleanการตั้งค่าตัวหนา

รีเทิร์น

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

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

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

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

setBold(startOffset, endOffsetInclusive, bold)

กำหนดการตั้งค่าตัวหนาสำหรับช่วงอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to bold.
const text = body.editAsText().setBold(0, 10, true);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerออฟเซ็ตเริ่มต้นของช่วงข้อความ
endOffsetInclusiveIntegerออฟเซ็ตสิ้นสุดของช่วงข้อความ
boldBooleanการตั้งค่าตัวหนา

รีเทิร์น

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

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

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

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

setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)

ตั้งค่าชุดแบบอักษรสำหรับช่วงอักขระที่ระบุ ชื่อเป็นแบบอักษรใดก็ได้จากแบบอักษร ในเอกสารหรือ Google Fonts และคำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่ ชื่อแบบอักษรที่ไม่รู้จักจะแสดงผลเป็น Arial เมธอด getFontFamily(offset) และ ตอนนี้ setFontFamily(fontFamilyName) ใช้ชื่อสตริงสำหรับแบบอักษรแทน enum ของ FontFamily แม้ว่า Enum นี้จะ เลิกใช้งานแล้ว แต่จะยังเข้ากันได้กับสคริปต์เวอร์ชันเก่ากว่า

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the font of the first 4 characters in the tab's body to Roboto.
const text = body.editAsText().setFontFamily(0, 3, 'Roboto');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerออฟเซ็ตเริ่มต้นของช่วงข้อความ
endOffsetInclusiveIntegerออฟเซ็ตสิ้นสุดของช่วงข้อความ
fontFamilyNameStringชื่อชุดแบบอักษรจากเมนูแบบอักษรในเอกสารหรือ Google Fonts

รีเทิร์น

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

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

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

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

setFontFamily(fontFamilyName)

ตั้งค่าชุดแบบอักษร ชื่ออาจเป็นแบบอักษรใดก็ได้จากเมนูแบบอักษรในเอกสารหรือ Google Fonts และคำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่ แบบอักษรที่ไม่รู้จัก จะแสดงเป็น Arial ขณะนี้เมธอด getFontFamily() และ setFontFamily(fontFamilyName) ใช้ชื่อสตริงสำหรับแบบอักษรแทน enum ของ FontFamily แม้ว่า Enum นี้จะ เลิกใช้งานแล้ว แต่จะยังเข้ากันได้กับสคริปต์เวอร์ชันเก่ากว่า

พารามิเตอร์

ชื่อประเภทคำอธิบาย
fontFamilyNameStringชื่อชุดแบบอักษรจากเมนูแบบอักษรในเอกสารหรือ Google Fonts

รีเทิร์น

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

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

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

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

setFontSize(startOffset, endOffsetInclusive, size)

ตั้งค่าขนาดแบบอักษรสำหรับช่วงอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the size of the first 11 characters in the tab's body to 12.
const text = body.editAsText().setFontSize(0, 10, 12);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerออฟเซ็ตเริ่มต้นของช่วงข้อความ
endOffsetInclusiveIntegerออฟเซ็ตสิ้นสุดของช่วงข้อความ
sizeNumberขนาดแบบอักษร

รีเทิร์น

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

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

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

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

setFontSize(size)

ตั้งค่าขนาดแบบอักษร

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sizeNumberขนาดแบบอักษร

รีเทิร์น

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

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

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

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

setForegroundColor(startOffset, endOffsetInclusive, color)

กำหนดสีพื้นหน้าสำหรับช่วงอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the foreground color of the first 2 characters in the
// tab's body to hex color #FF0000.
const text = body.editAsText().setForegroundColor(0, 1, '#FF0000');

// Gets the foreground color for the second character in the tab's body.
const foregroundColor = text.getForegroundColor(1);

//  Logs the foreground color to the console.
console.log(foregroundColor);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerออฟเซ็ตเริ่มต้นของช่วงข้อความ
endOffsetInclusiveIntegerออฟเซ็ตสิ้นสุดของช่วงข้อความ
colorStringสีพื้นหน้า ซึ่งจัดรูปแบบตามรูปแบบ CSS (เช่น '#ffffff')

รีเทิร์น

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

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

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

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

setForegroundColor(color)

ตั้งค่าสีพื้นหน้า

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorStringสีพื้นหน้า ซึ่งจัดรูปแบบตามรูปแบบ CSS (เช่น '#ffffff')

รีเทิร์น

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

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

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

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

setItalic(italic)

ตั้งค่าตัวเอียง

พารามิเตอร์

ชื่อประเภทคำอธิบาย
italicBooleanการตั้งค่าตัวเอียง

รีเทิร์น

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

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

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

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

setItalic(startOffset, endOffsetInclusive, italic)

กำหนดการตั้งค่าตัวเอียงสำหรับช่วงอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to italic.
const text = body.editAsText().setItalic(0, 10, true);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerออฟเซ็ตเริ่มต้นของช่วงข้อความ
endOffsetInclusiveIntegerออฟเซ็ตสิ้นสุดของช่วงข้อความ
italicBooleanการตั้งค่าตัวเอียง

รีเทิร์น

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

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

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

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

setLinkUrl(startOffset, endOffsetInclusive, url)

ตั้งค่า URL ของลิงก์สำหรับช่วงอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Applies a link to the first 11 characters in the body.
const text = body.editAsText().setLinkUrl(0, 10, 'https://example.com');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerออฟเซ็ตเริ่มต้นของช่วงข้อความ
endOffsetInclusiveIntegerออฟเซ็ตสิ้นสุดของช่วงข้อความ
urlStringURL ของลิงก์

รีเทิร์น

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

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

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

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

setLinkUrl(url)

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

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

setStrikethrough(strikethrough)

กำหนดการตั้งค่าขีดทับ

พารามิเตอร์

ชื่อประเภทคำอธิบาย
strikethroughBooleanการตั้งค่าขีดทับ

รีเทิร์น

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

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

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

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

setStrikethrough(startOffset, endOffsetInclusive, strikethrough)

กำหนดการตั้งค่าขีดทับสำหรับช่วงอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to strikethrough.
const text = body.editAsText().setStrikethrough(0, 10, true);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerออฟเซ็ตเริ่มต้นของช่วงข้อความ
endOffsetInclusiveIntegerออฟเซ็ตสิ้นสุดของช่วงข้อความ
strikethroughBooleanการตั้งค่าขีดทับ

รีเทิร์น

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

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

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

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

setText(text)

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

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Replaces the contents of the body with the text, 'New body text.'
const text = body.editAsText().setText('New body text.');

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

setTextAlignment(startOffset, endOffsetInclusive, textAlignment)

ตั้งค่าการจัดข้อความสำหรับช่วงอักขระที่ระบุ ประเภทการตรวจสอบความสอดคล้องที่ใช้ได้มีดังนี้ DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPT และ DocumentApp.TextAlignment.SUPERSCRIPT

// Make the first character in the first paragraph of the active tab be superscript.
var documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
var text = documentTab.getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(0, 0, DocumentApp.TextAlignment.SUPERSCRIPT);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerออฟเซ็ตเริ่มต้นของช่วงอักขระ
endOffsetInclusiveIntegerออฟเซ็ตสิ้นสุดของช่วงอักขระ (รวม)
textAlignmentTextAlignmentประเภทการจัดข้อความที่จะใช้

รีเทิร์น

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

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

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

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

setUnderline(underline)

ตั้งค่าการขีดเส้นใต้

พารามิเตอร์

ชื่อประเภทคำอธิบาย
underlineBooleanการตั้งค่าการขีดเส้นใต้

รีเทิร์น

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

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

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

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

setUnderline(startOffset, endOffsetInclusive, underline)

ตั้งค่าการขีดเส้นใต้สำหรับช่วงอักขระที่ระบุ

// Opens the Docs file by its URL. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the URL with your own.
const doc = DocumentApp.openByUrl('https://docs.google.com/document/d/DOCUMENT_ID/edit');

// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab(TAB_ID).asDocumentTab().getBody();

// Sets the first 11 characters in the tab's body to underline.
const text = body.editAsText().setUnderline(0, 10, true);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startOffsetIntegerออฟเซ็ตเริ่มต้นของช่วงข้อความ
endOffsetInclusiveIntegerออฟเซ็ตสิ้นสุดของช่วงข้อความ
underlineBooleanการตั้งค่าการขีดเส้นใต้

รีเทิร์น

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

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

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

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