Elemen yang merepresentasikan tabel. Table hanya boleh berisi elemen TableRow. Untuk
informasi selengkapnya tentang struktur dokumen, lihat panduan untuk memperluas Google Dokumen.
Saat membuat Table yang berisi banyak baris atau sel, pertimbangkan untuk membuatnya dari array string, seperti yang ditunjukkan dalam contoh berikut.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Create a two-dimensional array containing the cell contents. const cells = [ ['Row 1, Cell 1', 'Row 1, Cell 2'], ['Row 2, Cell 1', 'Row 2, Cell 2'], ]; // Build a table from the array. body.appendTable(cells);
Metode
| Metode | Jenis nilai yang ditampilkan | Deskripsi singkat |
|---|---|---|
append | Table | Membuat dan menambahkan Table baru. |
append | Table | Menambahkan Table yang diberikan. |
clear() | Table | Menghapus konten elemen. |
copy() | Table | Menampilkan salinan mendalam yang terlepas dari elemen saat ini. |
edit | Text | Mendapatkan versi Text dari elemen saat ini, untuk pengeditan. |
find | Range | Menelusuri konten elemen untuk menemukan turunan dari jenis yang ditentukan. |
find | Range | Menelusuri konten elemen untuk menemukan keturunan dari jenis yang ditentukan, dimulai dari
Range yang ditentukan. |
find | Range | Menelusuri konten elemen untuk pola teks yang ditentukan menggunakan ekspresi reguler. |
find | Range | Menelusuri konten elemen untuk menemukan pola teks yang ditentukan, dimulai dari hasil penelusuran tertentu. |
get | Object | Mengambil atribut elemen. |
get | String|null | Mengambil warna batas. |
get | Number|null | Mengambil lebar batas, dalam poin. |
get | Table | Mengambil Table pada indeks baris dan sel yang ditentukan. |
get | Element | Mengambil elemen turunan pada indeks turunan yang ditentukan. |
get | Integer | Mengambil indeks turunan untuk elemen turunan yang ditentukan. |
get | Number|null | Mengambil lebar kolom tabel yang ditentukan, dalam satuan poin. |
get | String|null | Mengambil URL link. |
get | Element|null | Mengambil elemen pasangan berikutnya dari elemen. |
get | Integer | Mengambil jumlah anak. |
get | Integer | Mengambil jumlah Table. |
get | Container | Mengambil elemen induk elemen. |
get | Element|null | Mengambil elemen saudara sebelumnya dari elemen. |
get | Table | Mengambil Table pada indeks baris yang ditentukan. |
get | String | Mengambil konten elemen sebagai string teks. |
get | Text | Mendapatkan perataan teks. |
get | Element | Mengambil Element elemen. |
insert | Table | Membuat dan menyisipkan Table baru pada indeks yang ditentukan. |
insert | Table | Menyisipkan Table yang diberikan pada indeks yang ditentukan. |
is | Boolean | Menentukan apakah elemen berada di akhir Document. |
remove | Table | Menghapus elemen turunan yang ditentukan. |
remove | Table|null | Menghapus elemen dari induknya. |
remove | Table | Menghapus Table pada indeks baris yang ditentukan. |
replace | Element | Mengganti semua kemunculan pola teks tertentu dengan string pengganti tertentu, menggunakan ekspresi reguler. |
set | Table | Menetapkan atribut elemen. |
set | Table | Menetapkan warna batas. |
set | Table | Menetapkan lebar batas, dalam poin. |
set | Table | Menetapkan lebar kolom yang ditentukan, dalam satuan poin. |
set | Table | Menetapkan URL link. |
set | Table | Menetapkan perataan teks. |
Dokumentasi mendetail
appendTableRow()
appendTableRow(tableRow)
Menambahkan TableRow yang diberikan.
// 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('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table in the tab 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 |
|---|---|---|
table | Table | Baris tabel yang akan ditambahkan. |
Pulang pergi
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 yang terlepas dari elemen saat ini.
Semua elemen turunan yang ada dalam elemen juga disalin. Elemen baru tidak memiliki induk.
Pulang pergi
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 pengeditan.
Gunakan editAsText untuk memanipulasi konten elemen sebagai teks kaya. Mode editAsText mengabaikan elemen non-teks (seperti InlineImage dan HorizontalRule).
Elemen turunan yang sepenuhnya berada dalam rentang teks yang dihapus akan dihapus dari elemen.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Insert two paragraphs separated by a paragraph containing an // horizontal rule. body.insertParagraph(0, 'An editAsText sample.'); body.insertHorizontalRule(0); body.insertParagraph(0, 'An example.'); // Delete " sample.\n\n An" removing the horizontal rule in the process. body.editAsText().deleteText(14, 25);
Pulang pergi
Text — versi teks dari elemen saat ini
findElement(elementType)
Menelusuri konten elemen untuk menemukan turunan dari jenis yang ditentukan.
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
element | Element | Jenis elemen yang akan ditelusuri. |
Pulang pergi
RangeElement|null — 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 menemukan keturunan dari jenis yang ditentukan, dimulai dari
RangeElement yang ditentukan.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Define the search parameters. let searchResult = null; // Search until the paragraph is found. while ( (searchResult = body.findElement( DocumentApp.ElementType.PARAGRAPH, searchResult, ))) { const par = searchResult.getElement().asParagraph(); if (par.getHeading() === DocumentApp.ParagraphHeading.HEADING1) { // Found one, update and stop. par.setText('This is the first header.'); break; } }
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
element | Element | Jenis elemen yang akan ditelusuri. |
from | Range | Hasil penelusuran yang akan ditelusuri. |
Pulang pergi
RangeElement|null — 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.
Sebagian fitur ekspresi reguler JavaScript tidak sepenuhnya didukung, seperti grup pengambilan dan pengubah mode.
Pola ekspresi reguler yang diberikan dicocokkan secara terpisah dengan setiap blok teks yang ada dalam elemen saat ini.
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
search | String | pola yang akan ditelusuri |
Pulang pergi
RangeElement|null — 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 menemukan pola teks yang ditentukan, dimulai dari hasil penelusuran tertentu.
Sebagian fitur ekspresi reguler JavaScript tidak sepenuhnya didukung, seperti grup pengambilan dan pengubah mode.
Pola ekspresi reguler yang diberikan dicocokkan secara terpisah dengan setiap blok teks yang ada dalam elemen saat ini.
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
search | String | pola yang akan ditelusuri |
from | Range | hasil penelusuran yang akan digunakan untuk memulai penelusuran |
Pulang pergi
RangeElement|null — 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.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Append a styled paragraph. const par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true); // Retrieve the paragraph's attributes. const atts = par.getAttributes(); // Log the paragraph attributes. for (const att in atts) { Logger.log(`${att}:${atts[att]}`); }
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
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('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the 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());
Pulang pergi
String|null — 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('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the 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());
Pulang pergi
Number|null — 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 baris dan sel 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('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the 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 |
|---|---|---|
row | Integer | Indeks baris yang berisi sel yang akan diambil. |
cell | Integer | Indeks sel yang akan diambil. |
Pulang pergi
TableCell|null — 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.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Obtain the first element in the tab. const 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 |
|---|---|---|
child | Integer | Indeks elemen turunan yang akan diambil. |
Pulang pergi
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 yang indeksnya akan diambil. |
Pulang pergi
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 satuan 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('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the 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 |
|---|---|---|
column | Integer | Indeks kolom. |
Pulang pergi
Number|null — 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.
Pulang pergi
String|null — 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 pasangan berikutnya dari elemen.
Saudara berikutnya memiliki induk yang sama dan mengikuti elemen saat ini.
Pulang pergi
Element|null — Elemen saudara 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 anak.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Log the number of elements in the tab. Logger.log(`There are ${body.getNumChildren()} elements in the tab's body.`);
Pulang pergi
Integer — Jumlah 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
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('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table. const table = body.getTables()[0]; // Logs the number of rows of the first table to the console. console.log(table.getNumRows());
Pulang pergi
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.
Pulang pergi
ContainerElement|null — 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 saudara sebelumnya dari elemen.
Saudara sebelumnya memiliki induk yang sama dan mendahului elemen saat ini.
Pulang pergi
Element|null — Elemen saudara 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('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the 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 |
|---|---|---|
row | Integer | Indeks baris yang akan diambil. |
Pulang pergi
TableRow|null — 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.
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|null — 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 pasti elemen tertentu.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Obtain the first element in the active tab's body. const firstChild = body.getChild(0); // Use getType() to determine the element's type. if (firstChild.getType() === DocumentApp.ElementType.PARAGRAPH) { Logger.log('The first element is a paragraph.'); } else { Logger.log('The first element is not a paragraph.'); }
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
insertTableRow(childIndex)
Membuat dan menyisipkan TableRow baru pada indeks yang ditentukan.
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
child | Integer | indeks tempat elemen akan disisipkan |
Pulang pergi
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 diberikan pada indeks yang ditentukan.
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
child | Integer | indeks tempat elemen akan disisipkan |
table | Table | baris tabel yang akan disisipkan |
Pulang pergi
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.
Pulang pergi
Boolean — Apakah elemen berada di akhir tab.
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('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the 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. |
Pulang pergi
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.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Remove all images in the active tab's body. const imgs = body.getImages(); for (let i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
Pulang pergi
Table|null — 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('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the first table and removes its second row. const table = body.getTables()[0]; table.removeRow(1);
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
row | Integer | Indeks baris yang akan dihapus. |
Pulang pergi
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 semua garis miring terbalik dalam pola.
Metode ini menggunakan library ekspresi reguler RE2 Google, yang membatasi sintaksis yang didukung.
Pola ekspresi reguler yang diberikan dicocokkan secara terpisah dengan setiap blok teks yang ada dalam elemen saat ini.
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Clear the text surrounding "Apps Script", with or without text. body.replaceText('^.*Apps ?Script.*$', 'Apps Script');
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
search | String | pola regex yang akan dicari |
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(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.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody(); // Define a custom paragraph style. const style = {}; style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT; style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri'; style[DocumentApp.Attribute.FONT_SIZE] = 18; style[DocumentApp.Attribute.BOLD] = true; // Append a plain paragraph. const par = body.appendParagraph('A paragraph with custom style.'); // Apply the custom style. par.setAttributes(style);
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
attributes | Object | Atribut elemen. |
Pulang pergi
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('123abc'); // Gets the body contents of the tab by its ID. // TODO(developer): Replace the ID with your own. const body = doc.getTab('123abc').asDocumentTab().getBody(); // Gets the 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'). |
Pulang pergi
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 poin.
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
width | Number | lebar batas, dalam poin |
Pulang pergi
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 satuan poin.
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
column | Integer | indeks kolom |
width | Number | lebar batas, dalam poin |
Pulang pergi
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 |
Pulang pergi
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 in the active tab be superscript. const documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab(); const text = documentTab.getBody().getParagraphs()[0].editAsText(); text.setTextAlignment(DocumentApp.TextAlignment.SUPERSCRIPT);
Parameter
| Nama | Jenis | Deskripsi |
|---|---|---|
text | Text | jenis perataan teks yang akan diterapkan |
Pulang pergi
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