Class Table

Tabel

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

MetodeJenis hasil yang ditampilkanDeskripsi singkat
appendTableRow()TableRowMembuat dan menambahkan TableRow baru.
appendTableRow(tableRow)TableRowMenambahkan TableRow yang ditentukan.
clear()TableMenghapus konten elemen.
copy()TableMenampilkan salinan mendalam dan terpisah dari elemen saat ini.
editAsText()TextMendapatkan versi Text dari elemen saat ini, untuk diedit.
findElement(elementType)RangeElementMenelusuri konten elemen untuk turunan dari jenis yang ditentukan.
findElement(elementType, from)RangeElementMenelusuri konten elemen untuk turunan dari jenis yang ditentukan, mulai dari RangeElement yang ditentukan.
findText(searchPattern)RangeElementMenelusuri konten elemen untuk pola teks yang ditentukan menggunakan ekspresi reguler.
findText(searchPattern, from)RangeElementMenelusuri konten elemen untuk pola teks yang ditentukan, mulai dari hasil penelusuran tertentu.
getAttributes()ObjectMengambil atribut elemen.
getBorderColor()StringMengambil warna batas.
getBorderWidth()NumberMengambil lebar batas dalam poin.
getCell(rowIndex, cellIndex)TableCellMengambil TableCell pada indeks sel dan baris yang ditentukan.
getChild(childIndex)ElementMengambil elemen turunan pada indeks turunan yang ditentukan.
getChildIndex(child)IntegerMengambil indeks turunan untuk elemen turunan yang ditentukan.
getColumnWidth(columnIndex)NumberMengambil lebar kolom tabel yang ditentukan, dalam poin.
getLinkUrl()StringMengambil URL link.
getNextSibling()ElementMengambil elemen seinduk elemen berikutnya.
getNumChildren()IntegerMengambil jumlah turunan.
getNumRows()IntegerMengambil jumlah TableRows.
getParent()ContainerElementMengambil elemen induk elemen.
getPreviousSibling()ElementMengambil elemen seinduk elemen sebelumnya.
getRow(rowIndex)TableRowMengambil TableRow pada indeks baris yang ditentukan.
getText()StringMengambil konten elemen sebagai string teks.
getTextAlignment()TextAlignmentMendapatkan perataan teks.
getType()ElementTypeMengambil ElementType elemen.
insertTableRow(childIndex)TableRowMembuat dan menyisipkan TableRow baru pada indeks yang ditentukan.
insertTableRow(childIndex, tableRow)TableRowMenyisipkan TableRow yang ditentukan pada indeks yang ditentukan.
isAtDocumentEnd()BooleanMenentukan apakah elemen berada di akhir Document.
removeChild(child)TableMenghapus elemen turunan yang ditentukan.
removeFromParent()TableMenghapus elemen dari induknya.
removeRow(rowIndex)TableRowMenghapus TableRow pada indeks baris yang ditentukan.
replaceText(searchPattern, replacement)ElementMengganti semua kemunculan pola teks tertentu dengan string pengganti tertentu, menggunakan ekspresi reguler.
setAttributes(attributes)TableMenetapkan atribut elemen.
setBorderColor(color)TableMenetapkan warna batas.
setBorderWidth(width)TableMenetapkan lebar batas dalam titik.
setColumnWidth(columnIndex, width)TableMenetapkan lebar kolom yang ditentukan, dalam titik.
setLinkUrl(url)TableMenetapkan URL link.
setTextAlignment(textAlignment)TableMenetapkan perataan teks.

Dokumentasi mendetail

appendTableRow()

Membuat dan menambahkan TableRow baru.

Return

TableRow — elemen baris tabel 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

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

NamaJenisDeskripsi
tableRowTableRowBaris 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()

Menghapus konten elemen.

Return

Table — elemen saat ini


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

NamaJenisDeskripsi
elementTypeElementTypejenis 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

NamaJenisDeskripsi
elementTypeElementTypejenis elemen yang akan dicari
fromRangeElementhasil 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

NamaJenisDeskripsi
searchPatternStringpola 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

NamaJenisDeskripsi
searchPatternStringpola untuk mencari
fromRangeElementhasil 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

NamaJenisDeskripsi
rowIndexIntegerIndeks baris yang berisi sel yang akan diambil.
cellIndexIntegerIndeks 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

NamaJenisDeskripsi
childIndexIntegerindeks 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

NamaJenisDeskripsi
childElementelemen 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

NamaJenisDeskripsi
columnIndexIntegerIndeks 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

NamaJenisDeskripsi
rowIndexIntegerIndeks 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

NamaJenisDeskripsi
childIndexIntegerindeks 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

NamaJenisDeskripsi
childIndexIntegerindeks untuk menyisipkan elemen
tableRowTableRowbaris 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

NamaJenisDeskripsi
childElementElemen 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

NamaJenisDeskripsi
rowIndexIntegerIndeks 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

NamaJenisDeskripsi
searchPatternStringpola regex untuk mencari
replacementStringteks 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

NamaJenisDeskripsi
attributesObjectAtribut 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

NamaJenisDeskripsi
colorStringWarna 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

NamaJenisDeskripsi
widthNumberlebar 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

NamaJenisDeskripsi
columnIndexIntegerindeks kolom
widthNumberlebar 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

NamaJenisDeskripsi
urlStringURL 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

NamaJenisDeskripsi
textAlignmentTextAlignmentjenis 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