เข้าถึงและแก้ไขไฟล์ Google ชีต การดําเนินการทั่วไปคือการเพิ่มแผ่นงานใหม่ และเพิ่มผู้ทํางานร่วมกัน
วิธีการ
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
---|---|---|
addDeveloperMetadata(key) | Spreadsheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ที่ระบุลงในสเปรดชีตระดับบนสุด |
addDeveloperMetadata(key, visibility) | Spreadsheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์โดยใช้คีย์ที่ระบุและระดับการเข้าถึงในสเปรดชีต |
addDeveloperMetadata(key, value) | Spreadsheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์โดยใช้คีย์และค่าที่ระบุในสเปรดชีต |
addDeveloperMetadata(key, value, visibility) | Spreadsheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ด้วยคีย์ ค่า และระดับการมองเห็นที่เจาะจงไปยังสเปรดชีต |
addEditor(emailAddress) | Spreadsheet | เพิ่มผู้ใช้ที่ต้องการลงในรายการเครื่องมือแก้ไขของ Spreadsheet |
addEditor(user) | Spreadsheet | เพิ่มผู้ใช้ที่ต้องการลงในรายการเครื่องมือแก้ไขของ Spreadsheet |
addEditors(emailAddresses) | Spreadsheet | เพิ่มอาร์เรย์ผู้ใช้ที่ระบุลงในรายการผู้แก้ไขสําหรับ Spreadsheet |
addMenu(name, subMenus) | void | สร้างเมนูใหม่ใน UI ของสเปรดชีต |
addViewer(emailAddress) | Spreadsheet | เพิ่มผู้ใช้ที่ต้องการลงในรายการผู้ชมสําหรับ Spreadsheet |
addViewer(user) | Spreadsheet | เพิ่มผู้ใช้ที่ต้องการลงในรายการผู้ชมสําหรับ Spreadsheet |
addViewers(emailAddresses) | Spreadsheet | เพิ่มอาร์เรย์ผู้ใช้ที่ระบุลงในรายการผู้ชมสําหรับ Spreadsheet |
appendRow(rowContents) | Sheet | เพิ่มแถวมาด้านล่างของเขตข้อมูลปัจจุบันในชีต |
autoResizeColumn(columnPosition) | Sheet | ตั้งค่าความกว้างของคอลัมน์ที่ระบุให้พอดีกับเนื้อหา |
copy(name) | Spreadsheet | คัดลอกสเปรดชีตและส่งคืนสเปรดชีตใหม่ |
createDeveloperMetadataFinder() | DeveloperMetadataFinder | แสดงผล DeveloperMetadataFinder สําหรับการค้นหาข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ภายในขอบเขตของสเปรดชีตนี้ |
createTextFinder(findText) | TextFinder | สร้างเครื่องมือค้นหาข้อความสําหรับสเปรดชีต ซึ่งสามารถใช้ค้นหาและแทนที่ข้อความภายในสเปรดชีตได้ |
deleteActiveSheet() | Sheet | ลบแผ่นงานที่ใช้งานอยู่ |
deleteColumn(columnPosition) | Sheet | ลบคอลัมน์ในตําแหน่งคอลัมน์ที่ระบุ |
deleteColumns(columnPosition, howMany) | void | ลบคอลัมน์จํานวนหนึ่งโดยเริ่มที่ตําแหน่งคอลัมน์ที่ระบุ |
deleteRow(rowPosition) | Sheet | ลบแถวที่ตําแหน่งแถวที่ระบุ |
deleteRows(rowPosition, howMany) | void | ลบแถวจํานวนหนึ่งโดยเริ่มที่ตําแหน่งแถวที่ระบุ |
deleteSheet(sheet) | void | ลบแผ่นงานที่ระบุ |
duplicateActiveSheet() | Sheet | ทําสําเนาแผ่นงานที่ใช้งานอยู่ให้เป็นแผ่นงานที่ใช้งานอยู่ |
getActiveCell() | Range | แสดงผลเซลล์ที่มีการใช้งานในแผ่นงานนี้ |
getActiveRange() | Range | แสดงผลช่วงที่เลือกในแผ่นงานที่ทํางานอยู่ หรือ null หากไม่มีช่วงที่มีการใช้งาน |
getActiveRangeList() | RangeList | แสดงรายการช่วงที่ใช้งานอยู่ในแผ่นงานที่มีการใช้งานหรือ null หากไม่มีช่วงที่ทํางานอยู่ |
getActiveSheet() | Sheet | ดาวน์โหลดชีตที่ใช้งานอยู่ในสเปรดชีต |
getAs(contentType) | Blob | ส่งคืนข้อมูลภายในออบเจ็กต์นี้เป็น Blob ที่แปลงเป็นประเภทเนื้อหาที่ระบุ |
getBandings() | Banding[] | แสดงค่าขอบเขตทั้งหมดในสเปรดชีตนี้ |
getBlob() | Blob | ส่งคืนข้อมูลภายในออบเจ็กต์นี้เป็น BLOB |
getColumnWidth(columnPosition) | Integer | รับความกว้างเป็นพิกเซลของคอลัมน์ที่ระบุ |
getCurrentCell() | Range | แสดงผลเซลล์ปัจจุบันในแผ่นงานที่ใช้อยู่ หรือ null ถ้าไม่มีเซลล์ปัจจุบัน |
getDataRange() | Range | แสดงผล Range ที่สอดคล้องกับมิติข้อมูลที่มีข้อมูลอยู่ |
getDataSourceFormulas() | DataSourceFormula[] | รับสูตรแหล่งข้อมูลทั้งหมด |
getDataSourcePivotTables() | DataSourcePivotTable[] | รับตาราง Pivot ของแหล่งข้อมูลทั้งหมด |
getDataSourceRefreshSchedules() | DataSourceRefreshSchedule[] | ดูกําหนดการรีเฟรชของสเปรดชีตนี้ |
getDataSourceSheets() | DataSourceSheet[] | แสดงผลแผ่นงานแหล่งข้อมูลทั้งหมดในสเปรดชีต |
getDataSourceTables() | DataSourceTable[] | รับตารางแหล่งข้อมูลทั้งหมด |
getDataSources() | DataSource[] | แสดงแหล่งข้อมูลทั้งหมดในสเปรดชีต |
getDeveloperMetadata() | DeveloperMetadata[] | รับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่เชื่อมโยงกับสเปรดชีตระดับบนสุด |
getEditors() | User[] | รับรายชื่อผู้แก้ไขสําหรับ Spreadsheet นี้ |
getFormUrl() | String | แสดงผล URL สําหรับฟอร์มที่ส่งการตอบกลับไปยังสเปรดชีตนี้ หรือ null ถ้าสเปรดชีตนี้ไม่มีฟอร์มที่เชื่อมโยง |
getFrozenColumns() | Integer | แสดงผลจํานวนคอลัมน์ที่ตรึงไว้ |
getFrozenRows() | Integer | แสดงผลจํานวนแถวที่ตรึง |
getId() | String | รับตัวระบุที่ไม่ซ้ํากันสําหรับสเปรดชีตนี้ |
getImages() | OverGridImage[] | แสดงผลภาพจากตารางกริดทั้งหมดบนแผ่นงาน |
getIterativeCalculationConvergenceThreshold() | Number | แสดงผลค่าเกณฑ์ที่ใช้ระหว่างการคํานวณซ้ํา |
getLastColumn() | Integer | แสดงผลตําแหน่งของคอลัมน์สุดท้ายที่มีเนื้อหา |
getLastRow() | Integer | แสดงผลตําแหน่งของแถวสุดท้ายที่มีเนื้อหา |
getMaxIterativeCalculationCycles() | Integer | แสดงผลจํานวนการทําซ้ําสูงสุดเพื่อใช้ในระหว่างการคํานวณซ้ํา |
getName() | String | รับชื่อเอกสาร |
getNamedRanges() | NamedRange[] | รับช่วงที่มีชื่อทั้งหมดในสเปรดชีตนี้ |
getNumSheets() | Integer | แสดงผลจํานวนแผ่นงานในสเปรดชีตนี้ |
getOwner() | User | แสดงเจ้าของเอกสารหรือ null สําหรับเอกสารในไดรฟ์ที่แชร์ |
getPredefinedSpreadsheetThemes() | SpreadsheetTheme[] | แสดงผลรายการธีมที่กําหนดไว้ล่วงหน้า |
getProtections(type) | Protection[] | รับอาร์เรย์ของวัตถุที่แสดงช่วงหรือแผ่นงานที่มีการป้องกันทั้งหมดในสเปรดชีต |
getRange(a1Notation) | Range | แสดงผลช่วงที่ระบุในหมายเหตุ A1 หรือ R1C1 |
getRangeByName(name) | Range | แสดงผลช่วงที่มีชื่อ หรือ null หากไม่พบช่วงที่มีชื่อดังกล่าว |
getRangeList(a1Notations) | RangeList | จะแสดงผลคอลเล็กชัน RangeList ที่แสดงช่วงในแผ่นงานเดียวกันที่ระบุโดยรายการที่ไม่หมายเหตุ A1 หรือ R1C1 |
getRecalculationInterval() | RecalculationInterval | แสดงผลช่วงการคํานวณสําหรับสเปรดชีตนี้ |
getRowHeight(rowPosition) | Integer | รับความสูงเป็นพิกเซลของแถวที่ระบุ |
getSelection() | Selection | แสดงผล Selection ปัจจุบันในสเปรดชีต |
getSheetByName(name) | Sheet | แสดงผลแผ่นงานที่มีชื่อที่ระบุ |
getSheetId() | Integer | แสดงผลรหัสของแผ่นงานที่ออบเจ็กต์นี้เป็นตัวแทน |
getSheetName() | String | แสดงผลชื่อแผ่นงาน |
getSheetValues(startRow, startColumn, numRows, numColumns) | Object[][] | แสดงผลตารางสี่เหลี่ยมผืนผ้าสําหรับช่วงนี้โดยเริ่มจากพิกัดที่กําหนด |
getSheets() | Sheet[] | ดาวน์โหลดแผ่นงานทั้งหมดในสเปรดชีตนี้ |
getSpreadsheetLocale() | String | รับภาษาของสเปรดชีต |
getSpreadsheetTheme() | SpreadsheetTheme | แสดงผลธีมปัจจุบันของสเปรดชีต หรือ null หากไม่ได้ใช้ธีม |
getSpreadsheetTimeZone() | String | รับเขตเวลาสําหรับสเปรดชีต |
getUrl() | String | แสดงผล URL สําหรับสเปรดชีตที่ระบุ |
getViewers() | User[] | รับรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ Spreadsheet นี้ |
hideColumn(column) | void | ซ่อนคอลัมน์ที่อยู่ในช่วงที่ระบุ |
hideRow(row) | void | ซ่อนแถวในช่วงที่กําหนด |
insertColumnAfter(afterPosition) | Sheet | แทรกคอลัมน์หลังจากตําแหน่งคอลัมน์ที่ระบุ |
insertColumnBefore(beforePosition) | Sheet | แทรกคอลัมน์หน้าคอลัมน์ที่ต้องการ |
insertColumnsAfter(afterPosition, howMany) | Sheet | แทรกจํานวนคอลัมน์หลังจากตําแหน่งคอลัมน์ที่กําหนด |
insertColumnsBefore(beforePosition, howMany) | Sheet | แทรกจํานวนคอลัมน์ก่อนคอลัมน์ |
insertDataSourceSheet(spec) | DataSourceSheet | แทรก DataSourceSheet ใหม่ในสเปรดชีตและเริ่มการเรียกใช้ข้อมูล |
insertImage(blobSource, column, row) | OverGridImage | แทรก Spreadsheet เป็นรูปภาพในเอกสารในแถวและคอลัมน์ที่ระบุ |
insertImage(blobSource, column, row, offsetX, offsetY) | OverGridImage | แทรก Spreadsheet เป็นรูปภาพในเอกสารในแถวและคอลัมน์ที่ระบุ โดยมีออฟเซ็ตพิกเซล |
insertImage(url, column, row) | OverGridImage | แทรกภาพในเอกสารที่แถวและคอลัมน์ที่กําหนด |
insertImage(url, column, row, offsetX, offsetY) | OverGridImage | แทรกรูปภาพในเอกสารในแถวและคอลัมน์หนึ่งๆ พร้อมออฟเซ็ตพิกเซล |
insertRowAfter(afterPosition) | Sheet | แทรกแถวหลังตําแหน่งแถวที่ระบุ |
insertRowBefore(beforePosition) | Sheet | แทรกแถวก่อนตําแหน่งแถวที่ต้องการ |
insertRowsAfter(afterPosition, howMany) | Sheet | แทรกจํานวนแถวหลังจากตําแหน่งแถวที่ระบุ |
insertRowsBefore(beforePosition, howMany) | Sheet | แทรกจํานวนแถวก่อนตําแหน่งแถวที่ต้องการ |
insertSheet() | Sheet | แทรกแผ่นงานใหม่ในสเปรดชีต โดยใช้ชื่อแผ่นงานเริ่มต้น |
insertSheet(sheetIndex) | Sheet | แทรกแผ่นงานใหม่ลงในสเปรดชีตที่ดัชนีที่ระบุ |
insertSheet(sheetIndex, options) | Sheet | แทรกแผ่นงานใหม่ลงในสเปรดชีตที่ดัชนีที่ระบุและใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ |
insertSheet(options) | Sheet | แทรกแผ่นงานใหม่ลงในสเปรดชีตโดยใช้ชื่อแผ่นงานเริ่มต้นและอาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ |
insertSheet(sheetName) | Sheet | แทรกแผ่นงานใหม่ลงในสเปรดชีตด้วยชื่อที่กําหนด |
insertSheet(sheetName, sheetIndex) | Sheet | แทรกแผ่นงานใหม่ลงในสเปรดชีตด้วยชื่อที่ระบุในดัชนีที่กําหนด |
insertSheet(sheetName, sheetIndex, options) | Sheet | แทรกแผ่นงานใหม่ลงในสเปรดชีตด้วยชื่อที่ระบุในดัชนีที่ระบุและใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ |
insertSheet(sheetName, options) | Sheet | แทรกแผ่นงานใหม่ลงในสเปรดชีตด้วยชื่อที่กําหนดและใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ |
insertSheetWithDataSourceTable(spec) | Sheet | แทรกแผ่นงานใหม่ในสเปรดชีต แล้วสร้าง DataSourceTable ที่ครอบคลุมทั้งแผ่นงานที่มีข้อกําหนดเฉพาะแหล่งข้อมูลที่ระบุ และเริ่มการเรียกใช้ข้อมูล |
isColumnHiddenByUser(columnPosition) | Boolean | แสดงผลว่าผู้ใช้ซ่อนคอลัมน์ที่ระบุหรือไม่ |
isIterativeCalculationEnabled() | Boolean | แสดงผลว่ามีการเปิดใช้งานการคํานวณซ้ําในสเปรดชีตนี้หรือไม่ |
isRowHiddenByFilter(rowPosition) | Boolean | แสดงผลว่าตัวกรองจะซ่อนแถวที่ระบุหรือไม่ (ไม่ใช่มุมมองตัวกรอง) |
isRowHiddenByUser(rowPosition) | Boolean | แสดงผลว่าผู้ใช้ซ่อนแถวที่ระบุหรือไม่ |
moveActiveSheet(pos) | void | ย้ายแผ่นงานที่ใช้งานอยู่ไปยังตําแหน่งที่ระบุในรายการแผ่นงาน |
moveChartToObjectSheet(chart) | Sheet | สร้างชีต SheetType.OBJECT ใหม่และย้ายแผนภูมิที่มีให้ |
refreshAllDataSources() | void | รีเฟรชแหล่งข้อมูลที่สนับสนุนทั้งหมดและออบเจ็กต์แหล่งข้อมูลที่ลิงก์ โดยการข้ามออบเจ็กต์แหล่งข้อมูลที่ไม่ถูกต้อง |
removeEditor(emailAddress) | Spreadsheet | นําผู้ใช้ที่ระบุออกจากรายการผู้แก้ไขสําหรับ Spreadsheet |
removeEditor(user) | Spreadsheet | นําผู้ใช้ที่ระบุออกจากรายการผู้แก้ไขสําหรับ Spreadsheet |
removeMenu(name) | void | นําเมนูที่ addMenu(name, subMenus) เพิ่มไว้ออก |
removeNamedRange(name) | void | ลบช่วงที่ตั้งชื่อแล้วโดยใช้ชื่อที่ระบุ |
removeViewer(emailAddress) | Spreadsheet | นําผู้ใช้ที่ระบุออกจากรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ Spreadsheet |
removeViewer(user) | Spreadsheet | นําผู้ใช้ที่ระบุออกจากรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ Spreadsheet |
rename(newName) | void | เปลี่ยนชื่อเอกสาร |
renameActiveSheet(newName) | void | เปลี่ยนชื่อแผ่นงานที่ใช้งานอยู่ให้เป็นชื่อใหม่ |
resetSpreadsheetTheme() | SpreadsheetTheme | นําธีมที่ใช้อยู่ออกและตั้งค่าธีมเริ่มต้นในสเปรดชีต |
setActiveRange(range) | Range | ตั้งค่าช่วงที่ระบุเป็น active range ในแผ่นงานที่ใช้งาน โดยเซลล์ซ้ายบนสุดในช่วงนั้นเป็น current cell |
setActiveRangeList(rangeList) | RangeList | ตั้งค่ารายการช่วงที่ระบุเป็น active ranges ในแผ่นงานที่ใช้งานอยู่ |
setActiveSelection(range) | Range | ตั้งค่าภูมิภาคที่เลือกที่ใช้งานอยู่สําหรับชีตนี้ |
setActiveSelection(a1Notation) | Range | ตั้งค่ารายการที่เลือกใช้งานตามที่ระบุ รูปแบบ A1 หรือ R1C1 |
setActiveSheet(sheet) | Sheet | ตั้งค่าแผ่นงานที่ระบุให้เป็นแผ่นงานที่ใช้งานอยู่ในสเปรดชีต |
setActiveSheet(sheet, restoreSelection) | Sheet | ตั้งค่าแผ่นงานที่ระบุให้เป็นแผ่นงานที่ใช้งานอยู่ในสเปรดชีต พร้อมตัวเลือกในการคืนค่าการเลือกล่าสุดภายในแผ่นงานนั้น |
setColumnWidth(columnPosition, width) | Sheet | ตั้งค่าความกว้างของคอลัมน์ที่ระบุเป็นพิกเซล |
setCurrentCell(cell) | Range | ตั้งค่าเซลล์ที่ระบุเป็น current cell |
setFrozenColumns(columns) | void | ตรึงจํานวนคอลัมน์ที่ระบุ |
setFrozenRows(rows) | void | ตรึงแถวที่ระบุ |
setIterativeCalculationConvergenceThreshold(minThreshold) | Spreadsheet | ตั้งค่าเกณฑ์ขั้นต่ําสําหรับการคํานวณซ้ํา |
setIterativeCalculationEnabled(isEnabled) | Spreadsheet | ตั้งค่าว่าจะมีการเปิดใช้งานการคํานวณซ้ําในสเปรดชีตนี้หรือไม่ |
setMaxIterativeCalculationCycles(maxIterations) | Spreadsheet | ตั้งค่าจํานวนสูงสุดของการคํานวณซ้ําที่ควรทําในระหว่างการคํานวณแบบวนซ้ํา |
setNamedRange(name, range) | void | ตั้งชื่อช่วง |
setRecalculationInterval(recalculationInterval) | Spreadsheet | ตั้งค่าความถี่ในการคํานวณสเปรดชีตนี้ใหม่ |
setRowHeight(rowPosition, height) | Sheet | ตั้งค่าความสูงของแถวของแถวที่กําหนดเป็นพิกเซล |
setSpreadsheetLocale(locale) | void | ตั้งค่าภาษาของสเปรดชีต |
setSpreadsheetTheme(theme) | SpreadsheetTheme | ตั้งค่าธีมในสเปรดชีต |
setSpreadsheetTimeZone(timezone) | void | ตั้งค่าเขตเวลาของสเปรดชีต |
show(userInterface) | void | แสดงคอมโพเนนต์อินเทอร์เฟซผู้ใช้ที่กําหนดเองในกล่องโต้ตอบจุดกึ่งกลางในมุมมอง เบราว์เซอร์ของผู้ใช้ |
sort(columnPosition) | Sheet | จัดเรียงแผ่นงานตามคอลัมน์จากน้อยไปมาก |
sort(columnPosition, ascending) | Sheet | จัดเรียงแผ่นงานตามคอลัมน์ |
toast(msg) | void | แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีตพร้อมข้อความที่ระบุ |
toast(msg, title) | void | แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีตพร้อมข้อความและชื่อ |
toast(msg, title, timeoutSeconds) | void | แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีต โดยใช้ชื่อและข้อความที่กําหนด ซึ่งยังคงเห็นเป็นระยะเวลาหนึ่ง |
unhideColumn(column) | void | เลิกซ่อนคอลัมน์ในช่วงที่กําหนด |
unhideRow(row) | void | เลิกซ่อนแถวในช่วงที่กําหนด |
updateMenu(name, subMenus) | void | อัปเดตเมนูที่เพิ่มโดย addMenu(name, subMenus) |
waitForAllDataExecutionsCompletion(timeoutInSeconds) | void | รอจนกว่าการดําเนินการปัจจุบันทั้งหมดในสเปรดชีตเสร็จสมบูรณ์ จะหมดเวลาหลังจากจํานวนวินาทีที่ระบุ |
เอกสารโดยละเอียด
addDeveloperMetadata(key)
เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ที่ระบุลงในสเปรดชีตระดับบนสุด
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds the key 'NAME' in the developer metadata for the spreadsheet. ss.addDeveloperMetadata('NAME') // Gets the first developer metadata object and logs its key. const developerMetaData = ss.getDeveloperMetadata()[0] console.log(developerMetaData.getKey())
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สําหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
ขากลับ
Spreadsheet
— สเปรดชีตนี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addDeveloperMetadata(key, visibility)
เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์โดยใช้คีย์ที่ระบุและระดับการเข้าถึงในสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds the key 'NAME' in the developer metadata for the spreadsheet and sets the visibility // to the developer project that created the metadata. ss.addDeveloperMetadata('NAME', SpreadsheetApp.DeveloperMetadataVisibility.PROJECT); // Gets the first developer metadata object and logs its key and visibility setting. const developerMetaData = ss.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log(`Key: ${developerMetaData.getKey()}, . Visibility: ${developerMetaData.getVisibility()}`);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สําหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
visibility | DeveloperMetadataVisibility | ระดับการเข้าถึงข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
ขากลับ
Spreadsheet
— สเปรดชีตนี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addDeveloperMetadata(key, value)
เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์โดยใช้คีย์และค่าที่ระบุในสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds the key 'NAME' and sets the value to 'GOOGLE' in the developer metadata for the // spreadsheet. ss.addDeveloperMetadata('NAME', 'GOOGLE'); // Gets the first developer metadata object and logs its key and value. const developerMetaData = ss.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log(`Key: ${developerMetaData.getKey()}, Value: ${developerMetaData.getValue()}`);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สําหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
value | String | ค่าข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
ขากลับ
Spreadsheet
— สเปรดชีตนี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addDeveloperMetadata(key, value, visibility)
เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ด้วยคีย์ ค่า และระดับการมองเห็นที่เจาะจงไปยังสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds the key 'NAME', sets the value to 'GOOGLE', and sets the visibility // to any developer project with document access. ss.addDeveloperMetadata('NAME', 'GOOGLE', SpreadsheetApp.DeveloperMetadataVisibility.DOCUMENT); // Gets the first developer metadata object and logs its key, value, and visibility setting. const developerMetaData = ss.getDeveloperMetadata()[0]; console.log(`Key: ${developerMetaData.getKey()}, Value: ${developerMetaData.getValue()}, Visibility: ${developerMetaData.getVisibility()}`);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สําหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
value | String | ค่าข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
visibility | DeveloperMetadataVisibility | ระดับการเข้าถึงข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
ขากลับ
Spreadsheet
— สเปรดชีตนี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addEditor(emailAddress)
เพิ่มผู้ใช้ที่ต้องการลงในรายการเครื่องมือแก้ไขของ Spreadsheet
หากผู้ใช้อยู่ในรายการผู้ชมแล้ว
วิธีนี้จะทําให้ผู้ใช้ไม่ได้อยู่ในรายการผู้ดู
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
emailAddress | String | ที่อยู่อีเมลของผู้ใช้ที่จะเพิ่ม |
ขากลับ
Spreadsheet
— Spreadsheet
นี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addEditor(user)
เพิ่มผู้ใช้ที่ต้องการลงในรายการเครื่องมือแก้ไขของ Spreadsheet
หากผู้ใช้อยู่ในรายการผู้ชมแล้ว
วิธีนี้จะทําให้ผู้ใช้ไม่ได้อยู่ในรายการผู้ดู
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะเพิ่ม |
ขากลับ
Spreadsheet
— Spreadsheet
นี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addEditors(emailAddresses)
เพิ่มอาร์เรย์ผู้ใช้ที่ระบุลงในรายการผู้แก้ไขสําหรับ Spreadsheet
หากผู้ใช้คนใดคนหนึ่งอยู่ในรายการผู้ชมแล้ว วิธีนี้โปรโมตพวกเขาจากรายการผู้ชม
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
emailAddresses | String[] | อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม |
ขากลับ
Spreadsheet
— Spreadsheet
นี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addMenu(name, subMenus)
สร้างเมนูใหม่ใน UI ของสเปรดชีต
แต่ละรายการเมนูจะเรียกใช้ฟังก์ชันที่ผู้ใช้กําหนด โดยทั่วไปแล้ว คุณต้องการเรียกใช้จากฟังก์ชัน onOpen()
เพื่อให้ระบบสร้างเมนูโดยอัตโนมัติเมื่อโหลดสเปรดชีต
// The onOpen function is executed automatically every time a Spreadsheet is loaded function onOpen() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var menuEntries = []; // When the user clicks on "addMenuExample" then "Menu Entry 1", the function function1 is // executed. menuEntries.push({name: "Menu Entry 1", functionName: "function1"}); menuEntries.push(null); // line separator menuEntries.push({name: "Menu Entry 2", functionName: "function2"}); ss.addMenu("addMenuExample", menuEntries); }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อของเมนูที่จะสร้าง |
subMenus | Object[] | อาร์เรย์ของแผนที่ JavaScript ที่มีพารามิเตอร์ name และ functionName
คุณใช้ฟังก์ชันจากไลบรารีที่ใช้ร่วมกันได้ เช่น
Library.libFunction1 |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addViewer(emailAddress)
เพิ่มผู้ใช้ที่ต้องการลงในรายการผู้ชมสําหรับ Spreadsheet
หากผู้ใช้อยู่ในรายชื่อผู้แก้ไข
แล้ว เมธอดนี้จะไม่ส่งผลใดๆ
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
emailAddress | String | ที่อยู่อีเมลของผู้ใช้ที่จะเพิ่ม |
ขากลับ
Spreadsheet
— Spreadsheet
นี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addViewer(user)
เพิ่มผู้ใช้ที่ต้องการลงในรายการผู้ชมสําหรับ Spreadsheet
หากผู้ใช้อยู่ในรายชื่อผู้แก้ไข
แล้ว เมธอดนี้จะไม่ส่งผลใดๆ
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะเพิ่ม |
ขากลับ
Spreadsheet
— Spreadsheet
นี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addViewers(emailAddresses)
เพิ่มอาร์เรย์ผู้ใช้ที่ระบุลงในรายการผู้ชมสําหรับ Spreadsheet
หากผู้ใช้คนใดคนหนึ่งอยู่ในรายการผู้แก้ไขอยู่แล้ว วิธีนี้จะไม่มีผลใดๆ
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
emailAddresses | String[] | อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม |
ขากลับ
Spreadsheet
— Spreadsheet
นี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
appendRow(rowContents)
เพิ่มแถวมาด้านล่างของเขตข้อมูลปัจจุบันในชีต
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Appends a new row with 3 columns to the bottom of the current // data region in the sheet containing the values in the array. sheet.appendRow(["a man", "a plan", "panama"]);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
rowContents | Object[] | อาร์เรย์ของค่าที่จะแทรกหลังแถวสุดท้ายในแผ่นงาน |
ขากลับ
Sheet
— ชีตซึ่งมีประโยชน์ในการเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
autoResizeColumn(columnPosition)
ตั้งค่าความกว้างของคอลัมน์ที่ระบุให้พอดีกับเนื้อหา
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; sheet.getRange('a1').setValue('Whenever it is a damp, drizzly November in my soul...'); // Sets the first column to a width which fits the text sheet.autoResizeColumn(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
columnPosition | Integer | ตําแหน่งของคอลัมน์ที่ต้องการปรับขนาด |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
copy(name)
คัดลอกสเปรดชีตและส่งคืนสเปรดชีตใหม่
// This code makes a copy of the current spreadsheet and names it appropriately var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.copy("Copy of " + ss.getName());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อของสําเนา |
ขากลับ
Spreadsheet
— สเปรดชีตนี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
createDeveloperMetadataFinder()
แสดงผล DeveloperMetadataFinder
สําหรับการค้นหาข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ภายในขอบเขตของสเปรดชีตนี้ โดยค่าเริ่มต้น ข้อมูลเมตาทั้งหมดจะเชื่อมโยงกับสเปรดชีต ชีต
แถว และคอลัมน์
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds developer metadata to the spreadsheet. ss.addDeveloperMetadata('NAME', 'CHARLIE'); ss.addDeveloperMetadata('COMPANY', 'EXAMPLE ORGANIZATION'); ss.addDeveloperMetadata('TECHNOLOGY', 'JAVASCRIPT'); // Creates a developer metadata finder. const developerMetadataFinder = ss.createDeveloperMetadataFinder(); // Finds the developer metadata objects with 'COMPANY' as the key. const googleMetadataFromSpreadsheet = developerMetadataFinder.withKey('COMPANY').find(); // Gets the first result of developer metadata that has the key 'COMPANY' and logs its value. console.log(googleMetadataFromSpreadsheet[0].getValue());
ขากลับ
DeveloperMetadataFinder
— เครื่องมือค้นหาข้อมูลเมตาสําหรับนักพัฒนาซอฟต์แวร์เพื่อค้นหาข้อมูลเมตาที่อยู่ในขอบเขตของสเปรดชีตนี้
createTextFinder(findText)
สร้างเครื่องมือค้นหาข้อความสําหรับสเปรดชีต ซึ่งสามารถใช้ค้นหาและแทนที่ข้อความภายในสเปรดชีตได้ การค้นหาจะเริ่มต้นจากแผ่นงานแรกของสเปรดชีต
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // Creates a text finder. var textFinder = spreadsheet.createTextFinder('dog'); // Returns the first occurrence of 'dog' in the spreadsheet. var firstOccurrence = textFinder.findNext(); // Replaces the last found occurrence of 'dog' with 'cat' and returns the number // of occurrences replaced. var numOccurrencesReplaced = findOccurrence.replaceWith('cat');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
findText | String | ข้อความที่จะค้นหา |
ขากลับ
TextFinder
— TextFinder
ของสเปรดชีต
deleteActiveSheet()
ลบแผ่นงานที่ใช้งานอยู่
// The code below deletes the currently active sheet and stores the new active sheet in a // variable var newSheet = SpreadsheetApp.getActiveSpreadsheet().deleteActiveSheet();
ขากลับ
Sheet
— แผ่นงานใหม่ที่ใช้งาน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
deleteColumn(columnPosition)
ลบคอลัมน์ในตําแหน่งคอลัมน์ที่ระบุ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Columns start at "1" - this deletes the first column sheet.deleteColumn(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
columnPosition | Integer | ตําแหน่งของคอลัมน์ เริ่มต้นที่ 1 สําหรับคอลัมน์แรก |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
deleteColumns(columnPosition, howMany)
ลบคอลัมน์จํานวนหนึ่งโดยเริ่มที่ตําแหน่งคอลัมน์ที่ระบุ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Columns start at "1" - this deletes the first two columns sheet.deleteColumns(1, 2);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
columnPosition | Integer | ตําแหน่งของคอลัมน์แรกที่จะลบ |
howMany | Integer | จํานวนคอลัมน์ที่จะลบ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
deleteRow(rowPosition)
ลบแถวที่ตําแหน่งแถวที่ระบุ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Rows start at "1" - this deletes the first row sheet.deleteRow(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
rowPosition | Integer | ตําแหน่งของแถว เริ่มต้นที่ 1 สําหรับแถวแรก |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
deleteRows(rowPosition, howMany)
ลบแถวจํานวนหนึ่งโดยเริ่มที่ตําแหน่งแถวที่ระบุ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Rows start at "1" - this deletes the first two rows sheet.deleteRows(1, 2);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
rowPosition | Integer | ตําแหน่งของแถวแรกที่จะลบ |
howMany | Integer | จํานวนแถวที่จะลบ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
deleteSheet(sheet)
ลบแผ่นงานที่ระบุ
// The code below deletes the specified sheet. var ss = SpreadsheetApp.getActive(); var sheet = ss.getSheetByName('My Sheet'); ss.deleteSheet(sheet);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | Sheet | แผ่นงานที่จะลบ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
duplicateActiveSheet()
ทําสําเนาแผ่นงานที่ใช้งานอยู่ให้เป็นแผ่นงานที่ใช้งานอยู่
// The code below makes a duplicate of the active sheet SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();
ขากลับ
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getActiveCell()
แสดงผลเซลล์ที่มีการใช้งานในแผ่นงานนี้
หมายเหตุ: ควรใช้ getCurrentCell()
ซึ่งแสดงผลเซลล์ที่ไฮไลต์ในปัจจุบัน
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Returns the active cell var cell = sheet.getActiveCell();
ขากลับ
Range
— เซลล์ที่กําลังใช้งานอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getActiveRange()
แสดงผลช่วงที่เลือกในแผ่นงานที่ทํางานอยู่ หรือ null
หากไม่มีช่วงที่มีการใช้งาน หากเลือกหลายช่วง วิธีนี้จะแสดงเฉพาะช่วงที่เลือกล่าสุดเท่านั้น
คําว่า "ช่วงที่มีการใช้งาน" หมายถึงช่วงที่ผู้ใช้เลือกในแผ่นงานที่ใช้งานอยู่ แต่ในฟังก์ชันที่กําหนดเอง จะเป็นการอ้างถึงเซลล์ที่มีการคํานวณใหม่อยู่ในขณะนั้น
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var activeRange = sheet.getActiveRange();
ขากลับ
Range
— ช่วงที่มีการใช้งานอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
ดูเพิ่มเติม
getActiveRangeList()
แสดงรายการช่วงที่ใช้งานอยู่ในแผ่นงานที่มีการใช้งานหรือ null
หากไม่มีช่วงที่ทํางานอยู่
หากมีการเลือกช่วงเดียว การทํางานนี้จะถือว่าเป็นการเรียก getActiveRange()
var sheet = SpreadsheetApp.getActiveSheet(); // Returns the list of active ranges. var activeRangeList = sheet.getActiveRangeList();
ขากลับ
RangeList
— รายการช่วงที่มีการใช้งาน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
ดูเพิ่มเติม
getActiveSheet()
ดาวน์โหลดชีตที่ใช้งานอยู่ในสเปรดชีต
แผ่นงานที่ใช้งานอยู่ในสเปรดชีตคือแผ่นงานที่แสดงอยู่ใน UI ของสเปรดชีต
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
ขากลับ
Sheet
— แผ่นงานที่ใช้งานอยู่ในสเปรดชีต
getAs(contentType)
ส่งคืนข้อมูลภายในออบเจ็กต์นี้เป็น Blob ที่แปลงเป็นประเภทเนื้อหาที่ระบุ วิธีนี้เพิ่มส่วนขยายที่เหมาะสมลงในชื่อไฟล์ เช่น "myfile.pdf" อย่างไรก็ตามมีการสันนิษฐานว่าส่วนของชื่อไฟล์ที่ตามหลังเครื่องหมายจุดสุดท้าย (ถ้ามี) คือส่วนขยายที่มีอยู่ซึ่งควรแทนที่ ดังนั้น "ShoppingList.12.25.2014" จะกลายเป็น "ShoppingList.12.25.pdf"
หากต้องการดูโควต้า Conversion รายวัน โปรดดูโควต้าสําหรับบริการของ Google โดเมน Google Workspace ที่สร้างขึ้นใหม่อาจขึ้นอยู่กับโควต้าชั่วคราว
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
contentType | String | ประเภท MIME ที่จะแปลงเป็น สําหรับ Blob ส่วนใหญ่ 'application/pdf' เป็นตัวเลือกเดียวที่ใช้ได้ สําหรับรูปภาพในรูปแบบ BMP, GIF, JPEG หรือ PNG จะสามารถใช้ 'image/bmp' , 'image/gif' , 'image/jpeg' หรือ 'image/png' ได้ |
ขากลับ
Blob
— ข้อมูลในรูปแบบ BLOB
getBandings()
แสดงค่าขอบเขตทั้งหมดในสเปรดชีตนี้
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets an array of the bandings in the spreadsheet. const bandings = ss.getBandings(); // Logs the range of the first banding in the spreadsheet to the console. console.log(bandings[0].getRange().getA1Notation());
ขากลับ
Banding[]
- สีกลุ่มในสเปรดชีตนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getBlob()
getColumnWidth(columnPosition)
รับความกว้างเป็นพิกเซลของคอลัมน์ที่ระบุ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Columns start at 1 Logger.log(sheet.getColumnWidth(1));
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
columnPosition | Integer | ตําแหน่งของคอลัมน์ที่จะตรวจสอบ |
ขากลับ
Integer
— ความกว้างของคอลัมน์เป็นพิกเซล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getCurrentCell()
แสดงผลเซลล์ปัจจุบันในแผ่นงานที่ใช้อยู่ หรือ null
ถ้าไม่มีเซลล์ปัจจุบัน เซลล์ปัจจุบันคือเซลล์ที่โฟกัสใน UI ของ Google ชีต และจะไฮไลต์ด้วยเส้นขอบสีเข้ม ต้องมีเซลล์ปัจจุบันไม่เกิน 1 เซลล์ เมื่อผู้ใช้เลือกช่วงของเซลล์อย่างน้อย 1 ช่วง
เซลล์ใดเซลล์หนึ่งในเซลล์ที่เลือกไว้จะเป็นเซลล์ปัจจุบัน
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // Returns the current highlighted cell in the one of the active ranges. var currentCell = sheet.getCurrentCell();
ขากลับ
Range
— เซลล์ปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataRange()
แสดงผล Range
ที่สอดคล้องกับมิติข้อมูลที่มีข้อมูลอยู่
ฟังก์ชันนี้จะเทียบเท่ากับการสร้างช่วงตามที่กําหนดโดย A1 และ (Sheet.getLastColumn(), Sheet.getLastRow())
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This represents ALL the data var range = sheet.getDataRange(); var values = range.getValues(); // This logs the spreadsheet in CSV format with a trailing comma for (var i = 0; i < values.length; i++) { var row = ""; for (var j = 0; j < values[i].length; j++) { if (values[i][j]) { row = row + values[i][j]; } row = row + ","; } Logger.log(row); }
ขากลับ
Range
— ช่วงที่ประกอบด้วยข้อมูลทั้งหมดในสเปรดชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceFormulas()
รับสูตรแหล่งข้อมูลทั้งหมด
// Opens the spreadsheet by its ID. If you created your script from within a Google Sheets // file, use SpreadsheetApp.getActiveSpreadsheet(). // TODO(developer): Replace the ID with your own. const ss = SpreadsheetApp.openById('abc123456'); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets an array of the data source formulas on Sheet1. // To get an array of data source formulas for the entire spreadsheet, // replace 'sheet' with 'ss'. const dataSourceFormulas = sheet.getDataSourceFormulas(); // Logs the first data source formula in the array. console.log(dataSourceFormulas[0].getFormula());
ขากลับ
DataSourceFormula[]
— รายการสูตรแหล่งข้อมูล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourcePivotTables()
รับตาราง Pivot ของแหล่งข้อมูลทั้งหมด
// Opens the spreadsheet file by its ID. If you created your script from a Google Sheets file, // use SpreadsheetApp.getActiveSpreadsheet(). // TODO(developer): Replace the ID with your own. const ss = SpreadsheetApp.openById('abc123456'); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets an array of the data source pivot tables on Sheet1. // To get an array of data source pivot tables for the entire // spreadsheet, replace 'sheet' with 'ss'. const dataSourcePivotTables = sheet.getDataSourcePivotTables(); // Logs the last time that the first pivot table in the array was refreshed. console.log(dataSourcePivotTables[0].getStatus().getLastRefreshedTime());
ขากลับ
DataSourcePivotTable[]
— รายการตาราง Pivot ของแหล่งข้อมูล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceRefreshSchedules()
ดูกําหนดการรีเฟรชของสเปรดชีตนี้
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Activates BigQuery operations for the connected spreadsheet. SpreadsheetApp.enableBigQueryExecution(); // Gets the frequency type of the first referesh schedule in the array. const frequencyType = ss.getDataSourceRefreshSchedules()[0] .getFrequency() .getFrequencyType() .toString(); // Logs the frequency type to the console. console.log(frequencyType);
ขากลับ
DataSourceRefreshSchedule[]
— กําหนดเวลาการรีเฟรชของสเปรดชีตนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceSheets()
แสดงผลแผ่นงานแหล่งข้อมูลทั้งหมดในสเปรดชีต
// Turns data execution on for BigQuery data sources. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets the first data source sheet in the spreadsheet. const dataSource = ss.getDataSourceSheets()[0]; // Gets the name of the data source sheet. console.log(dataSource.asSheet().getName());
ขากลับ
DataSourceSheet[]
— อาร์เรย์ของชีตแหล่งข้อมูลทั้งหมด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceTables()
รับตารางแหล่งข้อมูลทั้งหมด
// Opens the spreadsheet file by its ID. If you created your script from a Google Sheets file, // use SpreadsheetApp.getActiveSpreadsheet(). // TODO(developer): Replace the ID with your own. const ss = SpreadsheetApp.openById('abc123456'); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets an array of data source tables on Sheet1. // To get an array of data source tables for the entire spreadsheet, // replace 'sheet' with 'ss'. const dataSourceTables = sheet.getDataSourceTables(); // Logs the last completed data execution time on the first data source table. console.log(dataSourceTables[0].getStatus().getLastExecutionTime());
ขากลับ
DataSourceTable[]
— รายการตารางแหล่งข้อมูล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSources()
แสดงแหล่งข้อมูลทั้งหมดในสเปรดชีต
// Turns data execution on for BigQuery data sources. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets the data sources on the spreadsheet. const dataSources = ss.getDataSources(); // Logs the name of the first column on the first data source. console.log(dataSources[0].getColumns()[0].getName());
ขากลับ
DataSource[]
— อาร์เรย์ของแหล่งข้อมูลทั้งหมด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDeveloperMetadata()
รับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่เชื่อมโยงกับสเปรดชีตระดับบนสุด
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds 'Google' as a key to the spreadsheet metadata. ss.addDeveloperMetadata('Google'); // Gets the spreadsheet's metadata. const ssMetadata = ss.getDeveloperMetadata(); // Gets the first set of the spreadsheet's metadata and logs the key to the console. console.log(ssMetadata[0].getKey());
ขากลับ
DeveloperMetadata[]
— ข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่เชื่อมโยงกับช่วงนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getEditors()
รับรายชื่อผู้แก้ไขสําหรับ Spreadsheet
นี้
ขากลับ
User[]
— อาร์เรย์ของผู้ใช้ที่มีสิทธิ์แก้ไข
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFormUrl()
แสดงผล URL สําหรับฟอร์มที่ส่งการตอบกลับไปยังสเปรดชีตนี้ หรือ null
ถ้าสเปรดชีตนี้ไม่มีฟอร์มที่เชื่อมโยง ถ้าฟอร์มหลายรายการส่งการตอบกลับไปยังสเปรดชีตนี้
URL ของฟอร์มที่ส่งกลับจะไม่ชัดเจน หรืออีกทางเลือกหนึ่งคือ การเรียกการเชื่อมโยง URL ของฟอร์มต่อแผ่นงานสามารถดึงข้อมูลผ่านเมธอด Sheet.getFormUrl()
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets the form URL from the spreadsheet. const formUrl = ss.getFormUrl(); // Logs the form URL to the console. console.log(formUrl);
ขากลับ
String
— URL สําหรับแบบฟอร์มที่วางการตอบกลับในสเปรดชีตนี้ หรือ null
หากสเปรดชีตนี้ไม่มีแบบฟอร์มที่เชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFrozenColumns()
แสดงผลจํานวนคอลัมน์ที่ตรึงไว้
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; Logger.log("Number of frozen columns: %s", sheet.getFrozenColumns());
ขากลับ
Integer
— จํานวนคอลัมน์ที่ตรึงไว้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFrozenRows()
แสดงผลจํานวนแถวที่ตรึง
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; Logger.log("Number of frozen rows: %s", sheet.getFrozenRows());
ขากลับ
Integer
— จํานวนแถวที่ตรึง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getId()
รับตัวระบุที่ไม่ซ้ํากันสําหรับสเปรดชีตนี้ สามารถดึงรหัสสเปรดชีตจาก URL เช่น รหัสสเปรดชีตใน URL https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 คือ "abc1234567"
// The code below logs the ID for the active spreadsheet. Logger.log(SpreadsheetApp.getActiveSpreadsheet().getId());
ขากลับ
String
— รหัสที่ไม่ซ้ํากัน (หรือคีย์) ของสเปรดชีต
getImages()
แสดงผลภาพจากตารางกริดทั้งหมดบนแผ่นงาน
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets the over-the-grid images from Sheet1. // To get the over-the-grid images from the entire spreadsheet, use ss.getImages() instead. const images = sheet.getImages(); // For each image, logs the anchor cell in A1 notation. for (const image of images) { console.log(image.getAnchorCell().getA1Notation()); }
ขากลับ
OverGridImage[]
— อาร์เรย์ของภาพเหนือตาราง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getIterativeCalculationConvergenceThreshold()
แสดงผลค่าเกณฑ์ที่ใช้ระหว่างการคํานวณซ้ํา เมื่อผลลัพธ์ของการคํานวณแบบต่อเนื่อง น้อยกว่าค่านี้ การคํานวณแบบวนซ้ําจะหยุดลง
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the iterative calculation convergence threshold for the spreadsheet. ss.setIterativeCalculationConvergenceThreshold(2); // Logs the threshold to the console. console.log(ss.getIterativeCalculationConvergenceThreshold());
ขากลับ
Number
— เกณฑ์การบรรจบกัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getLastColumn()
แสดงผลตําแหน่งของคอลัมน์สุดท้ายที่มีเนื้อหา
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This logs the value in the very last cell of this sheet var lastRow = sheet.getLastRow(); var lastColumn = sheet.getLastColumn(); var lastCell = sheet.getRange(lastRow, lastColumn); Logger.log(lastCell.getValue());
ขากลับ
Integer
— คอลัมน์สุดท้ายของชีตที่มีเนื้อหา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getLastRow()
แสดงผลตําแหน่งของแถวสุดท้ายที่มีเนื้อหา
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This logs the value in the very last cell of this sheet var lastRow = sheet.getLastRow(); var lastColumn = sheet.getLastColumn(); var lastCell = sheet.getRange(lastRow, lastColumn); Logger.log(lastCell.getValue());
ขากลับ
Integer
— แถวสุดท้ายของชีตที่มีเนื้อหา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getMaxIterativeCalculationCycles()
แสดงผลจํานวนการทําซ้ําสูงสุดเพื่อใช้ในระหว่างการคํานวณซ้ํา
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the max iterative calculation cycles for the spreadsheet. ss.setMaxIterativeCalculationCycles(10); // Logs the max iterative calculation cycles to the console. console.log(ss.getMaxIterativeCalculationCycles());
ขากลับ
Integer
— จํานวนสูงสุดของการคํานวณซ้ํา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getName()
รับชื่อเอกสาร
var ss = SpreadsheetApp.getActiveSpreadsheet(); Logger.log(ss.getName());
ขากลับ
String
— ชื่อของสเปรดชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getNamedRanges()
รับช่วงที่มีชื่อทั้งหมดในสเปรดชีตนี้
// The code below logs the name of the first named range. var namedRanges = SpreadsheetApp.getActiveSpreadsheet().getNamedRanges(); for (var i = 0; i < namedRanges.length; i++) { Logger.log(namedRanges[i].getName()); }
ขากลับ
NamedRange[]
— อาร์เรย์ของช่วงที่มีชื่อทั้งหมดในสเปรดชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getNumSheets()
แสดงผลจํานวนแผ่นงานในสเปรดชีตนี้
// The code below logs the number of sheets in the active spreadsheet. Logger.log(SpreadsheetApp.getActiveSpreadsheet().getNumSheets());
ขากลับ
Integer
— จํานวนแผ่นงานในสเปรดชีต
getOwner()
แสดงเจ้าของเอกสารหรือ null
สําหรับเอกสารในไดรฟ์ที่แชร์
var ss = SpreadsheetApp.getActiveSpreadsheet(); var owner = ss.getOwner(); Logger.log(owner.getEmail());
ขากลับ
User
— เจ้าของเอกสาร หรือ null
หากเอกสารอยู่ในไดรฟ์ที่แชร์
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getPredefinedSpreadsheetThemes()
แสดงผลรายการธีมที่กําหนดไว้ล่วงหน้า
// The code below returns the list of predefined themes. var predefinedThemesList = SpreadsheetApp.getActiveSpreadsheet() .getPredefinedSpreadsheetThemes();
ขากลับ
SpreadsheetTheme[]
— รายการธีมที่กําหนดไว้ล่วงหน้า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getProtections(type)
รับอาร์เรย์ของวัตถุที่แสดงช่วงหรือแผ่นงานที่มีการป้องกันทั้งหมดในสเปรดชีต
// Remove all range protections in the spreadsheet that the user has permission to edit. var ss = SpreadsheetApp.getActive(); var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE); for (var i = 0; i < protections.length; i++) { var protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
// Remove all sheet protections in the spreadsheet that the user has permission to edit. var ss = SpreadsheetApp.getActive(); var protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET); for (var i = 0; i < protections.length; i++) { var protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
type | ProtectionType | ประเภทของพื้นที่ที่ได้รับการปกป้อง ซึ่งอาจเป็น SpreadsheetApp.ProtectionType.RANGE หรือ SpreadsheetApp.ProtectionType.SHEET |
ขากลับ
Protection[]
— อาร์เรย์ของวัตถุที่แสดงช่วงหรือแผ่นงานที่มีการป้องกันทั้งหมดในสเปรดชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRange(a1Notation)
แสดงผลช่วงที่ระบุในหมายเหตุ A1 หรือ R1C1
// Get a range A1:D4 on sheet titled "Invoices" var ss = SpreadsheetApp.getActiveSpreadsheet(); var range = ss.getRange("Invoices!A1:D4"); // Get cell A1 on the first sheet var sheet = ss.getSheets()[0]; var cell = sheet.getRange("A1");
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
a1Notation | String | ช่วงที่จะส่งคืน ตามที่ระบุในรูปแบบ A1 หรือ R1C1 |
ขากลับ
Range
— ช่วงตามตําแหน่งที่กําหนดไว้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRangeByName(name)
แสดงผลช่วงที่มีชื่อ หรือ null
หากไม่พบช่วงที่มีชื่อดังกล่าว หากแผ่นงานหลายสเปรดชีตใช้ชื่อช่วงเดียวกัน ให้ระบุชื่อแผ่นงานโดยไม่มีเครื่องหมายอัญประกาศเพิ่มเติม เช่น getRangeByName('TaxRates')
หรือ getRangeByName('Sheet Name!TaxRates')
แต่ไม่ใช่ getRangeByName('"Sheet
Name"!TaxRates')
// Log the number of columns for the range named 'TaxRates' in the active spreadsheet. var range = SpreadsheetApp.getActiveSpreadsheet().getRangeByName('TaxRates'); if (range != null) { Logger.log(range.getNumColumns()); }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อของช่วงที่จะรับ |
ขากลับ
Range
— ช่วงของเซลล์ที่มีชื่อที่ระบุ
getRangeList(a1Notations)
จะแสดงผลคอลเล็กชัน RangeList
ที่แสดงช่วงในแผ่นงานเดียวกันที่ระบุโดยรายการที่ไม่หมายเหตุ A1 หรือ R1C1
// Get a list of ranges A1:D4, F1:H4. var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var rangeList = sheet.getRangeList(['A1:D4', 'F1:H4']);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
a1Notations | String[] | รายการช่วงที่จะแสดง ตามที่ระบุไว้ในรูปแบบ A1 หรือ R1C1 |
ขากลับ
RangeList
— รายการช่วงตามตําแหน่งที่ตั้งที่กําหนด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRecalculationInterval()
แสดงผลช่วงการคํานวณสําหรับสเปรดชีตนี้
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Logs the calculation interval for the spreadsheet to the console. console.log(ss.getRecalculationInterval().toString());
ขากลับ
RecalculationInterval
— ช่วงการคํานวณสําหรับสเปรดชีตนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRowHeight(rowPosition)
รับความสูงเป็นพิกเซลของแถวที่ระบุ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Rows start at 1 Logger.log(sheet.getRowHeight(1));
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
rowPosition | Integer | ตําแหน่งของแถวที่จะตรวจสอบ |
ขากลับ
Integer
— ความสูงของแถวเป็นพิกเซล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSelection()
แสดงผล Selection
ปัจจุบันในสเปรดชีต
var selection = SpreadsheetApp.getActiveSpreadsheet().getSelection(); var currentCell = selection.getCurrentCell();
ขากลับ
Selection
— การเลือกในปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSheetByName(name)
แสดงผลแผ่นงานที่มีชื่อที่ระบุ
หากแผ่นงานหลายแผ่นมีชื่อเดียวกัน ระบบจะแสดงผลแผ่นงานซ้ายสุด แสดงผล null
ถ้าไม่มีแผ่นงานที่มีชื่อดังกล่าว
// The code below logs the index of a sheet named "Expenses" var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Expenses"); if (sheet != null) { Logger.log(sheet.getIndex()); }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อของแผ่นงานที่จะรับ |
ขากลับ
Sheet
— แผ่นงานที่มีชื่อที่กําหนด
getSheetId()
แสดงผลรหัสของแผ่นงานที่ออบเจ็กต์นี้เป็นตัวแทน
นี่คือรหัสของแผ่นงานที่ไม่ซ้ํากันในสเปรดชีต รหัสคือจํานวนเต็มที่เพิ่มขึ้นทีละตัวซึ่งกําหนด ณ เวลาที่สร้างแผ่นงานซึ่งไม่เกี่ยวข้องกับตําแหน่งในแผ่นงาน การดําเนินการนี้มีประโยชน์ในการใช้ร่วมกับเมธอดอย่างเช่น Range.copyFormatToRange(gridId, column, columnEnd, row, rowEnd)
ที่ใช้พารามิเตอร์ gridId
แทนอินสแตนซ์ Sheet
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; Logger.log(sheet.getSheetId());
ขากลับ
Integer
— รหัสของแผ่นงานที่ไม่ซ้ํากันในสเปรดชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSheetName()
แสดงผลชื่อแผ่นงาน
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; Logger.log(sheet.getSheetName());
ขากลับ
String
— ชื่อของชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSheetValues(startRow, startColumn, numRows, numColumns)
แสดงผลตารางสี่เหลี่ยมผืนผ้าสําหรับช่วงนี้โดยเริ่มจากพิกัดที่กําหนด ค่า -1 ที่ระบุเป็นตําแหน่งแถวหรือคอลัมน์จะเท่ากับการได้แถวหรือคอลัมน์สุดท้ายที่มีข้อมูลในแผ่นงาน
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // The two samples below produce the same output var values = sheet.getSheetValues(1, 1, 3, 3); Logger.log(values); var range = sheet.getRange(1, 1, 3, 3); values = range.getValues(); Logger.log(values);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
startRow | Integer | ตําแหน่งของแถวเริ่มต้น |
startColumn | Integer | ตําแหน่งของคอลัมน์เริ่มต้น |
numRows | Integer | จํานวนแถวที่จะแสดงผลค่า |
numColumns | Integer | จํานวนคอลัมน์ที่จะแสดงผลค่า |
ขากลับ
Object[][]
— อาร์เรย์ของค่าสองมิติ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSheets()
ดาวน์โหลดแผ่นงานทั้งหมดในสเปรดชีตนี้
// The code below logs the name of the second sheet var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets(); if (sheets.length > 1) { Logger.log(sheets[1].getName()); }
ขากลับ
Sheet[]
— อาร์เรย์ของแผ่นงานทั้งหมดในสเปรดชีต
getSpreadsheetLocale()
รับภาษาของสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets the spreadsheet locale. const ssLocale = ss.getSpreadsheetLocale(); // Logs the locale to the console. console.log(ssLocale);
ขากลับ
String
— ภาษาของสเปรดชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSpreadsheetTheme()
แสดงผลธีมปัจจุบันของสเปรดชีต หรือ null
หากไม่ได้ใช้ธีม
// The code below returns the current theme of the spreadsheet. var currentTheme = SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTheme();
ขากลับ
SpreadsheetTheme
— ธีมที่ใช้อยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSpreadsheetTimeZone()
รับเขตเวลาสําหรับสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the time zone of the spreadsheet. ss.setSpreadsheetTimeZone('America/New_York'); // Gets the time zone of the spreadsheet. const ssTimeZone = ss.getSpreadsheetTimeZone(); // Logs the time zone to the console. console.log(ssTimeZone);
ขากลับ
String
— เขตเวลาที่ระบุในรูปแบบ "long" (เช่น "America/New_York" ตามที่ระบุไว้โดย Joda.org)
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getUrl()
แสดงผล URL สําหรับสเปรดชีตที่ระบุ
var ss = SpreadsheetApp.getActiveSpreadsheet(); Logger.log(ss.getUrl());
ขากลับ
String
— URL สําหรับสเปรดชีตที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getViewers()
รับรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ Spreadsheet
นี้
ขากลับ
User[]
— อาร์เรย์ของผู้ใช้ที่มีสิทธิ์ดูหรือแสดงความคิดเห็น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
hideColumn(column)
ซ่อนคอลัมน์ที่อยู่ในช่วงที่ระบุ
let ss = SpreadsheetApp.getActiveSpreadsheet(); let sheet = ss.getSheets()[0]; // This hides the first column let range = sheet.getRange("A1"); sheet.hideColumn(range); // This hides the first 3 columns let range = sheet.getRange("A:C"); sheet.hideColumn(range);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Range | ช่วงคอลัมน์ที่จะซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
hideRow(row)
ซ่อนแถวในช่วงที่กําหนด
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This hides the first row var range = sheet.getRange("A1"); sheet.hideRow(range);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Range | ช่วงแถวที่จะซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertColumnAfter(afterPosition)
แทรกคอลัมน์หลังจากตําแหน่งคอลัมน์ที่ระบุ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts a column after the first column position sheet.insertColumnAfter(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
afterPosition | Integer | คอลัมน์หลังจากนั้นควรเพิ่มคอลัมน์ใหม่ |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertColumnBefore(beforePosition)
แทรกคอลัมน์หน้าคอลัมน์ที่ต้องการ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts a column in the first column position sheet.insertColumnBefore(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
beforePosition | Integer | คอลัมน์ก่อนหน้าที่ควรเพิ่มคอลัมน์ใหม่ |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertColumnsAfter(afterPosition, howMany)
แทรกจํานวนคอลัมน์หลังจากตําแหน่งคอลัมน์ที่กําหนด
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts a column in the second column position sheet.insertColumnsAfter(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
afterPosition | Integer | คอลัมน์หลังจากนั้นควรเพิ่มคอลัมน์ใหม่ |
howMany | Integer | จํานวนคอลัมน์ที่จะแทรก |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertColumnsBefore(beforePosition, howMany)
แทรกจํานวนคอลัมน์ก่อนคอลัมน์
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts five columns before the first column sheet.insertColumnsBefore(1, 5);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
beforePosition | Integer | คอลัมน์ก่อนหน้าที่ควรเพิ่มคอลัมน์ใหม่ |
howMany | Integer | จํานวนคอลัมน์ที่จะแทรก |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertDataSourceSheet(spec)
แทรก DataSourceSheet
ใหม่ในสเปรดชีตและเริ่มการเรียกใช้ข้อมูล ซึ่งจะทําให้แผ่นงานใหม่เป็นแผ่นงานที่ใช้งานอยู่ด้วย
สร้างข้อยกเว้นหากไม่ได้เปิดใช้ประเภทแหล่งข้อมูลนั้น ใช้วิธีการ SpreadsheetApp#enable...Execution()
เพื่อเปิดใช้การดําเนินการข้อมูลสําหรับแหล่งข้อมูลบางประเภท
// Activates BigQuery operations. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Builds a data source specification. // TODO (developer): Update the project ID to your own Google Cloud project ID. const dataSourceSpec = SpreadsheetApp.newDataSourceSpec() .asBigQuery() .setProjectId('project-id-1') .setTableProjectId('bigquery-public-data') .setDatasetId('ncaa_basketball') .setTableId('mbb_historical_teams_games') .build(); // Adds the data source and its data to the spreadsheet. ss.insertDataSourceSheet(dataSourceSpec);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
spec | DataSourceSpec | ข้อกําหนดของแหล่งข้อมูลที่จะแทรก |
ขากลับ
DataSourceSheet
— แผ่นงานแหล่งข้อมูลใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertImage(blobSource, column, row)
แทรก Spreadsheet
เป็นรูปภาพในเอกสารในแถวและคอลัมน์ที่ระบุ ระบบจะดึงขนาดรูปภาพจากเนื้อหา BLOB ขนาดของ BLOB ที่รองรับสูงสุดคือ 2 MB
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var blob = Utilities.newBlob(binaryData, 'image/png', 'MyImageName'); sheet.insertImage(blob, 1, 1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
blobSource | BlobSource | BLOB ที่มีเนื้อหารูปภาพ ประเภท MIME และชื่อ (ไม่บังคับ) |
column | Integer | ตําแหน่งคอลัมน์ |
row | Integer | ตําแหน่งแถว |
ขากลับ
OverGridImage
— รูปภาพที่แทรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertImage(blobSource, column, row, offsetX, offsetY)
แทรก Spreadsheet
เป็นรูปภาพในเอกสารในแถวและคอลัมน์ที่ระบุ โดยมีออฟเซ็ตพิกเซล ระบบจะดึงขนาดรูปภาพจากเนื้อหา Blob ขนาดของ BLOB ที่รองรับสูงสุดคือ 2 MB
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var blob = Utilities.newBlob(binaryData, 'image/png', 'MyImageName'); sheet.insertImage(blob, 1, 1, 10, 10);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
blobSource | BlobSource | BLOB ที่มีเนื้อหารูปภาพ ประเภท MIME และชื่อ (ไม่บังคับ) |
column | Integer | ตําแหน่งคอลัมน์ |
row | Integer | ตําแหน่งแถว |
offsetX | Integer | ระยะห่างแนวนอนจากเซลล์เป็นพิกเซล |
offsetY | Integer | ระยะห่างแนวตั้งจากเซลล์เป็นพิกเซล |
ขากลับ
OverGridImage
— รูปภาพที่แทรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertImage(url, column, row)
แทรกภาพในเอกสารที่แถวและคอลัมน์ที่กําหนด
URL ที่ระบุต้องเข้าถึงได้แบบสาธารณะ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; sheet.insertImage("https://www.google.com/images/srpr/logo3w.png", 1, 1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
url | String | URL ของรูปภาพ |
column | Integer | ตําแหน่งคอลัมน์ตารางกริด |
row | Integer | ตําแหน่งแถวตารางกริด |
ขากลับ
OverGridImage
— รูปภาพที่แทรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertImage(url, column, row, offsetX, offsetY)
แทรกรูปภาพในเอกสารในแถวและคอลัมน์หนึ่งๆ พร้อมออฟเซ็ตพิกเซล
URL ที่ระบุต้องเข้าถึงได้แบบสาธารณะ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; sheet.insertImage("https://www.google.com/images/srpr/logo3w.png", 1, 1, 10, 10);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
url | String | URL ของรูปภาพ |
column | Integer | ตําแหน่งคอลัมน์ |
row | Integer | ตําแหน่งแถว |
offsetX | Integer | ระยะห่างแนวนอนจากเซลล์เป็นพิกเซล |
offsetY | Integer | ระยะห่างแนวตั้งจากเซลล์เป็นพิกเซล |
ขากลับ
OverGridImage
— รูปภาพที่แทรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertRowAfter(afterPosition)
แทรกแถวหลังตําแหน่งแถวที่ระบุ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts a row after the first row position sheet.insertRowAfter(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
afterPosition | Integer | แถวหลังจากนั้นที่ควรเพิ่มแถวใหม่ |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertRowBefore(beforePosition)
แทรกแถวก่อนตําแหน่งแถวที่ต้องการ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts a row before the first row position sheet.insertRowBefore(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
beforePosition | Integer | แถวก่อนหน้าที่ควรเพิ่มแถวใหม่ |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertRowsAfter(afterPosition, howMany)
แทรกจํานวนแถวหลังจากตําแหน่งแถวที่ระบุ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts five rows after the first row sheet.insertRowsAfter(1, 5);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
afterPosition | Integer | แถวหลังจากนั้นที่ควรเพิ่มแถวใหม่ |
howMany | Integer | จํานวนแถวที่จะแทรก |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertRowsBefore(beforePosition, howMany)
แทรกจํานวนแถวก่อนตําแหน่งแถวที่ต้องการ
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts five rows before the first row sheet.insertRowsBefore(1, 5);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
beforePosition | Integer | แถวก่อนหน้าที่ควรเพิ่มแถวใหม่ |
howMany | Integer | จํานวนแถวที่จะแทรก |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet()
แทรกแผ่นงานใหม่ในสเปรดชีต โดยใช้ชื่อแผ่นงานเริ่มต้น แผ่นงานใหม่ก็คือ แผ่นงานที่ทํางานอยู่
var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.insertSheet();
ขากลับ
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetIndex)
แทรกแผ่นงานใหม่ลงในสเปรดชีตที่ดัชนีที่ระบุ แผ่นงานใหม่ก็คือ แผ่นงานที่ทํางานอยู่
var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.insertSheet(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheetIndex | Integer | ดัชนีของชีตที่สร้างขึ้นใหม่ หากต้องการแทรกแผ่นงานให้เป็นแผ่นงานแรกในสเปรดชีต ให้ตั้งค่าเป็น 0 |
ขากลับ
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetIndex, options)
แทรกแผ่นงานใหม่ลงในสเปรดชีตที่ดัชนีที่ระบุและใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ ชีตใหม่จะกลายเป็นแผ่นงานที่ใช้งานอยู่
var ss = SpreadsheetApp.getActiveSpreadsheet(); var templateSheet = ss.getSheetByName('Sales'); ss.insertSheet(1, {template: templateSheet});
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheetIndex | Integer | ดัชนีของชีตที่สร้างขึ้นใหม่ หากต้องการแทรกแผ่นงานให้เป็นแผ่นงานแรกในสเปรดชีต ให้ตั้งค่าเป็น 0 |
options | Object | อาร์กิวเมนต์ขั้นสูงแบบ JavaScript ที่ไม่บังคับ |
พารามิเตอร์ขั้นสูง
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
template | Sheet | ระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตของชีตต้องเป็นหนึ่งในชีตของออบเจ็กต์สเปรดชีต |
ขากลับ
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(options)
แทรกแผ่นงานใหม่ลงในสเปรดชีตโดยใช้ชื่อแผ่นงานเริ่มต้นและอาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ ชีตใหม่จะกลายเป็นแผ่นงานที่ใช้งานอยู่
var ss = SpreadsheetApp.getActiveSpreadsheet(); var templateSheet = ss.getSheetByName('Sales'); ss.insertSheet({template: templateSheet});
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
options | Object | อาร์กิวเมนต์ขั้นสูงแบบ JavaScript ที่ไม่บังคับ แสดงไว้ด้านล่าง |
พารามิเตอร์ขั้นสูง
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
template | Sheet | ระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตของชีตต้องเป็นหนึ่งในชีตของออบเจ็กต์สเปรดชีตนี้ |
ขากลับ
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetName)
แทรกแผ่นงานใหม่ลงในสเปรดชีตด้วยชื่อที่กําหนด แผ่นงานใหม่ก็คือ แผ่นงานที่ทํางานอยู่
var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.insertSheet('My New Sheet');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheetName | String | ชื่อของแผ่นงานใหม่ |
ขากลับ
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetName, sheetIndex)
แทรกแผ่นงานใหม่ลงในสเปรดชีตด้วยชื่อที่ระบุในดัชนีที่กําหนด แผ่นงานใหม่จะกลายเป็น แผ่นงานที่ทํางานอยู่
var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.insertSheet('My New Sheet', 1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheetName | String | ชื่อของแผ่นงานใหม่ |
sheetIndex | Integer | ดัชนีของชีตที่สร้างขึ้นใหม่ หากต้องการแทรกแผ่นงานให้เป็นแผ่นงานแรกในสเปรดชีต ให้ตั้งค่าเป็น 0 |
ขากลับ
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetName, sheetIndex, options)
แทรกแผ่นงานใหม่ลงในสเปรดชีตด้วยชื่อที่ระบุในดัชนีที่ระบุและใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ ชีตใหม่จะกลายเป็นแผ่นงานที่ใช้งานอยู่
var ss = SpreadsheetApp.getActiveSpreadsheet(); var templateSheet = ss.getSheetByName('Sales'); ss.insertSheet('My New Sheet', 1, {template: templateSheet});
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheetName | String | ชื่อของแผ่นงานใหม่ |
sheetIndex | Integer | ดัชนีของแผ่นงานที่แทรกใหม่ หากต้องการแทรกแผ่นงานให้เป็นแผ่นงานแรกในสเปรดชีต ให้ตั้งค่าเป็น 0 |
options | Object | อาร์กิวเมนต์ขั้นสูงแบบ JavaScript ที่ไม่บังคับ |
พารามิเตอร์ขั้นสูง
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
template | Sheet | ระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตของชีตต้องเป็นหนึ่งในชีตของออบเจ็กต์สเปรดชีต |
ขากลับ
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetName, options)
แทรกแผ่นงานใหม่ลงในสเปรดชีตด้วยชื่อที่กําหนดและใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ ชีตใหม่จะกลายเป็นแผ่นงานที่ใช้งานอยู่
var ss = SpreadsheetApp.getActiveSpreadsheet(); var templateSheet = ss.getSheetByName('Sales'); ss.insertSheet('My New Sheet', {template: templateSheet});
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheetName | String | ชื่อของแผ่นงานใหม่ |
options | Object | อาร์กิวเมนต์ขั้นสูงแบบ JavaScript ที่ไม่บังคับ |
พารามิเตอร์ขั้นสูง
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
template | Sheet | ระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตของชีตต้องเป็นหนึ่งในชีตของออบเจ็กต์สเปรดชีต |
ขากลับ
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheetWithDataSourceTable(spec)
แทรกแผ่นงานใหม่ในสเปรดชีต แล้วสร้าง DataSourceTable
ที่ครอบคลุมทั้งแผ่นงานที่มีข้อกําหนดเฉพาะแหล่งข้อมูลที่ระบุ และเริ่มการเรียกใช้ข้อมูล ผลข้างเคียงคือ
ทําให้ชีตใหม่เป็นแผ่นงานที่ใช้งานอยู่
สร้างข้อยกเว้นหากไม่ได้เปิดใช้ประเภทแหล่งข้อมูลนั้น ใช้วิธีการ SpreadsheetApp#enable...Execution()
เพื่อเปิดใช้การดําเนินการข้อมูลสําหรับแหล่งข้อมูลบางประเภท
// Activates BigQuery operations. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds a sheet and sets cell A1 as the parameter cell. const parameterCell = ss.insertSheet('parameterSheet').getRange('A1'); // Sets the value of the parameter cell to 'Duke'. parameterCell.setValue('Duke'); const query = 'select * from `bigquery-public-data`.`ncaa_basketball`.' + '`mbb_historical_tournament_games` WHERE win_school_ncaa = @SCHOOL'; // Adds a data source with a query parameter. // TODO(developer): Update the project ID to your own Google Cloud project ID. const dataSourceSpec = SpreadsheetApp.newDataSourceSpec() .asBigQuery() .setProjectId('project-id-1') .setRawQuery(query) .setParameterFromCell('SCHOOL', 'parameterSheet!A1') .build(); // Adds sheets for the data source and data source table to the spreadsheet. ss.insertSheetWithDataSourceTable(dataSourceSpec);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
spec | DataSourceSpec | ข้อกําหนดของแหล่งข้อมูลที่จะแทรก |
ขากลับ
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isColumnHiddenByUser(columnPosition)
แสดงผลว่าผู้ใช้ซ่อนคอลัมน์ที่ระบุหรือไม่
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Columns start at 1 Logger.log(sheet.isColumnHiddenByUser(1));
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
columnPosition | Integer | ตําแหน่งของคอลัมน์ที่จะตรวจสอบ |
ขากลับ
Boolean
— true
หากซ่อนคอลัมน์ไว้ false
มิเช่นนั้น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isIterativeCalculationEnabled()
แสดงผลว่ามีการเปิดใช้งานการคํานวณซ้ําในสเปรดชีตนี้หรือไม่
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Activates iterative calculation on the spreadsheet. ss.setIterativeCalculationEnabled(true); // Logs whether iterative calculation is activated for the spreadsheet. console.log(ss.isIterativeCalculationEnabled());
ขากลับ
Boolean
— true
หากเปิดใช้งานการคํานวณแบบวนซ้ําไว้ มิเช่นนั้น false
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isRowHiddenByFilter(rowPosition)
แสดงผลว่าตัวกรองจะซ่อนแถวที่ระบุหรือไม่ (ไม่ใช่มุมมองตัวกรอง)
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Rows start at 1 Logger.log(sheet.isRowHiddenByFilter(1));
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
rowPosition | Integer | ตําแหน่งของแถวที่จะตรวจสอบ |
ขากลับ
Boolean
— true
ถ้าแถวซ่อนอยู่ false
หรือไม่เช่นนั้น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isRowHiddenByUser(rowPosition)
แสดงผลว่าผู้ใช้ซ่อนแถวที่ระบุหรือไม่
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Rows start at 1 Logger.log(sheet.isRowHiddenByUser(1));
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
rowPosition | Integer | ตําแหน่งของแถวที่จะตรวจสอบ |
ขากลับ
Boolean
— true
ถ้าแถวซ่อนอยู่ false
หรือไม่เช่นนั้น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
moveActiveSheet(pos)
ย้ายแผ่นงานที่ใช้งานอยู่ไปยังตําแหน่งที่ระบุในรายการแผ่นงาน ยกเว้นข้อยกเว้นในกรณีที่ตําแหน่งเป็นค่าลบหรือมากกว่าจํานวนของแผ่นงาน
// This example assumes that there are 2 sheets in the current // active spreadsheet: one named "first" in position 1 and another named "second" // in position 2. var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // Gets the "first" sheet and activates it. var sheet = spreadsheet.getSheetByName("first").activate(); // Logs 'Current index of sheet: 1' console.log("Current index of sheet: %s", sheet.getIndex()); spreadsheet.moveActiveSheet(2); // Logs 'New index of sheet: 2' console.log("New index of sheet: %s", sheet.getIndex());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
pos | Integer | ตําแหน่ง 1 ดัชนีที่จะย้ายแผ่นงานที่ใช้งานอยู่ลงในรายการของแผ่นงาน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
moveChartToObjectSheet(chart)
สร้างชีต SheetType.OBJECT
ใหม่และย้ายแผนภูมิที่มีให้ หากแผนภูมิอยู่ในแผ่นงานของตัวเองอยู่แล้ว แผ่นงานนั้นจะส่งคืนโดยไม่สร้างแผ่นงานใหม่
var sheet = SpreadsheetApp.getActiveSheet(); var chart = sheet.newChart().setPosition(1, 1, 0, 0).build(); sheet.insertChart(chart); var objectSheet = SpreadsheetApp.getActive().moveChartToObjectSheet(chart);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
chart | EmbeddedChart | แผนภูมิที่ต้องการย้าย |
ขากลับ
Sheet
— แผ่นงานที่แผนภูมิเปิดอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
refreshAllDataSources()
รีเฟรชแหล่งข้อมูลที่สนับสนุนทั้งหมดและออบเจ็กต์แหล่งข้อมูลที่ลิงก์ โดยการข้ามออบเจ็กต์แหล่งข้อมูลที่ไม่ถูกต้อง
ใช้วิธีการ SpreadsheetApp#enable...Execution()
เพื่อเปิดใช้การดําเนินการกับข้อมูลสําหรับประเภทแหล่งข้อมูลเฉพาะ
// Activates BigQuery operations. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets the first data source sheet on the spreadsheet. const dataSheet = ss.getDataSourceSheets()[0]; // Refreshes all data sources on the spreadsheet. ss.refreshAllDataSources(); // Logs the last refreshed time of the first data source sheet. console.log(`Last refresh time: ${dataSheet.getStatus().getLastRefreshedTime()}`);
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeEditor(emailAddress)
นําผู้ใช้ที่ระบุออกจากรายการผู้แก้ไขสําหรับ Spreadsheet
วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง Spreadsheet
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Spreadsheet
กับทั้งโดเมนของผู้ใช้ หรือหาก Spreadsheet
อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้
สําหรับไฟล์ในไดรฟ์ การดําเนินการนี้จะนําผู้ใช้ออกจากรายชื่อผู้ดูด้วย
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
emailAddress | String | ที่อยู่อีเมลของผู้ใช้ที่จะนําออก |
ขากลับ
Spreadsheet
— Spreadsheet
นี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeEditor(user)
นําผู้ใช้ที่ระบุออกจากรายการผู้แก้ไขสําหรับ Spreadsheet
วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง Spreadsheet
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Spreadsheet
กับทั้งโดเมนของผู้ใช้ หรือหาก Spreadsheet
อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้
สําหรับไฟล์ในไดรฟ์ การดําเนินการนี้จะนําผู้ใช้ออกจากรายชื่อผู้ดูด้วย
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะนําออก |
ขากลับ
Spreadsheet
— Spreadsheet
นี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeMenu(name)
นําเมนูที่ addMenu(name, subMenus)
เพิ่มไว้ออก อาร์กิวเมนต์ name
ควรมีค่าเดียวกันกับการเรียกไปยัง addMenu(name, subMenus)
// The onOpen function is executed automatically every time a Spreadsheet is loaded function onOpen() { var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.addMenu("badMenu", [{name: "remove bad menu", functionName: "removeBadMenu"}, {name: "foo", functionName: "foo"}]); } function removeBadMenu() { var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.removeMenu("badMenu"); // name must match the name used when added the menu } function foo(){ // Do nothing }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อของเมนูที่จะนําออก |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeNamedRange(name)
ลบช่วงที่ตั้งชื่อแล้วโดยใช้ชื่อที่ระบุ สร้างข้อยกเว้นหากไม่พบช่วงที่มีชื่อนั้นในสเปรดชีต
// The code below creates a new named range "foo", and then remove it. var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.setNamedRange("foo", ss.getActiveRange()); ss.removeNamedRange("foo");
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อช่วง |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeViewer(emailAddress)
นําผู้ใช้ที่ระบุออกจากรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ Spreadsheet
วิธีการนี้จะไม่มีผลหากผู้ใช้เป็นผู้แก้ไข ไม่ใช่ผู้ดูหรือผู้แสดงความคิดเห็น วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง Spreadsheet
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Spreadsheet
กับทั้งโดเมนของผู้ใช้ หรือหาก Spreadsheet
อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้
สําหรับไฟล์ในไดรฟ์ การดําเนินการนี้จะนําผู้ใช้ออกจากรายชื่อผู้แก้ไขด้วย
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
emailAddress | String | ที่อยู่อีเมลของผู้ใช้ที่จะนําออก |
ขากลับ
Spreadsheet
— Spreadsheet
สําหรับการเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeViewer(user)
นําผู้ใช้ที่ระบุออกจากรายการผู้ชมและผู้แสดงความคิดเห็นสําหรับ Spreadsheet
วิธีการนี้จะไม่มีผลหากผู้ใช้เป็นผู้แก้ไข ไม่ใช่ผู้ดู วิธีการนี้จะไม่บล็อกผู้ใช้ไม่ให้เข้าถึง Spreadsheet
หากผู้ใช้เป็นสมาชิกในชั้นเรียนที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Spreadsheet
กับทั้งโดเมนของผู้ใช้ หรือหาก Spreadsheet
อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้
สําหรับไฟล์ในไดรฟ์ การดําเนินการนี้จะนําผู้ใช้ออกจากรายชื่อผู้แก้ไขด้วย
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะนําออก |
ขากลับ
Spreadsheet
— Spreadsheet
สําหรับการเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
rename(newName)
เปลี่ยนชื่อเอกสาร
var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.rename("This is the new name");
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
newName | String | ชื่อใหม่ของเอกสาร |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
renameActiveSheet(newName)
เปลี่ยนชื่อแผ่นงานที่ใช้งานอยู่ให้เป็นชื่อใหม่
// The code below renames the active sheet to "Hello world" SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet("Hello world");
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
newName | String | ชื่อใหม่ของแผ่นงานที่ใช้งานอยู่ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
resetSpreadsheetTheme()
นําธีมที่ใช้อยู่ออกและตั้งค่าธีมเริ่มต้นในสเปรดชีต
// The code below applies default theme on the spreadsheet. SpreadsheetApp.getActiveSpreadsheet().resetSpreadsheetTheme();
ขากลับ
SpreadsheetTheme
— ธีมเริ่มต้น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveRange(range)
ตั้งค่าช่วงที่ระบุเป็น active range
ในแผ่นงานที่ใช้งาน โดยเซลล์ซ้ายบนสุดในช่วงนั้นเป็น current cell
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var range = sheet.getRange('A1:D4'); sheet.setActiveRange(range); var selection = sheet.getSelection(); // Current cell: A1 var currentCell = selection.getCurrentCell(); // Active Range: A1:D4 var activeRange = selection.getActiveRange();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
range | Range | ช่วงที่จะตั้งค่าเป็นช่วงที่ใช้งานอยู่ |
ขากลับ
Range
— ช่วงที่มีการใช้งานใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveRangeList(rangeList)
ตั้งค่ารายการช่วงที่ระบุเป็น active ranges
ในแผ่นงานที่ใช้งานอยู่ ช่วงสุดท้ายของรายการถูกตั้งค่าเป็น active range
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['D4', 'B2:C4']); sheet.setActiveRangeList(rangeList); var selection = sheet.getSelection(); // Current cell: B2 var currentCell = selection.getCurrentCell(); // Active range: B2:C4 var activeRange = selection.getActiveRange(); // Active range list: [D4, B2:C4] var activeRangeList = selection.getActiveRangeList();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
rangeList | RangeList | รายการช่วงให้เลือก |
ขากลับ
RangeList
— รายการช่วงที่เลือกใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveSelection(range)
ตั้งค่าภูมิภาคที่เลือกที่ใช้งานอยู่สําหรับชีตนี้
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var range = sheet.getRange("A1:D4"); sheet.setActiveSelection(range);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
range | Range | ช่วงที่จะตั้งค่าเป็นการเลือกที่ทํางานอยู่ |
ขากลับ
Range
— ช่วงที่มีการใช้งานใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveSelection(a1Notation)
ตั้งค่ารายการที่เลือกใช้งานตามที่ระบุ รูปแบบ A1 หรือ R1C1
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; sheet.setActiveSelection("A1:D4");
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
a1Notation | String | ช่วงที่จะตั้งค่าเป็นใช้งานอยู่ ตามที่ระบุไว้ในเครื่องหมาย A1 หรือ R1C1 |
ขากลับ
Range
— ช่วงที่มีการใช้งานใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveSheet(sheet)
ตั้งค่าแผ่นงานที่ระบุให้เป็นแผ่นงานที่ใช้งานอยู่ในสเปรดชีต UI ของ Google ชีตจะแสดง แผ่นงานที่เลือกเว้นแต่แผ่นงานจะอยู่ในสเปรดชีตอื่น
// The code below makes the first sheet active in the active spreadsheet. var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); spreadsheet.setActiveSheet(spreadsheet.getSheets()[0]);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | Sheet | แผ่นงานที่ตั้งค่าเป็นแผ่นงานที่ทํางานอยู่ |
ขากลับ
Sheet
— แผ่นงานที่ใช้งานอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveSheet(sheet, restoreSelection)
ตั้งค่าแผ่นงานที่ระบุให้เป็นแผ่นงานที่ใช้งานอยู่ในสเปรดชีต พร้อมตัวเลือกในการคืนค่าการเลือกล่าสุดภายในแผ่นงานนั้น UI ของ Google ชีตจะแสดงแผ่นงานที่เลือกไว้ ยกเว้นว่าแผ่นงานจะอยู่ในสเปรดชีตอื่น
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var firstSheet = spreadsheet.getSheets()[0]; var secondSheet = spreadsheet.getSheets()[1]; // Set the first sheet as the active sheet and select the range D4:F4. spreadsheet.setActiveSheet(firstSheet).getRange('D4:F4').activate(); // Switch to the second sheet to do some work. spreadsheet.setActiveSheet(secondSheet); // Switch back to first sheet, and restore its selection. spreadsheet.setActiveSheet(firstSheet, true); // The selection of first sheet is restored, and it logs D4:F4 var range = spreadsheet.getActiveSheet().getSelection().getActiveRange(); Logger.log(range.getA1Notation());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | Sheet | ชีตใหม่ที่มีการใช้งาน |
restoreSelection | Boolean | สําหรับ "true " การเลือกชีตใหม่ล่าสุดจะทํางานอีกครั้งเมื่อแผ่นงานใหม่เริ่มทํางานแล้ว หาก false แผ่นงานใหม่จะทํางานโดยไม่เปลี่ยนแปลงการเลือกปัจจุบัน |
ขากลับ
Sheet
— แผ่นงานใหม่ที่ใช้งาน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setColumnWidth(columnPosition, width)
ตั้งค่าความกว้างของคอลัมน์ที่ระบุเป็นพิกเซล
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Sets the first column to a width of 200 pixels sheet.setColumnWidth(1, 200);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
columnPosition | Integer | ตําแหน่งของคอลัมน์ที่กําหนด |
width | Integer | ความกว้างเป็นพิกเซลเพื่อตั้งค่า |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setCurrentCell(cell)
ตั้งค่าเซลล์ที่ระบุเป็น current cell
ถ้าเซลล์ที่ระบุอยู่ในช่วงที่เลือกไว้แล้ว ช่วงนั้นจะเป็นช่วงที่มีการใช้งานด้วยเซลล์นั้นเป็นเซลล์ปัจจุบัน
ถ้าเซลล์ที่ระบุไม่อยู่ในช่วงที่เลือกใดๆ การเลือกที่มีอยู่จะถูกนําออกและเซลล์นั้นจะกลายเป็นเซลล์ปัจจุบันและช่วงที่มีการใช้งาน
หมายเหตุ: Range
ที่ระบุต้องมีเซลล์เดียว ไม่เช่นนั้นจะยกเว้นข้อยกเว้น
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var cell = sheet.getRange('B5'); sheet.setCurrentCell(cell); var selection = sheet.getSelection(); // Current cell: B5 var currentCell = selection.getCurrentCell();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
cell | Range | เซลล์ที่ตั้งค่าเป็นเซลล์ปัจจุบัน |
ขากลับ
Range
— เซลล์ปัจจุบันที่เพิ่งกําหนด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFrozenColumns(columns)
ตรึงจํานวนคอลัมน์ที่ระบุ หากเป็น 0 จะไม่มีการตรึงคอลัมน์
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Freezes the first column sheet.setFrozenColumns(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
columns | Integer | จํานวนคอลัมน์ที่จะตรึง |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFrozenRows(rows)
ตรึงแถวที่ระบุ หากเป็น 0 จะไม่มีการตรึงแถว
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Freezes the first row sheet.setFrozenRows(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
rows | Integer | จํานวนแถวที่ตรึง |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setIterativeCalculationConvergenceThreshold(minThreshold)
ตั้งค่าเกณฑ์ขั้นต่ําสําหรับการคํานวณซ้ํา เมื่อผลลัพธ์ของการคํานวณแบบต่อเนื่อง น้อยกว่าค่านี้ การคํานวณแบบวนซ้ําจะหยุดลง ค่านี้ต้องไม่ติดลบและมีค่าเริ่มต้นเป็น 0.05
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the iterative calculation convergence threshold for the spreadsheet. ss.setIterativeCalculationConvergenceThreshold(2); // Logs the threshold to the console. console.log(ss.getIterativeCalculationConvergenceThreshold());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
minThreshold | Number | เกณฑ์การบรรจบกันขั้นต่ํา (ต้องไม่เป็นค่าลบ) |
ขากลับ
Spreadsheet
— สเปรดชีตนี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setIterativeCalculationEnabled(isEnabled)
ตั้งค่าว่าจะมีการเปิดใช้งานการคํานวณซ้ําในสเปรดชีตนี้หรือไม่ หากก่อนหน้านี้ยังไม่มีการกําหนดจํานวนรอบการคํานวณสูงสุดและเกณฑ์ Conversion ไว้เมื่อเปิดใช้งานการคํานวณ ค่าเริ่มต้นดังกล่าวจะเท่ากับ 50 และ 0.05 ตามลําดับ หากมีการตั้งค่าไว้ก่อนหน้านี้ ระบบจะคงค่าเดิมไว้
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Activates iterative calculation on the spreadsheet. ss.setIterativeCalculationEnabled(true); // Logs whether iterative calculation is activated for the spreadsheet. console.log(ss.isIterativeCalculationEnabled());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
isEnabled | Boolean | true หากควรเปิดใช้การคํานวณแบบวนซ้ํา หรือมิเช่นนั้น false |
ขากลับ
Spreadsheet
— สเปรดชีตนี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setMaxIterativeCalculationCycles(maxIterations)
ตั้งค่าจํานวนสูงสุดของการคํานวณซ้ําที่ควรทําในระหว่างการคํานวณแบบวนซ้ํา ค่านี้ต้องอยู่ระหว่าง 1 ถึง 10,000 (รวม) และมีค่าเริ่มต้นเป็น 50
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the max iterative calculation cycles for the spreadsheet. ss.setMaxIterativeCalculationCycles(10); // Logs the max iterative calculation cycles to the console. console.log(ss.getMaxIterativeCalculationCycles());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
maxIterations | Integer | จํานวนสูงสุดของการคํานวณซ้ํา (ระหว่าง 1 ถึง 10,000) |
ขากลับ
Spreadsheet
— สเปรดชีตนี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setNamedRange(name, range)
ตั้งชื่อช่วง
// The code below creates a new named range "TaxRates" in the active spreadsheet var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.setNamedRange("TaxRates", SpreadsheetApp.getActiveRange());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อที่ระบุช่วง |
range | Range | ข้อกําหนดของช่วง |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setRecalculationInterval(recalculationInterval)
ตั้งค่าความถี่ในการคํานวณสเปรดชีตนี้ใหม่
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the calculation interval for the spreadsheet to 'ON_CHANGE'. const interval = ss.setRecalculationInterval(SpreadsheetApp.RecalculationInterval.ON_CHANGE); // Logs the calculation interval to the console. console.log(interval);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
recalculationInterval | RecalculationInterval | ช่วงเวลาการคํานวณใหม่ |
ขากลับ
Spreadsheet
— สเปรดชีตนี้สําหรับเชน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setRowHeight(rowPosition, height)
ตั้งค่าความสูงของแถวของแถวที่กําหนดเป็นพิกเซล โดยค่าเริ่มต้น แถวจะขยายออกให้พอดีกับเนื้อหาของเซลล์ หากต้องการบังคับให้แถวสูงที่ระบุ ให้ใช้ Sheet.setRowHeightsForced(startRow, numRows, height)
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Sets the first row to a height of 200 pixels sheet.setRowHeight(1, 200);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
rowPosition | Integer | ตําแหน่งแถวที่จะเปลี่ยน |
height | Integer | ความสูงของพิกเซลที่จะตั้งค่า |
ขากลับ
Sheet
— ชีตซึ่งมีประโยชน์ในการเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setSpreadsheetLocale(locale)
ตั้งค่าภาษาของสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the spreadsheet locale. ss.setSpreadsheetLocale('fr'); // Gets the spreadsheet locale. const ssLocale = ss.getSpreadsheetLocale(); // Logs the locale to the console. console.log(ssLocale);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
locale | String | รหัสภาษาที่จะใช้ (เช่น "en", "fr" หรือ "en_US") |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setSpreadsheetTheme(theme)
ตั้งค่าธีมในสเปรดชีต
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // The code below sets the second predefined theme as the current theme of the spreadsheet. var predefinedThemesList = spreadsheet.getPredefinedSpreadsheetThemes(); spreadsheet.setSpreadsheetTheme(predefinedThemesList[1]);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
theme | SpreadsheetTheme | ธีมที่จะใช้ |
ขากลับ
SpreadsheetTheme
— ธีมใหม่ปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setSpreadsheetTimeZone(timezone)
ตั้งค่าเขตเวลาของสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the time zone of the spreadsheet. ss.setSpreadsheetTimeZone('America/New_York'); // Gets the time zone of the spreadsheet. const ssTimeZone = ss.getSpreadsheetTimeZone(); // Logs the time zone to the console. console.log(ssTimeZone);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
timezone | String | เขตเวลาที่ระบุไว้ในรูปแบบ "แบบยาว" (เช่น "อเมริกา/New_York" ตามที่ Joda.org แสดง) |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
show(userInterface)
แสดงคอมโพเนนต์อินเทอร์เฟซผู้ใช้ที่กําหนดเองในกล่องโต้ตอบจุดกึ่งกลางในมุมมอง เบราว์เซอร์ของผู้ใช้ การดําเนินการของสคริปต์ฝั่งเซิร์ฟเวอร์ไม่ถูกระงับ ในการสื่อสารกับฝั่งเซิร์ฟเวอร์ คอมโพเนนต์อินเทอร์เฟซผู้ใช้จะต้องเรียกโค้ดอะซิงโครนัสไปยังสคริปต์ฝั่งเซิร์ฟเวอร์
หากสคริปต์ฝั่งเซิร์ฟเวอร์ก่อนหน้านี้แสดงกล่องโต้ตอบที่ไม่ถูกปิด ระบบจะแทนที่กล่องโต้ตอบที่มีอยู่ด้วยอินเทอร์เฟซผู้ใช้ของกล่องโต้ตอบที่ขอใหม่
ข้อมูลโค้ดต่อไปนี้แสดงแอปพลิเคชัน HtmlService
แบบง่ายในกล่องโต้ตอบที่มีชื่อ ความสูง และความกว้างที่ระบุ
var htmlApp = HtmlService .createHtmlOutput('<p>A change of speed, a change of style...</p>') .setTitle('My HtmlService Application') .setWidth(250) .setHeight(300); SpreadsheetApp.getActiveSpreadsheet().show(htmlApp); // The script resumes execution immediately after showing the dialog.
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
userInterface | Object | HtmlOutput |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/script.container.ui
sort(columnPosition)
จัดเรียงแผ่นงานตามคอลัมน์จากน้อยไปมาก
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Sorts the sheet by the first column, ascending sheet.sort(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
columnPosition | Integer | คอลัมน์ที่จัดเรียงตาม |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
sort(columnPosition, ascending)
จัดเรียงแผ่นงานตามคอลัมน์ ใช้พารามิเตอร์เพื่อระบุจากน้อยไปมากหรือมากไปน้อย
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Sorts the sheet by the first column, descending sheet.sort(1, false);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
columnPosition | Integer | คอลัมน์ที่จัดเรียงตาม |
ascending | Boolean | true สําหรับการจัดเรียงจากน้อยไปมาก และ false จากมากไปน้อย |
ขากลับ
Sheet
— ชีต มีประโยชน์สําหรับเชนเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
toast(msg)
แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีตพร้อมข้อความที่ระบุ
// Show a popup with the message "Task started". SpreadsheetApp.getActiveSpreadsheet().toast('Task started');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
msg | String | ข้อความที่จะแสดงในข้อความโทสต์ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
toast(msg, title)
แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีตพร้อมข้อความและชื่อ
// Show a popup with the title "Status" and the message "Task started". SpreadsheetApp.getActiveSpreadsheet().toast('Task started', 'Status');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
msg | String | ข้อความที่จะแสดงในข้อความโทสต์ |
title | String | ชื่อของข้อความโทสต์ซึ่งไม่บังคับ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
toast(msg, title, timeoutSeconds)
แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีต โดยใช้ชื่อและข้อความที่กําหนด ซึ่งยังคงเห็นเป็นระยะเวลาหนึ่ง
// Show a 3-second popup with the title "Status" and the message "Task started". SpreadsheetApp.getActiveSpreadsheet().toast('Task started', 'Status', 3);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
msg | String | ข้อความที่จะแสดงในข้อความโทสต์ |
title | String | ชื่อของข้อความโทสต์ซึ่งไม่บังคับ |
timeoutSeconds | Number | ระยะหมดเวลาเป็นวินาที หาก null ข้อความโทสต์จะมีค่าเริ่มต้นเป็น 5 วินาที หากเป็นเชิงลบ ข้อความโทสต์จะยังคงอยู่จนกว่าจะปิด |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
unhideColumn(column)
เลิกซ่อนคอลัมน์ในช่วงที่กําหนด
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This unhides the first column if it was previously hidden var range = sheet.getRange("A1"); sheet.unhideColumn(range);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Range | ช่วงที่จะเลิกซ่อน หากซ่อนอยู่ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
unhideRow(row)
เลิกซ่อนแถวในช่วงที่กําหนด
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This unhides the first row if it was previously hidden var range = sheet.getRange("A1"); sheet.unhideRow(range);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Range | ช่วงที่จะเลิกซ่อน หากซ่อนอยู่ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
updateMenu(name, subMenus)
อัปเดตเมนูที่เพิ่มโดย addMenu(name, subMenus)
ทํางานเหมือนกับ addMenu(name, subMenus)
var ss = SpreadsheetApp.getActiveSpreadsheet(); var menuEntries = []; menuEntries.push({name: "Lone Menu Entry", functionName: "function1"}); ss.updateMenu("addMenuExample", menuEntries);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อของเมนูที่จะอัปเดต |
subMenus | Object[] | อาร์เรย์ของแผนที่ JavaScript ที่มีพารามิเตอร์ name และ functionName
คุณใช้ฟังก์ชันจากไลบรารีที่ใช้ร่วมกันได้ เช่น
Library.libFunction1 |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
waitForAllDataExecutionsCompletion(timeoutInSeconds)
รอจนกว่าการดําเนินการปัจจุบันทั้งหมดในสเปรดชีตเสร็จสมบูรณ์ จะหมดเวลาหลังจากจํานวนวินาทีที่ระบุ จะส่งข้อยกเว้นหากการดําเนินการไม่เสร็จสมบูรณ์เมื่อหมดเวลา แต่ไม่ได้ยกเลิกการดําเนินการข้อมูล
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
timeoutInSeconds | Integer | เวลารอการเรียกใช้ข้อมูล หน่วยเป็นวินาที ความยาวสูงสุด 300 วินาที |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องใช้สิทธิ์กับขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets