องค์ประกอบที่แสดงตาราง Table อาจมีองค์ประกอบ Table เท่านั้น ดูข้อมูลเพิ่มเติมเกี่ยวกับโครงสร้างเอกสารได้ที่คำแนะนำในการขยาย Google เอกสาร
เมื่อสร้าง Table ที่มีแถวหรือเซลล์จํานวนมาก ให้พิจารณาสร้างจากอาร์เรย์สตริง ดังที่แสดงในตัวอย่างต่อไปนี้
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);
เมธอด
| วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ | 
|---|---|---|
append | Table | สร้างและเพิ่ม Table ใหม่ต่อท้าย | 
append | Table | เพิ่ม Table ที่ระบุต่อท้าย | 
clear() | Table | ล้างเนื้อหาขององค์ประกอบ | 
copy() | Table | แสดงผลสำเนาที่แยกออกและแบบเจาะลึกขององค์ประกอบปัจจุบัน | 
edit | Text | รับองค์ประกอบปัจจุบันเวอร์ชัน Text เพื่อแก้ไข | 
find | Range | ค้นหาเนื้อหาขององค์ประกอบเพื่อหารายการที่สืบทอดมาจากประเภทที่ระบุ | 
find | Range | ค้นหาเนื้อหาขององค์ประกอบเพื่อหารายการที่สืบทอดของประเภทที่ระบุ โดยเริ่มจาก Range ที่ระบุ | 
find | Range | ค้นหาเนื้อหาขององค์ประกอบเพื่อหารูปแบบข้อความที่ระบุโดยใช้นิพจน์ทั่วไป | 
find | Range | ค้นหาเนื้อหาขององค์ประกอบเพื่อหารูปแบบข้อความที่ระบุ โดยเริ่มจากผลการค้นหาหนึ่งๆ | 
get | Object | ดึงข้อมูลแอตทริบิวต์ขององค์ประกอบ | 
get | String | ดึงข้อมูลสีเส้นขอบ | 
get | Number | ดึงข้อมูลความกว้างของเส้นขอบเป็นจุด | 
get | Table | ดึงข้อมูล Table ที่ดัชนีแถวและเซลล์ที่ระบุ | 
get | Element | ดึงข้อมูลองค์ประกอบย่อยที่ดัชนีย่อยที่ระบุ | 
get | Integer | ดึงข้อมูลดัชนีย่อยสําหรับองค์ประกอบย่อยที่ระบุ | 
get | Number | ดึงข้อมูลความกว้างของคอลัมน์ตารางที่ระบุเป็นจุด | 
get | String | ดึงข้อมูล URL ของลิงก์ | 
get | Element | ดึงข้อมูลองค์ประกอบพี่น้องถัดไปขององค์ประกอบ | 
get | Integer | ดึงข้อมูลจํานวนเด็ก | 
get | Integer | ดึงข้อมูลจํานวน Table | 
get | Container | ดึงข้อมูลองค์ประกอบหลักขององค์ประกอบ | 
get | Element | ดึงข้อมูลองค์ประกอบพี่น้องก่อนหน้าขององค์ประกอบ | 
get | Table | ดึงข้อมูล Table ที่ดัชนีแถวที่ระบุ | 
get | String | ดึงข้อมูลเนื้อหาขององค์ประกอบเป็นสตริงข้อความ | 
get | Text | รับการจัดข้อความ | 
get | Element | ดึงข้อมูล Element ขององค์ประกอบ | 
insert | Table | สร้างและแทรก Table ใหม่ ณ ดัชนีที่ระบุ | 
insert | Table | แทรก Table ที่ระบุไว้ที่ดัชนีที่ระบุ | 
is | Boolean | ระบุว่าองค์ประกอบอยู่ท้าย Document หรือไม่ | 
remove | Table | นำองค์ประกอบย่อยที่ระบุออก | 
remove | Table | นำองค์ประกอบออกจากองค์ประกอบหลัก | 
remove | Table | นำ Table ที่ดัชนีแถวที่ระบุออก | 
replace | Element | แทนที่รายการทั้งหมดของรูปแบบข้อความหนึ่งๆ ด้วยสตริงการแทนที่หนึ่งๆ โดยใช้นิพจน์ทั่วไป | 
set | Table | ตั้งค่าแอตทริบิวต์ขององค์ประกอบ | 
set | Table | ตั้งค่าสีเส้นขอบ | 
set | Table | ตั้งค่าความกว้างของขอบเป็นจุด | 
set | Table | ตั้งค่าความกว้างของคอลัมน์ที่ระบุเป็นจุด | 
set | Table | ตั้งค่า URL ของลิงก์ | 
set | Table | ตั้งค่าการจัดข้อความ | 
เอกสารประกอบโดยละเอียด
append Table Row()
append Table Row(tableRow)
เพิ่ม Table ที่ระบุต่อท้าย
// 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);
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
table | Table | แถวของตารางที่จะเพิ่มต่อท้าย | 
รีเทิร์น
Table — องค์ประกอบแถวในตารางที่ต่อท้าย
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
clear()
copy()
แสดงผลสำเนาที่แยกออกและแบบเจาะลึกขององค์ประกอบปัจจุบัน
ระบบจะคัดลอกองค์ประกอบย่อยทั้งหมดที่อยู่ในองค์ประกอบนั้นด้วย องค์ประกอบใหม่ไม่มีองค์ประกอบหลัก
รีเทิร์น
Table — สำเนาใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
edit As Text()
รับองค์ประกอบปัจจุบันเวอร์ชัน Text เพื่อแก้ไข
ใช้ edit เพื่อจัดการเนื้อหาขององค์ประกอบเป็น Rich Text โหมด edit ไม่สนใจองค์ประกอบที่ไม่ใช่ข้อความ (เช่น Inline และ Horizontal)
ระบบจะนำองค์ประกอบย่อยที่อยู่ในช่วงข้อความที่ลบออกทั้งหมดออกจากองค์ประกอบ
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);
รีเทิร์น
Text — องค์ประกอบปัจจุบันเวอร์ชันข้อความ
find Element(elementType)
ค้นหาเนื้อหาขององค์ประกอบเพื่อหารายการที่สืบทอดมาจากประเภทที่ระบุ
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
element | Element | ประเภทองค์ประกอบที่จะค้นหา | 
รีเทิร์น
Range — ผลการค้นหาที่ระบุตําแหน่งขององค์ประกอบการค้นหา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
find Element(elementType, from)
ค้นหาเนื้อหาขององค์ประกอบเพื่อหารายการที่สืบทอดของประเภทที่ระบุ โดยเริ่มจาก Range ที่ระบุ
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; } }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
element | Element | ประเภทองค์ประกอบที่จะค้นหา | 
from | Range | ผลการค้นหาที่จะค้นหา | 
รีเทิร์น
Range — ผลการค้นหาที่ระบุตำแหน่งถัดไปขององค์ประกอบการค้นหา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
find Text(searchPattern)
ค้นหาเนื้อหาขององค์ประกอบเพื่อหารูปแบบข้อความที่ระบุโดยใช้นิพจน์ทั่วไป
ระบบไม่รองรับฟีเจอร์นิพจน์ทั่วไปของ JavaScript บางรายการ เช่น กลุ่มที่จับและตัวแก้ไขโหมด
ระบบจะจับคู่รูปแบบนิพจน์ทั่วไปที่ระบุกับบล็อกข้อความแต่ละรายการในองค์ประกอบปัจจุบันแยกกัน
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
search | String | รูปแบบที่จะค้นหา | 
รีเทิร์น
Range — ผลการค้นหาที่ระบุตําแหน่งของข้อความค้นหา หรือเป็นค่าว่างหากไม่พบการจับคู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
find Text(searchPattern, from)
ค้นหาเนื้อหาขององค์ประกอบเพื่อหารูปแบบข้อความที่ระบุ โดยเริ่มจากผลการค้นหาหนึ่งๆ
ระบบไม่รองรับฟีเจอร์นิพจน์ทั่วไปของ JavaScript บางรายการ เช่น กลุ่มที่จับและตัวแก้ไขโหมด
ระบบจะจับคู่รูปแบบนิพจน์ทั่วไปที่ระบุกับบล็อกข้อความแต่ละรายการในองค์ประกอบปัจจุบันแยกกัน
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
search | String | รูปแบบที่จะค้นหา | 
from | Range | ผลการค้นหาที่จะค้นหา | 
รีเทิร์น
Range — ผลการค้นหาที่ระบุตําแหน่งถัดไปของข้อความค้นหา หรือเป็นค่าว่างหากไม่พบการจับคู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Attributes()
ดึงข้อมูลแอตทริบิวต์ขององค์ประกอบ
ผลลัพธ์ที่ได้คือออบเจ็กต์ที่มีพร็อพเพอร์ตี้สำหรับแอตทริบิวต์องค์ประกอบที่ถูกต้องแต่ละรายการ โดยที่ชื่อพร็อพเพอร์ตี้แต่ละรายการสอดคล้องกับรายการในการแจกแจง Document
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]}`); }
รีเทิร์น
Object — แอตทริบิวต์ขององค์ประกอบ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Border Color()
ดึงข้อมูลสีเส้นขอบ
// 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());
รีเทิร์น
String — สีเส้นขอบที่จัดรูปแบบเป็นรูปแบบ CSS (เช่น '#ffffff')
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Border Width()
ดึงข้อมูลความกว้างของเส้นขอบเป็นจุด
// 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());
รีเทิร์น
Number — ความกว้างของเส้นขอบเป็นจุด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Cell(rowIndex, cellIndex)
ดึงข้อมูล Table ที่ดัชนีแถวและเซลล์ที่ระบุ
// 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());
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
row | Integer | ดัชนีของแถวที่มีเซลล์ที่จะดึงข้อมูล | 
cell | Integer | ดัชนีของเซลล์ที่จะดึงข้อมูล | 
รีเทิร์น
Table — เซลล์ตาราง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Child(childIndex)
ดึงข้อมูลองค์ประกอบย่อยที่ดัชนีย่อยที่ระบุ
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.'); }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
child | Integer | ดัชนีขององค์ประกอบย่อยที่จะดึงข้อมูล | 
รีเทิร์น
Element — องค์ประกอบย่อยที่อยู่ที่อินเด็กซ์ที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Child Index(child)
ดึงข้อมูลดัชนีย่อยสําหรับองค์ประกอบย่อยที่ระบุ
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
child | Element | องค์ประกอบย่อยที่จะดึงข้อมูลดัชนี | 
รีเทิร์น
Integer — ดัชนีย่อย
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Column Width(columnIndex)
ดึงข้อมูลความกว้างของคอลัมน์ตารางที่ระบุเป็นจุด
// 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));
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
column | Integer | ดัชนีคอลัมน์ | 
รีเทิร์น
Number — ความกว้างของคอลัมน์เป็นจุด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Link Url()
ดึงข้อมูล URL ของลิงก์
รีเทิร์น
String — URL ของลิงก์ หรือเป็นค่าว่างหากองค์ประกอบมีค่าหลายค่าสำหรับแอตทริบิวต์นี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Next Sibling()
ดึงข้อมูลองค์ประกอบพี่น้องถัดไปขององค์ประกอบ
องค์ประกอบถัดไปมีองค์ประกอบหลักเดียวกันและอยู่หลังองค์ประกอบปัจจุบัน
รีเทิร์น
Element — องค์ประกอบระดับถัดไป
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Num Children()
ดึงข้อมูลจํานวนเด็ก
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.`);
รีเทิร์น
Integer — จำนวนเด็ก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Num Rows()
ดึงข้อมูลจํานวน Table
// 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());
รีเทิร์น
Integer — จํานวนแถวของตาราง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Parent()
ดึงข้อมูลองค์ประกอบหลักขององค์ประกอบ
องค์ประกอบหลักมีองค์ประกอบปัจจุบัน
รีเทิร์น
Container — องค์ประกอบหลัก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Previous Sibling()
ดึงข้อมูลองค์ประกอบพี่น้องก่อนหน้าขององค์ประกอบ
องค์ประกอบระดับข้างเคียงก่อนหน้ามีองค์ประกอบหลักเดียวกันและอยู่ก่อนองค์ประกอบปัจจุบัน
รีเทิร์น
Element — องค์ประกอบระดับข้างเคียงก่อนหน้า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Row(rowIndex)
ดึงข้อมูล Table ที่ดัชนีแถวที่ระบุ
// 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());
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
row | Integer | ดัชนีของแถวที่จะดึงข้อมูล | 
รีเทิร์น
Table — แถวของตาราง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Text()
ดึงข้อมูลเนื้อหาขององค์ประกอบเป็นสตริงข้อความ
รีเทิร์น
String — เนื้อหาขององค์ประกอบเป็นสตริงข้อความ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Text Alignment()
รับการจัดข้อความ ประเภทการจัดแนวที่ใช้ได้มี Document, Document และ Document
รีเทิร์น
Text — ประเภทการจัดแนวข้อความ หรือ null หากข้อความมีการจัดแนวข้อความหลายประเภท หรือหากไม่เคยตั้งค่าการจัดแนวข้อความ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
get Type()
ดึงข้อมูล Element ขององค์ประกอบ
ใช้ get เพื่อระบุประเภทที่แน่นอนขององค์ประกอบหนึ่งๆ
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.'); }
รีเทิร์น
Element — ประเภทองค์ประกอบ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
insert Table Row(childIndex)
สร้างและแทรก Table ใหม่ ณ ดัชนีที่ระบุ
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
child | Integer | ดัชนีที่จะแทรกองค์ประกอบ | 
รีเทิร์น
Table — องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
insert Table Row(childIndex, tableRow)
แทรก Table ที่ระบุไว้ที่ดัชนีที่ระบุ
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
child | Integer | ดัชนีที่จะแทรกองค์ประกอบ | 
table | Table | แถวของตารางที่จะแทรก | 
รีเทิร์น
Table — องค์ประกอบแถวของตารางที่แทรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
is At Document End()
remove Child(child)
นำองค์ประกอบย่อยที่ระบุออก
// 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());
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
child | Element | องค์ประกอบย่อยที่จะนําออก | 
รีเทิร์น
Table — องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
remove From Parent()
นำองค์ประกอบออกจากองค์ประกอบหลัก
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(); }
รีเทิร์น
Table — องค์ประกอบที่ถูกนำออก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
remove Row(rowIndex)
นำ Table ที่ดัชนีแถวที่ระบุออก
// 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);
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
row | Integer | ดัชนีของแถวที่จะนําออก | 
รีเทิร์น
Table — แถวที่นําออก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
replace Text(searchPattern, replacement)
แทนที่รายการทั้งหมดของรูปแบบข้อความหนึ่งๆ ด้วยสตริงการแทนที่หนึ่งๆ โดยใช้นิพจน์ทั่วไป
ระบบจะส่งรูปแบบการค้นหาเป็นสตริง ไม่ใช่ออบเจ็กต์นิพจน์ทั่วไปของ JavaScript คุณจึงต้องยกเว้นเครื่องหมายแบ็กสแลชในนิพจน์
วิธีนี้ใช้ไลบรารีนิพจน์ทั่วไป RE2 ของ Google ซึ่งจํากัดไวยากรณ์ที่รองรับ
ระบบจะจับคู่รูปแบบนิพจน์ทั่วไปที่ระบุกับบล็อกข้อความแต่ละรายการในองค์ประกอบปัจจุบันแยกกัน
const body = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab().getBody(); // Clear the text surrounding "Apps Script", with or without text. body.replaceText('^.*Apps ?Script.*$', 'Apps Script');
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
search | String | รูปแบบนิพจน์ทั่วไปที่จะค้นหา | 
replacement | String | ข้อความที่จะใช้แทนที่ | 
รีเทิร์น
Element — องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
set Attributes(attributes)
ตั้งค่าแอตทริบิวต์ขององค์ประกอบ
พารามิเตอร์แอตทริบิวต์ที่ระบุต้องเป็นออบเจ็กต์ที่ชื่อพร็อพเพอร์ตี้แต่ละรายการเป็นรายการในลิสต์Document และค่าพร็อพเพอร์ตี้แต่ละรายการเป็นค่าใหม่ที่จะใช้
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);
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
attributes | Object | แอตทริบิวต์ขององค์ประกอบ | 
รีเทิร์น
Table — องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
set Border Color(color)
ตั้งค่าสีเส้นขอบ
// 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');
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
color | String | สีเส้นขอบที่จัดรูปแบบเป็นรูปแบบการเขียน CSS (เช่น '#ffffff') | 
รีเทิร์น
Table — องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
set Border Width(width)
ตั้งค่าความกว้างของขอบเป็นจุด
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
width | Number | ความกว้างของเส้นขอบเป็นจุด | 
รีเทิร์น
Table — องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
set Column Width(columnIndex, width)
ตั้งค่าความกว้างของคอลัมน์ที่ระบุเป็นจุด
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
column | Integer | ดัชนีคอลัมน์ | 
width | Number | ความกว้างของเส้นขอบเป็นจุด | 
รีเทิร์น
Table — องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents 
set Link Url(url)
set Text Alignment(textAlignment)
ตั้งค่าการจัดข้อความ ประเภทการจัดแนวที่ใช้ได้มี Document, Document และ Document
// 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);
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย | 
|---|---|---|
text | Text | ประเภทการจัดแนวข้อความที่จะใช้ | 
รีเทิร์น
Table — องค์ประกอบปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
- 
https://www.googleapis.com/auth/documents.currentonly - 
https://www.googleapis.com/auth/documents