Elemen yang mewakili tabel. Table
hanya boleh berisi elemen TableRow
. Untuk mengetahui informasi selengkapnya tentang struktur dokumen, lihat panduan memperluas Google Dokumen.
Saat membuat Table
yang berisi baris atau sel dalam jumlah besar, sebaiknya Anda membuatnya
dari array string, seperti yang ditunjukkan pada contoh berikut.
var body = DocumentApp.getActiveDocument().getBody(); // Create a two-dimensional array containing the 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. body.appendTable(cells);
Metode
Metode | Jenis hasil yang ditampilkan | Deskripsi singkat |
---|---|---|
appendTableRow() | TableRow | Membuat dan menambahkan TableRow baru. |
appendTableRow(tableRow) | TableRow | Menambahkan TableRow yang ditentukan. |
clear() | Table | Menghapus konten elemen. |
copy() | Table | Menampilkan salinan mendalam dan terpisah dari elemen saat ini. |
editAsText() | Text | Mendapatkan versi Text dari elemen saat ini, untuk diedit. |
findElement(elementType) | RangeElement | Menelusuri konten elemen untuk turunan dari jenis yang ditentukan. |
findElement(elementType, from) | RangeElement | Menelusuri konten elemen untuk turunan dari jenis yang ditentukan, mulai dari RangeElement yang ditentukan. |
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. |
getBorderColor() | String | Mengambil warna batas. |
getBorderWidth() | Number | Mengambil lebar batas dalam poin. |
getCell(rowIndex, cellIndex) | TableCell | Mengambil TableCell pada indeks sel dan baris yang ditentukan. |
getChild(childIndex) | Element | Mengambil elemen turunan pada indeks turunan yang ditentukan. |
getChildIndex(child) | Integer | Mengambil indeks turunan untuk elemen turunan yang ditentukan. |
getColumnWidth(columnIndex) | Number | Mengambil lebar kolom tabel yang ditentukan, dalam poin. |
getLinkUrl() | String | Mengambil URL link. |
getNextSibling() | Element | Mengambil elemen seinduk elemen berikutnya. |
getNumChildren() | Integer | Mengambil jumlah turunan. |
getNumRows() | Integer | Mengambil jumlah TableRows . |
getParent() | ContainerElement | Mengambil elemen induk elemen. |
getPreviousSibling() | Element | Mengambil elemen seinduk elemen sebelumnya. |
getRow(rowIndex) | TableRow | Mengambil TableRow pada indeks baris yang ditentukan. |
getText() | String | Mengambil konten elemen sebagai string teks. |
getTextAlignment() | TextAlignment | Mendapatkan perataan teks. |
getType() | ElementType | Mengambil ElementType elemen. |
insertTableRow(childIndex) | TableRow | Membuat dan menyisipkan TableRow baru pada indeks yang ditentukan. |
insertTableRow(childIndex, tableRow) | TableRow | Menyisipkan TableRow yang ditentukan pada indeks yang ditentukan. |
isAtDocumentEnd() | Boolean | Menentukan apakah elemen berada di akhir Document . |
removeChild(child) | Table | Menghapus elemen turunan yang ditentukan. |
removeFromParent() | Table | Menghapus elemen dari induknya. |
removeRow(rowIndex) | TableRow | Menghapus TableRow pada indeks baris yang ditentukan. |
replaceText(searchPattern, replacement) | Element | Mengganti semua kemunculan pola teks tertentu dengan string pengganti tertentu, menggunakan ekspresi reguler. |
setAttributes(attributes) | Table | Menetapkan atribut elemen. |
setBorderColor(color) | Table | Menetapkan warna batas. |
setBorderWidth(width) | Table | Menetapkan lebar batas dalam titik. |
setColumnWidth(columnIndex, width) | Table | Menetapkan lebar kolom yang ditentukan, dalam titik. |
setLinkUrl(url) | Table | Menetapkan URL link. |
setTextAlignment(textAlignment) | Table | Menetapkan perataan teks. |
Dokumentasi mendetail
appendTableRow()
appendTableRow(tableRow)
Menambahkan TableRow
yang ditentukan.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first table in the document and copies the second row. const table = body.getTables()[0]; const row = table.getChild(1).copy(); // Adds the copied row to the bottom of the table. const tableRow = table.appendTableRow(row);
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
tableRow | TableRow | Baris tabel yang akan ditambahkan. |
Return
TableRow
— Elemen baris tabel yang ditambahkan.
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
clear()
copy()
Menampilkan salinan mendalam dan terpisah dari elemen saat ini.
Setiap elemen turunan yang ada dalam elemen juga akan disalin. Elemen baru ini tidak memiliki induk.
Return
Table
— 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
editAsText()
Mendapatkan versi Text
dari 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 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);
Return
Text
— versi teks dari elemen saat ini
findElement(elementType)
Menelusuri konten elemen untuk turunan dari jenis yang ditentukan.
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
elementType | ElementType | jenis elemen yang akan dicari |
Return
RangeElement
— hasil penelusuran yang menunjukkan posisi elemen penelusuran
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
findElement(elementType, from)
Menelusuri konten elemen untuk turunan dari jenis yang ditentukan, mulai dari RangeElement
yang ditentukan.
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Define the search parameters. var searchType = DocumentApp.ElementType.PARAGRAPH; var searchHeading = DocumentApp.ParagraphHeading.HEADING1; var searchResult = null; // Search until the paragraph is found. while (searchResult = body.findElement(searchType, searchResult)) { var par = searchResult.getElement().asParagraph(); if (par.getHeading() == searchHeading) { // Found one, update and stop. par.setText('This is the first header.'); return; } }
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
elementType | ElementType | jenis elemen yang akan dicari |
from | RangeElement | hasil penelusuran untuk mencari |
Return
RangeElement
— hasil penelusuran yang menunjukkan posisi berikutnya dari elemen penelusuran
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)
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 mencari |
Return
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 mencari |
from | RangeElement | hasil penelusuran untuk mencari |
Return
RangeElement
— hasil penelusuran yang menunjukkan posisi berikutnya dari 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
getAttributes()
Mengambil atribut elemen.
Hasilnya adalah objek yang berisi properti untuk setiap atribut elemen yang valid, dengan setiap nama properti sesuai dengan item dalam 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]); }
Return
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
getBorderColor()
Mengambil warna batas.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first table. const table = body.getTables()[0]; // Sets the border color of the first table. table.setBorderColor('#00FF00'); // Logs the border color of the first table to the console. console.log(table.getBorderColor());
Return
String
— Warna batas, 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
getBorderWidth()
Mengambil lebar batas dalam poin.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first table. const table = body.getTables()[0]; // Sets the border width of the first table. table.setBorderWidth(20); // Logs the border width of the first table. console.log(table.getBorderWidth());
Return
Number
— Lebar batas, dalam poin.
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
getCell(rowIndex, cellIndex)
Mengambil TableCell
pada indeks sel dan baris yang ditentukan.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first table. const table = body.getTables()[0]; // Gets the cell of the table's third row and second column. const cell = table.getCell(2, 1); // Logs the cell text to the console. console.log(cell.getText());
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
rowIndex | Integer | Indeks baris yang berisi sel yang akan diambil. |
cellIndex | Integer | Indeks sel yang akan diambil. |
Return
TableCell
— Sel tabel.
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
getChild(childIndex)
Mengambil elemen turunan pada indeks turunan yang ditentukan.
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Obtain the first element in the document. var firstChild = body.getChild(0); // If it's a paragraph, set its contents. if (firstChild.getType() == DocumentApp.ElementType.PARAGRAPH) { firstChild.asParagraph().setText("This is the first paragraph."); }
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
childIndex | Integer | indeks elemen turunan untuk mengambil |
Return
Element
— elemen turunan pada indeks yang ditentukan
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
getChildIndex(child)
Mengambil indeks turunan untuk elemen turunan yang ditentukan.
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
child | Element | elemen turunan untuk mengambil indeks |
Return
Integer
— indeks turunan
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
getColumnWidth(columnIndex)
Mengambil lebar kolom tabel yang ditentukan, dalam poin.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first table. const table = body.getTables()[0]; // Sets the width of the second column to 100 points. const columnWidth = table.setColumnWidth(1, 100); // Gets the width of the second column and logs it to the console. console.log(columnWidth.getColumnWidth(1));
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
columnIndex | Integer | Indeks kolom. |
Return
Number
— Lebar kolom, dalam poin.
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.
Return
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
getNextSibling()
Mengambil elemen seinduk elemen berikutnya.
Saudara berikutnya memiliki induk yang sama dan mengikuti elemen saat ini.
Return
Element
— Elemen seinduk 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
getNumChildren()
Mengambil jumlah turunan.
// Get the body section of the active document. var body = DocumentApp.getActiveDocument().getBody(); // Log the number of elements in the document. Logger.log("There are " + body.getNumChildren() + " elements in the document body.");
Return
Integer
— jumlah anak
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
getNumRows()
Mengambil jumlah TableRows
.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first table. const table = body.getTables()[0]; // Logs the number of rows of the first table to the console. console.log(table.getNumRows());
Return
Integer
— Jumlah baris tabel.
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.
Return
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.
Return
Element
— Elemen seinduk 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
getRow(rowIndex)
Mengambil TableRow
pada indeks baris yang ditentukan.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first table and logs the text of first row to the console. const table = body.getTables()[0]; console.log(table.getRow(0).getText());
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
rowIndex | Integer | Indeks baris yang akan diambil. |
Return
TableRow
— Baris tabel.
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.
Return
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
.
Return
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
getType()
Mengambil ElementType
elemen.
Gunakan getType()
untuk menentukan jenis yang tepat dari elemen tertentu.
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.'); }
Return
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
insertTableRow(childIndex)
Membuat dan menyisipkan TableRow
baru pada indeks yang ditentukan.
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
childIndex | Integer | indeks untuk menyisipkan elemen |
Return
TableRow
— 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
insertTableRow(childIndex, tableRow)
Menyisipkan TableRow
yang ditentukan pada indeks yang ditentukan.
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
childIndex | Integer | indeks untuk menyisipkan elemen |
tableRow | TableRow | baris tabel untuk menyisipkan |
Return
TableRow
— elemen baris tabel yang disisipkan
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
.
Return
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
removeChild(child)
Menghapus elemen turunan yang ditentukan.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first table. const table = body.getTables()[0]; // Finds the first table row and removes it. const element = table.findElement(DocumentApp.ElementType.TABLE_ROW); table.removeChild(element.getElement());
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
child | Element | Elemen turunan yang akan dihapus. |
Return
Table
— 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
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(); }
Return
Table
— 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
removeRow(rowIndex)
Menghapus TableRow
pada indeks baris yang ditentukan.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first table and removes its second row. const table = body.getTables()[0]; table.removeRow(1);
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
rowIndex | Integer | Indeks baris yang akan dihapus. |
Return
TableRow
— Baris 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)
Mengganti semua kemunculan pola teks tertentu dengan string pengganti tertentu, menggunakan ekspresi reguler.
Pola penelusuran diteruskan sebagai string, bukan objek ekspresi reguler JavaScript. Oleh karena itu, Anda harus meng-escape setiap garis miring terbalik di pola tersebut.
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 regex untuk mencari |
replacement | String | teks untuk digunakan sebagai pengganti |
Return
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(attributes)
Menetapkan atribut elemen.
Parameter atribut yang ditentukan harus berupa objek dengan setiap nama properti merupakan 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. |
Return
Table
— 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
setBorderColor(color)
Menetapkan warna batas.
// Opens the Docs file by its ID. If you created your script from within a // Google Docs file, you can use DocumentApp.getActiveDocument() instead. // TODO(developer): Replace the ID with your own. const doc = DocumentApp.openById('abc123456'); // Gets the document body. const body = doc.getBody(); // Gets the first table. const table = body.getTables()[0]; // Sets the border color of the table to green. table.setBorderColor('#00FF00');
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
color | String | Warna batas, diformat dalam notasi CSS (seperti '#ffffff' ). |
Return
Table
— 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
setBorderWidth(width)
Menetapkan lebar batas dalam titik.
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
width | Number | lebar batas, dalam poin |
Return
Table
— 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
setColumnWidth(columnIndex, width)
Menetapkan lebar kolom yang ditentukan, dalam titik.
Parameter
Nama | Jenis | Deskripsi |
---|---|---|
columnIndex | Integer | indeks kolom |
width | Number | lebar batas, dalam poin |
Return
Table
— 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 |
Return
Table
— 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 |
Return
Table
— 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