Class Text

Teks

Elemen yang merepresentasikan wilayah rich text. Semua teks dalam Document terdapat dalam elemen Text. Elemen Text dapat dimuat di dalam Equation, EquationFunction, ListItem, atau Paragraph, tetapi tidak boleh berisi elemen lain. Untuk informasi selengkapnya tentang struktur dokumen, lihat panduan untuk memperluas Google Dokumen.

var body = DocumentApp.getActiveDocument().getBody();

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

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

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

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

Metode

MetodeJenis hasil yang ditampilkanDeskripsi singkat
appendText(text)TextMenambahkan teks yang ditentukan ke akhir area teks ini.
copy()TextMenampilkan salinan mendalam dan terpisah dari elemen saat ini.
deleteText(startOffset, endOffsetInclusive)TextMenghapus rentang teks.
editAsText()TextMendapatkan versi Text elemen saat ini, untuk diedit.
findText(searchPattern)RangeElementMenelusuri konten elemen untuk pola teks yang ditentukan menggunakan ekspresi reguler.
findText(searchPattern, from)RangeElementMenelusuri konten elemen untuk pola teks yang ditentukan, mulai dari hasil penelusuran tertentu.
getAttributes()ObjectMengambil atribut elemen.
getAttributes(offset)ObjectMengambil atribut pada offset karakter yang ditentukan.
getBackgroundColor()StringMengambil setelan warna latar belakang.
getBackgroundColor(offset)StringMengambil warna latar belakang pada offset karakter yang ditentukan.
getFontFamily()StringMengambil setelan jenis font.
getFontFamily(offset)StringMengambil jenis font pada offset karakter yang ditentukan.
getFontSize()NumberMengambil setelan ukuran font.
getFontSize(offset)NumberMengambil ukuran font pada offset karakter yang ditentukan.
getForegroundColor()StringMengambil setelan warna latar depan.
getForegroundColor(offset)StringMengambil warna latar depan pada offset karakter yang ditentukan.
getLinkUrl()StringMengambil URL link.
getLinkUrl(offset)StringMengambil URL link pada offset karakter yang ditentukan.
getNextSibling()ElementMengambil elemen seinduk elemen berikutnya.
getParent()ContainerElementMengambil elemen induk elemen.
getPreviousSibling()ElementMengambil elemen seinduk elemen sebelumnya.
getText()StringMengambil konten elemen sebagai string teks.
getTextAlignment()TextAlignmentMendapatkan perataan teks.
getTextAlignment(offset)TextAlignmentMendapatkan perataan teks untuk satu karakter.
getTextAttributeIndices()Integer[]Mengambil kumpulan indeks teks yang sesuai dengan awal proses pemformatan teks yang berbeda.
getType()ElementTypeMengambil ElementType elemen.
insertText(offset, text)TextMenyisipkan teks yang ditentukan pada offset karakter yang ditentukan.
isAtDocumentEnd()BooleanMenentukan apakah elemen berada di akhir Document.
isBold()BooleanMengambil setelan tebal.
isBold(offset)BooleanMengambil setelan tebal pada offset karakter yang ditentukan.
isItalic()BooleanMengambil setelan miring.
isItalic(offset)BooleanMengambil setelan miring pada offset karakter yang ditentukan.
isStrikethrough()BooleanMengambil setelan coretan.
isStrikethrough(offset)BooleanMengambil setelan coretan pada offset karakter yang ditentukan.
isUnderline()BooleanMengambil setelan garis bawah.
isUnderline(offset)BooleanMengambil setelan garis bawah pada offset karakter yang ditentukan.
merge()TextMenggabungkan elemen dengan kerabat sebelumnya dari jenis yang sama.
removeFromParent()TextMenghapus elemen dari induknya.
replaceText(searchPattern, replacement)ElementMenggantikan semua kemunculan pola teks tertentu dengan string pengganti tertentu menggunakan ekspresi reguler.
setAttributes(startOffset, endOffsetInclusive, attributes)TextMenerapkan atribut yang ditentukan ke rentang karakter tertentu.
setAttributes(attributes)TextMenetapkan atribut elemen.
setBackgroundColor(startOffset, endOffsetInclusive, color)TextMenetapkan warna latar belakang untuk rentang karakter yang ditentukan.
setBackgroundColor(color)TextMenetapkan warna latar belakang.
setBold(bold)TextMenetapkan setelan tebal.
setBold(startOffset, endOffsetInclusive, bold)TextMenetapkan setelan tebal untuk rentang karakter yang ditentukan.
setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)TextMenetapkan jenis font untuk rentang karakter yang ditentukan.
setFontFamily(fontFamilyName)TextMenetapkan jenis font.
setFontSize(startOffset, endOffsetInclusive, size)TextMenetapkan ukuran font untuk rentang karakter yang ditentukan.
setFontSize(size)TextMenetapkan ukuran font.
setForegroundColor(startOffset, endOffsetInclusive, color)TextMenetapkan warna latar depan untuk rentang karakter yang ditentukan.
setForegroundColor(color)TextMenetapkan warna latar depan.
setItalic(italic)TextMenetapkan setelan miring.
setItalic(startOffset, endOffsetInclusive, italic)TextMenetapkan setelan miring untuk rentang karakter yang ditentukan.
setLinkUrl(startOffset, endOffsetInclusive, url)TextMenetapkan URL link untuk rentang karakter yang ditentukan.
setLinkUrl(url)TextMenetapkan URL link.
setStrikethrough(strikethrough)TextMenetapkan setelan coretan.
setStrikethrough(startOffset, endOffsetInclusive, strikethrough)TextMenetapkan setelan coretan untuk rentang karakter yang ditentukan.
setText(text)TextMenetapkan konten teks.
setTextAlignment(startOffset, endOffsetInclusive, textAlignment)TextMenetapkan perataan teks untuk rentang karakter tertentu.
setTextAlignment(textAlignment)TextMenetapkan perataan teks.
setUnderline(underline)TextMenetapkan setelan garis bawah.
setUnderline(startOffset, endOffsetInclusive, underline)TextMenetapkan setelan garis bawah untuk rentang karakter yang ditentukan.

Dokumentasi mendetail

appendText(text)

Menambahkan teks yang ditentukan ke akhir area teks ini.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
textStringTeks yang akan ditambahkan.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

copy()

Menampilkan salinan mendalam dan terpisah dari elemen saat ini.

Semua elemen turunan yang ada dalam elemen tersebut juga akan disalin. Elemen baru tidak memiliki induk.

Pulang pergi

Text — Salinan baru.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

deleteText(startOffset, endOffsetInclusive)

Menghapus rentang teks.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset karakter dari karakter pertama yang akan dihapus.
endOffsetInclusiveIntegerOffset karakter pada karakter terakhir yang akan dihapus.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

editAsText()

Mendapatkan versi Text elemen saat ini, untuk diedit.

Gunakan editAsText untuk memanipulasi konten elemen sebagai rich text. Mode editAsText mengabaikan elemen non-teks (seperti InlineImage dan HorizontalRule).

Elemen turunan yang sepenuhnya terdapat dalam rentang teks yang dihapus akan dihapus dari elemen.

var body = DocumentApp.getActiveDocument().getBody();

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

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

Pulang pergi

Text — versi teks dari elemen saat ini


findText(searchPattern)

Menelusuri konten elemen untuk pola teks yang ditentukan menggunakan ekspresi reguler.

Subset fitur ekspresi reguler JavaScript tidak sepenuhnya didukung, seperti grup tangkapan dan pengubah mode.

Pola ekspresi reguler yang disediakan dicocokkan secara independen dengan setiap blok teks yang terdapat dalam elemen saat ini.

Parameter

NamaJenisDeskripsi
searchPatternStringpola untuk menelusuri

Pulang pergi

RangeElement — hasil penelusuran yang menunjukkan posisi teks penelusuran, atau null jika tidak ada kecocokan

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

findText(searchPattern, from)

Menelusuri konten elemen untuk pola teks yang ditentukan, mulai dari hasil penelusuran tertentu.

Subset fitur ekspresi reguler JavaScript tidak sepenuhnya didukung, seperti grup tangkapan dan pengubah mode.

Pola ekspresi reguler yang disediakan dicocokkan secara independen dengan setiap blok teks yang terdapat dalam elemen saat ini.

Parameter

NamaJenisDeskripsi
searchPatternStringpola untuk menelusuri
fromRangeElementhasil penelusuran untuk menelusuri dari

Pulang pergi

RangeElement — hasil penelusuran yang menunjukkan posisi teks penelusuran berikutnya, atau null jika tidak ada kecocokan

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getAttributes()

Mengambil atribut elemen.

Hasilnya adalah objek yang berisi properti untuk setiap atribut elemen yang valid, dengan setiap nama properti yang sesuai dengan item di enumerasi DocumentApp.Attribute.

var body = DocumentApp.getActiveDocument().getBody();

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

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

// Log the paragraph attributes.
for (var att in atts) {
  Logger.log(att + ":" + atts[att]);
}

Pulang pergi

Object — Atribut elemen.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getAttributes(offset)

Mengambil atribut pada offset karakter yang ditentukan.

Hasilnya adalah objek yang berisi properti untuk setiap atribut teks yang valid, dengan setiap nama properti yang sesuai dengan item di enumerasi 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/abc123456/edit');

// Gets the document body.
const body = doc.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 document 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);

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter.

Pulang pergi

Object — Atribut elemen.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getBackgroundColor()

Mengambil setelan warna latar belakang.

Pulang pergi

String — warna latar belakang, yang diformat dalam notasi CSS (seperti '#ffffff'), atau null jika elemen berisi beberapa nilai untuk atribut ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getBackgroundColor(offset)

Mengambil warna latar belakang pada offset karakter yang ditentukan.

// 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/abc123456');

// Gets the document body.
const body = doc.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);

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter.

Pulang pergi

String — Warna latar belakang, yang diformat dalam notasi CSS (seperti '#ffffff').

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getFontFamily()

Mengambil setelan jenis font. Nama dapat berupa font apa pun dari menu Font di Dokumen atau Google Fonts, dan peka huruf besar/kecil. Metode getFontFamily() dan setFontFamily(fontFamilyName) kini menggunakan nama string untuk font, bukan enum FontFamily. Meskipun tidak digunakan lagi, enum ini akan tetap tersedia untuk kompatibilitas dengan skrip lama.

Pulang pergi

String — jenis font, atau null jika elemen berisi beberapa nilai untuk atribut ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getFontFamily(offset)

Mengambil jenis font pada offset karakter yang ditentukan. Nama dapat berupa font apa pun dari menu Font di Dokumen atau Google Fonts, dan peka huruf besar/kecil. Metode getFontFamily() dan setFontFamily(fontFamilyName) kini menggunakan nama string untuk font, bukan enum FontFamily. Meskipun tidak digunakan lagi, enum ini akan tetap tersedia untuk kompatibilitas dengan skrip lama.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.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 document body.
const fontFamily = text.getFontFamily(15);

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

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter.

Pulang pergi

String — Jenis font.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getFontSize()

Mengambil setelan ukuran font.

Pulang pergi

Number — ukuran font, atau null jika elemen berisi beberapa nilai untuk atribut ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getFontSize(offset)

Mengambil ukuran font pada offset karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.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);

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter.

Pulang pergi

Number — Ukuran font.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getForegroundColor()

Mengambil setelan warna latar depan.

Pulang pergi

String — warna latar depan, yang diformat dalam notasi CSS (seperti '#ffffff'), atau null jika elemen berisi beberapa nilai untuk atribut ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getForegroundColor(offset)

Mengambil warna latar depan pada offset karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

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

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter.

Pulang pergi

String — Warna latar depan, yang diformat dalam notasi CSS (seperti '#ffffff').

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getLinkUrl()

Mengambil URL link.

Pulang pergi

String — URL link, atau null jika elemen berisi beberapa nilai untuk atribut ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getLinkUrl(offset)

Mengambil URL link pada offset karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.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);

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter.

Pulang pergi

String — URL link.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getNextSibling()

Mengambil elemen seinduk elemen berikutnya.

Saudara kandung berikutnya memiliki induk yang sama dan mengikuti elemen saat ini.

Pulang pergi

Element — Elemen pasangan berikutnya.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getParent()

Mengambil elemen induk elemen.

Elemen induk berisi elemen saat ini.

Pulang pergi

ContainerElement — Elemen induk.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getPreviousSibling()

Mengambil elemen seinduk elemen sebelumnya.

Saudara sebelumnya memiliki induk yang sama dan mendahului elemen saat ini.

Pulang pergi

Element — Elemen sibling sebelumnya.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getText()

Mengambil konten elemen sebagai string teks.

Pulang pergi

String — konten elemen sebagai string teks

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getTextAlignment()

Mendapatkan perataan teks. Jenis perataan yang tersedia adalah DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPT, dan DocumentApp.TextAlignment.SUPERSCRIPT.

Pulang pergi

TextAlignment — jenis perataan teks, atau null jika teks berisi beberapa jenis perataan teks atau jika perataan teks belum pernah ditetapkan

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getTextAlignment(offset)

Mendapatkan perataan teks untuk satu karakter. Jenis perataan yang tersedia adalah DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPT, dan 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Sets the text alignment of the document 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());

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter.

Pulang pergi

TextAlignment — Jenis perataan teks, atau null jika perataan teks belum pernah ditetapkan.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getTextAttributeIndices()

Mengambil kumpulan indeks teks yang sesuai dengan awal proses pemformatan teks yang berbeda.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.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());

Pulang pergi

Integer[] — Kumpulan indeks teks yang format teksnya berubah.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

getType()

Mengambil ElementType elemen.

Gunakan getType() untuk menentukan jenis yang tepat dari elemen yang diberikan.

var body = DocumentApp.getActiveDocument().getBody();

// Obtain the first element in the document body.

var firstChild = body.getChild(0);

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

Pulang pergi

ElementType — Jenis elemen.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

insertText(offset, text)

Menyisipkan teks yang ditentukan pada offset karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter untuk menyisipkan teks.
textStringTeks yang akan disisipkan.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

isAtDocumentEnd()

Menentukan apakah elemen berada di akhir Document.

Pulang pergi

Boolean — Apakah elemen berada di akhir dokumen.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

isBold()

Mengambil setelan tebal.

Pulang pergi

Boolean — apakah teksnya dicetak tebal, atau null jika elemen berisi beberapa nilai untuk atribut ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

isBold(offset)

Mengambil setelan tebal pada offset karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

// Bolds the first 4 characters in the document 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);

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter.

Pulang pergi

Boolean — Setelan tebal.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

isItalic()

Mengambil setelan miring.

Pulang pergi

Boolean — apakah teks dicetak miring, atau null jika elemen berisi beberapa nilai untuk atribut ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

isItalic(offset)

Mengambil setelan miring pada offset karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter.

Pulang pergi

Boolean — Setelan miring.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

isStrikethrough()

Mengambil setelan coretan.

Pulang pergi

Boolean — apakah teks dicoret, atau null jika elemen berisi beberapa nilai untuk atribut ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

isStrikethrough(offset)

Mengambil setelan coretan pada offset karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter.

Pulang pergi

Boolean — Setelan coretan.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

isUnderline()

Mengambil setelan garis bawah.

Pulang pergi

Boolean — apakah teks digarisbawahi, atau null jika elemen berisi beberapa nilai untuk atribut ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

isUnderline(offset)

Mengambil setelan garis bawah pada offset karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

Parameter

NamaJenisDeskripsi
offsetIntegerOffset karakter.

Pulang pergi

Boolean — Setelan garis bawah.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

merge()

Menggabungkan elemen dengan kerabat sebelumnya dari jenis yang sama.

Hanya elemen dengan ElementType yang sama yang dapat digabungkan. Setiap elemen turunan yang terdapat dalam elemen saat ini akan dipindahkan ke elemen yang setara sebelumnya.

Elemen saat ini dihapus dari dokumen.

var body = DocumentApp.getActiveDocument().getBody();
// Example 1: Merge paragraphs
// Append two paragraphs to the document.
var par1 = body.appendParagraph('Paragraph 1.');
var par2 = body.appendParagraph('Paragraph 2.');
// Merge the newly added paragraphs into a single paragraph.
par2.merge();

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

Pulang pergi

Text — Elemen yang digabungkan.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

removeFromParent()

Menghapus elemen dari induknya.

var body = DocumentApp.getActiveDocument().getBody();

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

Pulang pergi

Text — Elemen yang dihapus.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

replaceText(searchPattern, replacement)

Menggantikan semua kemunculan pola teks tertentu dengan string pengganti tertentu menggunakan ekspresi reguler.

Pola penelusuran diteruskan sebagai string, bukan objek ekspresi reguler JavaScript. Karena itu, Anda harus meng-escape garis miring terbalik dalam pola.

Metode ini menggunakan library ekspresi reguler RE2 Google, yang membatasi sintaksis yang didukung.

Pola ekspresi reguler yang disediakan dicocokkan secara independen dengan setiap blok teks yang terdapat dalam elemen saat ini.

var body = DocumentApp.getActiveDocument().getBody();

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

Parameter

NamaJenisDeskripsi
searchPatternStringpola ekspresi reguler yang akan ditelusuri
replacementStringteks yang akan digunakan sebagai pengganti

Pulang pergi

Element — elemen saat ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setAttributes(startOffset, endOffsetInclusive, attributes)

Menerapkan atribut yang ditentukan ke rentang karakter tertentu.

Parameter atribut yang ditentukan harus berupa objek dengan setiap nama properti adalah item dalam enumerasi DocumentApp.Attribute dan setiap nilai properti adalah nilai baru yang akan diterapkan.

// 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/abc123456/edit');

// Gets the document body and edits as text.
const body = doc.getBody().editAsText();

// 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 document body.
const text = body.setAttributes(0, 8, style);

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset awal rentang teks.
endOffsetInclusiveIntegerOffset akhir rentang teks.
attributesObjectAtribut elemen.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setAttributes(attributes)

Menetapkan atribut elemen.

Parameter atribut yang ditentukan harus berupa objek dengan setiap nama properti adalah item dalam enumerasi DocumentApp.Attribute dan setiap nilai properti adalah nilai baru yang akan diterapkan.

var body = DocumentApp.getActiveDocument().getBody();

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

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

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

Parameter

NamaJenisDeskripsi
attributesObjectAtribut elemen.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setBackgroundColor(startOffset, endOffsetInclusive, color)

Menetapkan warna latar belakang untuk rentang karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset awal rentang teks.
endOffsetInclusiveIntegerOffset akhir rentang teks.
colorStringWarna latar belakang, diformat dalam notasi CSS (seperti '#ffffff').

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setBackgroundColor(color)

Menetapkan warna latar belakang.

Parameter

NamaJenisDeskripsi
colorStringwarna latar belakang, yang diformat dalam notasi CSS (seperti '#ffffff')

Pulang pergi

Text — elemen saat ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setBold(bold)

Menetapkan setelan tebal.

Parameter

NamaJenisDeskripsi
boldBooleansetelan tebal

Pulang pergi

Text — elemen saat ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setBold(startOffset, endOffsetInclusive, bold)

Menetapkan setelan tebal untuk rentang karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset awal rentang teks.
endOffsetInclusiveIntegerOffset akhir rentang teks.
boldBooleanSetelan tebal.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setFontFamily(startOffset, endOffsetInclusive, fontFamilyName)

Menetapkan jenis font untuk rentang karakter yang ditentukan. Nama dapat berupa font apa pun dari menu Font di Dokumen atau Google Fonts, dan peka huruf besar/kecil. Nama font yang tidak dikenal akan dirender sebagai Arial. Metode getFontFamily(offset) dan setFontFamily(fontFamilyName) kini menggunakan nama string untuk font, bukan enum FontFamily. Meskipun tidak digunakan lagi, enum ini akan tetap tersedia untuk kompatibilitas dengan skrip lama.

// 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/abc123456/edit');

// Gets body of the document.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset awal rentang teks.
endOffsetInclusiveIntegerOffset akhir rentang teks.
fontFamilyNameStringNama jenis font, dari menu Font di Dokumen atau Google Fonts.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setFontFamily(fontFamilyName)

Menetapkan jenis font. Nama dapat berupa font apa pun dari menu Font di Dokumen atau Google Fonts, dan peka huruf besar/kecil. Nama font yang tidak dikenal akan dirender sebagai Arial. Metode getFontFamily() dan setFontFamily(fontFamilyName) kini menggunakan nama string untuk font, bukan enum FontFamily. Meskipun tidak digunakan lagi, enum ini akan tetap tersedia untuk kompatibilitas dengan skrip lama.

Parameter

NamaJenisDeskripsi
fontFamilyNameStringnama jenis font, dari menu Font di Dokumen atau Google Fonts

Pulang pergi

Text — elemen saat ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setFontSize(startOffset, endOffsetInclusive, size)

Menetapkan ukuran font untuk rentang karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset awal rentang teks.
endOffsetInclusiveIntegerOffset akhir rentang teks.
sizeNumberUkuran font.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setFontSize(size)

Menetapkan ukuran font.

Parameter

NamaJenisDeskripsi
sizeNumberukuran font

Pulang pergi

Text — elemen saat ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setForegroundColor(startOffset, endOffsetInclusive, color)

Menetapkan warna latar depan untuk rentang karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

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

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

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset awal rentang teks.
endOffsetInclusiveIntegerOffset akhir rentang teks.
colorStringWarna latar depan, diformat dalam notasi CSS (seperti '#ffffff').

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setForegroundColor(color)

Menetapkan warna latar depan.

Parameter

NamaJenisDeskripsi
colorStringwarna latar depan, yang diformat dalam notasi CSS (seperti '#ffffff')

Pulang pergi

Text — elemen saat ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setItalic(italic)

Menetapkan setelan miring.

Parameter

NamaJenisDeskripsi
italicBooleansetelan miring

Pulang pergi

Text — elemen saat ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setItalic(startOffset, endOffsetInclusive, italic)

Menetapkan setelan miring untuk rentang karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset awal rentang teks.
endOffsetInclusiveIntegerOffset akhir rentang teks.
italicBooleanSetelan miring.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setLinkUrl(startOffset, endOffsetInclusive, url)

Menetapkan URL link untuk rentang karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset awal rentang teks.
endOffsetInclusiveIntegerOffset akhir rentang teks.
urlStringURL link.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setLinkUrl(url)

Menetapkan URL link.

Parameter

NamaJenisDeskripsi
urlStringURL link

Pulang pergi

Text — elemen saat ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setStrikethrough(strikethrough)

Menetapkan setelan coretan.

Parameter

NamaJenisDeskripsi
strikethroughBooleansetelan coretan

Pulang pergi

Text — elemen saat ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setStrikethrough(startOffset, endOffsetInclusive, strikethrough)

Menetapkan setelan coretan untuk rentang karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset awal rentang teks.
endOffsetInclusiveIntegerOffset akhir rentang teks.
strikethroughBooleanSetelan coret.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setText(text)

Menetapkan konten teks.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
textStringKonten teks baru.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setTextAlignment(startOffset, endOffsetInclusive, textAlignment)

Menetapkan perataan teks untuk rentang karakter tertentu. Jenis penyelarasan yang tersedia adalah DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPT, dan DocumentApp.TextAlignment.SUPERSCRIPT.

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

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset awal rentang karakter.
endOffsetInclusiveIntegerOffset akhir rentang karakter (inklusif).
textAlignmentTextAlignmentJenis perataan teks yang akan diterapkan.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setTextAlignment(textAlignment)

Menetapkan perataan teks. Jenis perataan yang tersedia adalah DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPT, dan DocumentApp.TextAlignment.SUPERSCRIPT.

// Make the entire first paragraph be superscript.
var text = DocumentApp.getActiveDocument().getBody().getParagraphs()[0].editAsText();
text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);

Parameter

NamaJenisDeskripsi
textAlignmentTextAlignmentjenis perataan teks yang akan diterapkan

Pulang pergi

Text — elemen saat ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setUnderline(underline)

Menetapkan setelan garis bawah.

Parameter

NamaJenisDeskripsi
underlineBooleansetelan garis bawah

Pulang pergi

Text — elemen saat ini

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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

setUnderline(startOffset, endOffsetInclusive, underline)

Menetapkan setelan garis bawah untuk rentang karakter yang ditentukan.

// 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/abc123456/edit');

// Gets the document body.
const body = doc.getBody();

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

Parameter

NamaJenisDeskripsi
startOffsetIntegerOffset awal rentang teks.
endOffsetInclusiveIntegerOffset akhir rentang teks.
underlineBooleanSetelan garis bawah.

Pulang pergi

Text — Elemen saat ini.

Otorisasi

Skrip yang menggunakan metode ini memerlukan otorisasi dengan satu atau beberapa cakupan berikut:

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