Elemen yang mewakili tanggal yang telah diformat
Metode
Metode | Jenis hasil yang ditampilkan | Deskripsi singkat |
---|---|---|
copy() | Date | Menampilkan salinan mendalam dan terpisah dari elemen saat ini. |
getAttributes() | Object | Mengambil atribut elemen. |
getDisplayText() | String | Menampilkan nilai tampilan yang dirender dalam dokumen. |
getLocale() | String | Menampilkan lokal tanggal yang digunakan untuk nilai tampilan. |
getNextSibling() | Element | Mengambil elemen seinduk elemen berikutnya. |
getParent() | ContainerElement | Mengambil elemen induk elemen. |
getPreviousSibling() | Element | Mengambil elemen seinduk elemen sebelumnya. |
getTimestamp() | Date | Menampilkan stempel waktu yang terkait dengan tanggal. |
getType() | ElementType | Mengambil ElementType elemen. |
isAtDocumentEnd() | Boolean | Menentukan apakah elemen berada di akhir Document . |
merge() | Date | Menggabungkan elemen dengan pasangan sebelumnya dari jenis yang sama. |
removeFromParent() | Date | Menghapus elemen dari induknya. |
setAttributes(attributes) | Date | Menetapkan atribut elemen. |
Dokumentasi mendetail
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
Date
— 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
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
getDisplayText()
Menampilkan nilai tampilan yang dirender dalam dokumen. Nilai tampilan menggunakan zona waktu
UTC dan lokal tanggal. Misalnya, Jul 16, 2021
.
Return
String
— Nilai tampilan.
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
getLocale()
Menampilkan lokal tanggal yang digunakan untuk nilai tampilan. Misalnya, en
.
Return
String
— Lokalitas tanggal.
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
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
getTimestamp()
Menampilkan stempel waktu yang terkait dengan tanggal.
Return
Date
— Stempel waktu.
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
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
merge()
Menggabungkan elemen dengan pasangan sebelumnya dari jenis yang sama.
Hanya elemen dari ElementType
yang sama yang dapat digabungkan. Setiap elemen turunan yang terkandung dalam elemen saat ini akan dipindahkan ke elemen seinduk 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();
Return
Date
— Elemen gabungan.
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
Date
— 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
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
Date
— 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