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
Metode | Jenis hasil yang ditampilkan | Deskripsi singkat |
---|---|---|
appendText(text) | Text | Menambahkan teks yang ditentukan ke akhir area teks ini. |
copy() | Text | Menampilkan salinan mendalam dan terpisah dari elemen saat ini. |
deleteText(startOffset, endOffsetInclusive) | Text | Menghapus rentang teks. |
editAsText() | Text | Mendapatkan versi Text elemen saat ini, untuk diedit. |
findText(searchPattern) | RangeElement | Menelusuri konten elemen untuk pola teks yang ditentukan menggunakan ekspresi reguler. |
findText(searchPattern, from) | RangeElement | Menelusuri konten elemen untuk pola teks yang ditentukan, mulai dari hasil penelusuran tertentu. |
getAttributes() | Object | Mengambil atribut elemen. |
getAttributes(offset) | Object | Mengambil atribut pada offset karakter yang ditentukan. |
getBackgroundColor() | String | Mengambil setelan warna latar belakang. |
getBackgroundColor(offset) | String | Mengambil warna latar belakang pada offset karakter yang ditentukan. |
getFontFamily() | String | Mengambil setelan jenis font. |
getFontFamily(offset) | String | Mengambil jenis font pada offset karakter yang ditentukan. |
getFontSize() | Number | Mengambil setelan ukuran font. |
getFontSize(offset) | Number | Mengambil ukuran font pada offset karakter yang ditentukan. |
getForegroundColor() | String | Mengambil setelan warna latar depan. |
getForegroundColor(offset) | String | Mengambil warna latar depan pada offset karakter yang ditentukan. |
getLinkUrl() | String | Mengambil URL link. |
getLinkUrl(offset) | String | Mengambil URL link pada offset karakter yang ditentukan. |
getNextSibling() | Element | Mengambil elemen seinduk elemen berikutnya. |
getParent() | ContainerElement | Mengambil elemen induk elemen. |
getPreviousSibling() | Element | Mengambil elemen seinduk elemen sebelumnya. |
getText() | String | Mengambil konten elemen sebagai string teks. |
getTextAlignment() | TextAlignment | Mendapatkan perataan teks. |
getTextAlignment(offset) | TextAlignment | Mendapatkan perataan teks untuk satu karakter. |
getTextAttributeIndices() | Integer[] | Mengambil kumpulan indeks teks yang sesuai dengan awal proses pemformatan teks yang berbeda. |
getType() | ElementType | Mengambil ElementType elemen. |
insertText(offset, text) | Text | Menyisipkan teks yang ditentukan pada offset karakter yang ditentukan. |
isAtDocumentEnd() | Boolean | Menentukan apakah elemen berada di akhir Document . |
isBold() | Boolean | Mengambil setelan tebal. |
isBold(offset) | Boolean | Mengambil setelan tebal pada offset karakter yang ditentukan. |
isItalic() | Boolean | Mengambil setelan miring. |
isItalic(offset) | Boolean | Mengambil setelan miring pada offset karakter yang ditentukan. |
isStrikethrough() | Boolean | Mengambil setelan coretan. |
isStrikethrough(offset) | Boolean | Mengambil setelan coretan pada offset karakter yang ditentukan. |
isUnderline() | Boolean | Mengambil setelan garis bawah. |
isUnderline(offset) | Boolean | Mengambil setelan garis bawah pada offset karakter yang ditentukan. |
merge() | Text | Menggabungkan elemen dengan kerabat sebelumnya dari jenis yang sama. |
removeFromParent() | Text | Menghapus elemen dari induknya. |
replaceText(searchPattern, replacement) | Element | Menggantikan semua kemunculan pola teks tertentu dengan string pengganti tertentu menggunakan ekspresi reguler. |
setAttributes(startOffset, endOffsetInclusive, attributes) | Text | Menerapkan atribut yang ditentukan ke rentang karakter tertentu. |
setAttributes(attributes) | Text | Menetapkan atribut elemen. |
setBackgroundColor(startOffset, endOffsetInclusive, color) | Text | Menetapkan warna latar belakang untuk rentang karakter yang ditentukan. |
setBackgroundColor(color) | Text | Menetapkan warna latar belakang. |
setBold(bold) | Text | Menetapkan setelan tebal. |
setBold(startOffset, endOffsetInclusive, bold) | Text | Menetapkan setelan tebal untuk rentang karakter yang ditentukan. |
setFontFamily(startOffset, endOffsetInclusive, fontFamilyName) | Text | Menetapkan jenis font untuk rentang karakter yang ditentukan. |
setFontFamily(fontFamilyName) | Text | Menetapkan jenis font. |
setFontSize(startOffset, endOffsetInclusive, size) | Text | Menetapkan ukuran font untuk rentang karakter yang ditentukan. |
setFontSize(size) | Text | Menetapkan ukuran font. |
setForegroundColor(startOffset, endOffsetInclusive, color) | Text | Menetapkan warna latar depan untuk rentang karakter yang ditentukan. |
setForegroundColor(color) | Text | Menetapkan warna latar depan. |
setItalic(italic) | Text | Menetapkan setelan miring. |
setItalic(startOffset, endOffsetInclusive, italic) | Text | Menetapkan setelan miring untuk rentang karakter yang ditentukan. |
setLinkUrl(startOffset, endOffsetInclusive, url) | Text | Menetapkan URL link untuk rentang karakter yang ditentukan. |
setLinkUrl(url) | Text | Menetapkan URL link. |
setStrikethrough(strikethrough) | Text | Menetapkan setelan coretan. |
setStrikethrough(startOffset, endOffsetInclusive, strikethrough) | Text | Menetapkan setelan coretan untuk rentang karakter yang ditentukan. |
setText(text) | Text | Menetapkan konten teks. |
setTextAlignment(startOffset, endOffsetInclusive, textAlignment) | Text | Menetapkan perataan teks untuk rentang karakter tertentu. |
setTextAlignment(textAlignment) | Text | Menetapkan perataan teks. |
setUnderline(underline) | Text | Menetapkan setelan garis bawah. |
setUnderline(startOffset, endOffsetInclusive, underline) | Text | Menetapkan 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
Nama | Jenis | Deskripsi |
---|---|---|
text | String | Teks 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset karakter dari karakter pertama yang akan dihapus. |
endOffsetInclusive | Integer | Offset 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
Nama | Jenis | Deskripsi |
---|---|---|
searchPattern | String | pola 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
Nama | Jenis | Deskripsi |
---|---|---|
searchPattern | String | pola untuk menelusuri |
from | RangeElement | hasil 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset 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
. Meskipun tidak digunakan lagi, enum ini akan tetap tersedia untuk kompatibilitas dengan skrip lama.FontFamily
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
. Meskipun tidak digunakan lagi, enum ini akan tetap tersedia untuk kompatibilitas dengan skrip lama.
FontFamily
// 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset karakter untuk menyisipkan teks. |
text | String | Teks 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset 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
Nama | Jenis | Deskripsi |
---|---|---|
offset | Integer | Offset 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
Nama | Jenis | Deskripsi |
---|---|---|
searchPattern | String | pola ekspresi reguler yang akan ditelusuri |
replacement | String | teks 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset awal rentang teks. |
endOffsetInclusive | Integer | Offset akhir rentang teks. |
attributes | Object | Atribut 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
Nama | Jenis | Deskripsi |
---|---|---|
attributes | Object | Atribut 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset awal rentang teks. |
endOffsetInclusive | Integer | Offset akhir rentang teks. |
color | String | Warna 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
Nama | Jenis | Deskripsi |
---|---|---|
color | String | warna 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
Nama | Jenis | Deskripsi |
---|---|---|
bold | Boolean | setelan 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset awal rentang teks. |
endOffsetInclusive | Integer | Offset akhir rentang teks. |
bold | Boolean | Setelan 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
. Meskipun tidak digunakan lagi, enum ini akan tetap tersedia untuk kompatibilitas dengan skrip lama.
FontFamily
// 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset awal rentang teks. |
endOffsetInclusive | Integer | Offset akhir rentang teks. |
fontFamilyName | String | Nama 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
. Meskipun tidak digunakan lagi, enum ini akan tetap tersedia untuk kompatibilitas dengan skrip lama.FontFamily
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
fontFamilyName | String | nama 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset awal rentang teks. |
endOffsetInclusive | Integer | Offset akhir rentang teks. |
size | Number | Ukuran 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
Nama | Jenis | Deskripsi |
---|---|---|
size | Number | ukuran 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset awal rentang teks. |
endOffsetInclusive | Integer | Offset akhir rentang teks. |
color | String | Warna 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
Nama | Jenis | Deskripsi |
---|---|---|
color | String | warna 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
Nama | Jenis | Deskripsi |
---|---|---|
italic | Boolean | setelan 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset awal rentang teks. |
endOffsetInclusive | Integer | Offset akhir rentang teks. |
italic | Boolean | Setelan 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset awal rentang teks. |
endOffsetInclusive | Integer | Offset akhir rentang teks. |
url | String | URL 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
Nama | Jenis | Deskripsi |
---|---|---|
url | String | URL 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
Nama | Jenis | Deskripsi |
---|---|---|
strikethrough | Boolean | setelan 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset awal rentang teks. |
endOffsetInclusive | Integer | Offset akhir rentang teks. |
strikethrough | Boolean | Setelan 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
Nama | Jenis | Deskripsi |
---|---|---|
text | String | Konten 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset awal rentang karakter. |
endOffsetInclusive | Integer | Offset akhir rentang karakter (inklusif). |
textAlignment | TextAlignment | Jenis 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
Nama | Jenis | Deskripsi |
---|---|---|
textAlignment | TextAlignment | jenis 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
Nama | Jenis | Deskripsi |
---|---|---|
underline | Boolean | setelan 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
Nama | Jenis | Deskripsi |
---|---|---|
startOffset | Integer | Offset awal rentang teks. |
endOffsetInclusive | Integer | Offset akhir rentang teks. |
underline | Boolean | Setelan 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