Class Text

Text

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

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

// Use editAsText to obtain a single text element containing
// all the characters in the tab.
const 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|nullค้นหารูปแบบข้อความที่ระบุในเนื้อหาขององค์ประกอบโดยใช้นิพจน์ทั่วไป
findText(searchPattern, from)RangeElement|nullค้นหารูปแบบข้อความที่ระบุในเนื้อหาขององค์ประกอบ โดยเริ่มจากผลการค้นหาที่ระบุ
getAttributes()Objectดึงแอตทริบิวต์ขององค์ประกอบ
getAttributes(offset)Objectดึงข้อมูลแอตทริบิวต์ที่ออฟเซ็ตอักขระที่ระบุ
getBackgroundColor()String|nullเรียกการตั้งค่าสีพื้นหลัง
getBackgroundColor(offset)String|nullเรียกข้อมูลสีพื้นหลังที่ออฟเซ็ตอักขระที่ระบุ
getFontFamily()String|nullดึงการตั้งค่าชุดแบบอักษร
getFontFamily(offset)String|nullดึงข้อมูลชุดแบบอักษรที่ออฟเซ็ตอักขระที่ระบุ
getFontSize()Number|nullดึงการตั้งค่าขนาดแบบอักษร
getFontSize(offset)Number|nullดึงข้อมูลขนาดแบบอักษรที่ออฟเซ็ตอักขระที่ระบุ
getForegroundColor()String|nullดึงข้อมูลการตั้งค่าสีด้านหน้า
getForegroundColor(offset)String|nullดึงสีด้านหน้าในออฟเซ็ตอักขระที่ระบุ
getLinkUrl()String|nullเรียก URL ของลิงก์
getLinkUrl(offset)String|nullดึง URL ของลิงก์ที่ออฟเซ็ตอักขระที่ระบุ
getNextSibling()Element|nullดึงองค์ประกอบพี่น้องถัดไปขององค์ประกอบ
getParent()ContainerElement|nullดึงองค์ประกอบหลักขององค์ประกอบ
getPreviousSibling()Element|nullดึงองค์ประกอบพี่น้องก่อนหน้าขององค์ประกอบ
getText()Stringดึงเนื้อหาขององค์ประกอบเป็นสตริงข้อความ
getTextAlignment()TextAlignment|nullรับการจัดข้อความ
getTextAlignment(offset)TextAlignment|nullรับการจัดข้อความสำหรับอักขระเดียว
getTextAttributeIndices()Integer[]ดึงข้อมูลชุดดัชนีข้อความที่สอดคล้องกับการเริ่มต้นของ การเรียกใช้การจัดรูปแบบข้อความที่แตกต่างกัน
getType()ElementTypeดึง ElementType ขององค์ประกอบ
insertText(offset, text)Textแทรกข้อความที่ระบุที่ออฟเซ็ตอักขระที่กำหนด
isAtDocumentEnd()Booleanกำหนดว่าองค์ประกอบอยู่ท้าย Document หรือไม่
isBold()Boolean|nullเรียกการตั้งค่าตัวหนา
isBold(offset)Boolean|nullดึงการตั้งค่าตัวหนาที่ออฟเซ็ตอักขระที่ระบุ
isItalic()Boolean|nullเรียกการตั้งค่าตัวเอียง
isItalic(offset)Boolean|nullดึงการตั้งค่าตัวเอียงที่ออฟเซ็ตอักขระที่ระบุ
isStrikethrough()Boolean|nullเรียกการตั้งค่าขีดทับ
isStrikethrough(offset)Boolean|nullดึงการตั้งค่าขีดทับที่ออฟเซ็ตอักขระที่ระบุ
isUnderline()Boolean|nullเรียกการตั้งค่าขีดเส้นใต้
isUnderline(offset)Boolean|nullดึงการตั้งค่าขีดเส้นใต้ที่ออฟเซ็ตอักขระที่ระบุ
merge()Text|nullผสานองค์ประกอบกับองค์ประกอบที่อยู่ก่อนหน้าซึ่งเป็นประเภทเดียวกัน
removeFromParent()Text|nullนำองค์ประกอบออกจากองค์ประกอบหลัก
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('123abc').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('123abc').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)

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

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

// Insert two paragraphs separated by a paragraph containing an
// horizontal rule.
body.insertParagraph(0, 'An editAsText sample.');
body.insertHorizontalRule(0);
body.insertParagraph(0, 'An example.');

// Delete " sample.\n\n An" removing the horizontal rule in the process.
body.editAsText().deleteText(14, 25);

รีเทิร์น

Text - ข้อความขององค์ประกอบปัจจุบัน


findText(searchPattern)

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

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

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

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

findText(searchPattern, from)

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

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

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

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

getAttributes()

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

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

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

// Append a styled paragraph.
const par = body.appendParagraph('A bold, italicized paragraph.');
par.setBold(true);
par.setItalic(true);

// Retrieve the paragraph's attributes.
const atts = par.getAttributes();

// Log the paragraph attributes.
for (const att in atts) {
  Logger.log(`${att}:${atts[att]}`);
}

รีเทิร์น

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

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

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

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

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('123abc').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|null - สีพื้นหลังที่จัดรูปแบบในสัญกรณ์ 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('123abc').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|null — สีพื้นหลังที่จัดรูปแบบในสัญกรณ์ CSS (เช่น '#ffffff')

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

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

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

getFontFamily()

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

รีเทิร์น

String|null - ตระกูลแบบอักษร หรือ null หากองค์ประกอบมีค่าหลายค่าสำหรับแอตทริบิวต์นี้

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

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

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

getFontFamily(offset)

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

// 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('123abc').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|null — ชุดแบบอักษร

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

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

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

getFontSize()

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

รีเทิร์น

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

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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('123abc').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|null — ขนาดแบบอักษร

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

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

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

getForegroundColor()

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

รีเทิร์น

String|null - สีพื้นหน้าซึ่งจัดรูปแบบในสัญกรณ์ 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('123abc').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|null — สีพื้นหน้าซึ่งจัดรูปแบบในรูปแบบสัญกรณ์ CSS (เช่น '#ffffff')

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

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

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

getLinkUrl()

เรียก URL ของลิงก์

รีเทิร์น

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

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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('123abc').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|null — URL ของลิงก์

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

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

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

getNextSibling()

ดึงองค์ประกอบพี่น้องถัดไปขององค์ประกอบ

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

รีเทิร์น

Element|null — องค์ประกอบร่วมถัดไป

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

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

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

getParent()

ดึงองค์ประกอบหลักขององค์ประกอบ

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

รีเทิร์น

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

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

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

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

getPreviousSibling()

ดึงองค์ประกอบพี่น้องก่อนหน้าขององค์ประกอบ

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

รีเทิร์น

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

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

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

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

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 — ประเภทการจัดแนวข้อความ หรือ 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('123abc').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 — ประเภทการจัดข้อความ หรือ 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('123abc').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() เพื่อระบุประเภทที่แน่นอนขององค์ประกอบที่กำหนด

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

// Obtain the first element in the active tab's body.

const firstChild = body.getChild(0);

// Use getType() to determine the element's type.
if (firstChild.getType() === DocumentApp.ElementType.PARAGRAPH) {
  Logger.log('The first element is a paragraph.');
} else {
  Logger.log('The first element is not a paragraph.');
}

รีเทิร์น

ElementType — ประเภทองค์ประกอบ

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

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

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

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('123abc').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 — ข้อความเป็นตัวหนาหรือไม่ หรือเป็น 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('123abc').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|null — การตั้งค่าตัวหนา

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

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

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

isItalic()

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

รีเทิร์น

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

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

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

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

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

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

isStrikethrough()

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

รีเทิร์น

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

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

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

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

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

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

isUnderline()

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

รีเทิร์น

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

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

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

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

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

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

merge()

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

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

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

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

// Example 1: Merge paragraphs
// Append two paragraphs to the document's active tab.
const par1 = body.appendParagraph('Paragraph 1.');
const par2 = body.appendParagraph('Paragraph 2.');
// Merge the newly added paragraphs into a single paragraph.
par2.merge();

// Example 2: Merge table cells
// Create a two-dimensional array containing the table's cell contents.
const cells = [
  ['Row 1, Cell 1', 'Row 1, Cell 2'],
  ['Row 2, Cell 1', 'Row 2, Cell 2'],
];
// Build a table from the array.
const table = body.appendTable(cells);
// Get the first row in the table.
const row = table.getRow(0);
// Get the two cells in this row.
const cell1 = row.getCell(0);
const cell2 = row.getCell(1);
// Merge the current cell into its preceding sibling element.
const merged = cell2.merge();

รีเทิร์น

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

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

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

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

removeFromParent()

นำองค์ประกอบออกจากองค์ประกอบหลัก

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

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

รีเทิร์น

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

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

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

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

replaceText(searchPattern, replacement)

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

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

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

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

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

// Clear the text surrounding "Apps Script", with or without text.
body.replaceText('^.*Apps ?Script.*$', 'Apps Script');

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

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('123abc').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 และค่าพร็อพเพอร์ตี้แต่ละรายการเป็นค่าใหม่ที่จะ ใช้

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

// Define a custom paragraph style.
const style = {};
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] =
    DocumentApp.HorizontalAlignment.RIGHT;
style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri';
style[DocumentApp.Attribute.FONT_SIZE] = 18;
style[DocumentApp.Attribute.BOLD] = true;

// Append a plain paragraph.
const par = body.appendParagraph('A paragraph with custom style.');

// Apply the custom style.
par.setAttributes(style);

พารามิเตอร์

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

รีเทิร์น

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('123abc').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('123abc').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) ใช้ชื่อสตริงสำหรับแบบอักษรแทน FontFamily enum แล้ว แม้ว่าระบบจะ เลิกใช้งาน</0x0A>การแจงนับนี้แล้ว แต่จะยังคงใช้งานได้เพื่อความเข้ากันได้กับสคริปต์รุ่นเก่า

// 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('123abc').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) ใช้ชื่อสตริงสำหรับแบบอักษรแทนการแจงนับ FontFamily แล้ว แม้ว่าระบบจะ เลิกใช้งาน</0x0A>การแจงนับนี้แล้ว แต่จะยังคงใช้งานได้เพื่อความเข้ากันได้กับสคริปต์รุ่นเก่า

พารามิเตอร์

ชื่อประเภทคำอธิบาย
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('123abc').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('123abc').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('123abc').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('123abc').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('123abc').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('123abc').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.
const documentTab =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
const 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.
const documentTab =
    DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
const 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('123abc').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