Class Spreadsheet

สเปรดชีต

เข้าถึงและแก้ไขไฟล์ 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())

พารามิเตอร์

ชื่อประเภทคำอธิบาย
keyStringคีย์สำหรับข้อมูลเมตาใหม่ของนักพัฒนาซอฟต์แวร์

ขากลับ

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()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
keyStringคีย์สำหรับข้อมูลเมตาใหม่ของนักพัฒนาซอฟต์แวร์
visibilityDeveloperMetadataVisibilityระดับการเข้าถึงข้อมูลเมตาใหม่ของนักพัฒนาซอฟต์แวร์

ขากลับ

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()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
keyStringคีย์สำหรับข้อมูลเมตาใหม่ของนักพัฒนาซอฟต์แวร์
valueStringค่าสำหรับข้อมูลเมตาใหม่ของนักพัฒนาซอฟต์แวร์

ขากลับ

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()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
keyStringคีย์สำหรับข้อมูลเมตาใหม่ของนักพัฒนาซอฟต์แวร์
valueStringค่าสำหรับข้อมูลเมตาใหม่ของนักพัฒนาซอฟต์แวร์
visibilityDeveloperMetadataVisibilityระดับการเข้าถึงข้อมูลเมตาใหม่ของนักพัฒนาซอฟต์แวร์

ขากลับ

Spreadsheet — สเปรดชีตนี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addEditor(emailAddress)

เพิ่มผู้ใช้ที่ระบุลงในรายการเอดิเตอร์ของ Spreadsheet หากผู้ใช้อยู่ในรายการผู้ชมแล้ว วิธีนี้จะโปรโมตผู้ใช้ออกจากรายการผู้ชม

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressStringอีเมลของผู้ใช้ที่จะเพิ่ม

ขากลับ

SpreadsheetSpreadsheet นี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addEditor(user)

เพิ่มผู้ใช้ที่ระบุลงในรายการเอดิเตอร์ของ Spreadsheet หากผู้ใช้อยู่ในรายการผู้ชมแล้ว วิธีนี้จะโปรโมตผู้ใช้ออกจากรายการผู้ชม

พารามิเตอร์

ชื่อประเภทคำอธิบาย
userUserตัวแทนของผู้ใช้ที่จะเพิ่ม

ขากลับ

SpreadsheetSpreadsheet นี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addEditors(emailAddresses)

เพิ่มอาร์เรย์ที่ระบุของผู้ใช้ลงในรายการเครื่องมือแก้ไขสำหรับ Spreadsheet หากมีผู้ใช้อยู่ในรายการผู้ชมแล้ว วิธีนี้จะโปรโมตผู้ใช้เหล่านั้นจากรายชื่อผู้ชม

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressesString[]อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม

ขากลับ

SpreadsheetSpreadsheet นี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);
}

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อเมนูที่จะสร้าง
subMenusObject[]อาร์เรย์ของ JavaScript ที่มีพารามิเตอร์ name และ functionName คุณใช้ฟังก์ชันจากไลบรารีที่รวมอยู่ได้ เช่น Library.libFunction1

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addViewer(emailAddress)

เพิ่มผู้ใช้ที่ระบุลงในรายการผู้ดูสำหรับ Spreadsheet หากผู้ใช้อยู่ในรายการเอดิเตอร์อยู่แล้ว วิธีนี้จะไม่มีผล

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressStringอีเมลของผู้ใช้ที่จะเพิ่ม

ขากลับ

SpreadsheetSpreadsheet นี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addViewer(user)

เพิ่มผู้ใช้ที่ระบุลงในรายการผู้ดูสำหรับ Spreadsheet หากผู้ใช้อยู่ในรายการเอดิเตอร์อยู่แล้ว วิธีนี้จะไม่มีผล

พารามิเตอร์

ชื่อประเภทคำอธิบาย
userUserตัวแทนของผู้ใช้ที่จะเพิ่ม

ขากลับ

SpreadsheetSpreadsheet นี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

addViewers(emailAddresses)

เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายการผู้ดูสำหรับ Spreadsheet หากมีผู้ใช้อยู่ในรายการเอดิเตอร์อยู่แล้ว วิธีนี้จะไม่มีผลกับผู้ใช้

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressesString[]อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม

ขากลับ

SpreadsheetSpreadsheet นี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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"]);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowContentsObject[]อาร์เรย์ของค่าที่จะแทรกหลังแถวสุดท้ายในชีต

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnPositionIntegerตําแหน่งของคอลัมน์ที่ระบุเพื่อปรับขนาด

ขากลับ

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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อของสำเนา

ขากลับ

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');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
findTextStringข้อความที่จะค้นหา

ขากลับ

TextFinderTextFinder สำหรับสเปรดชีต


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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnPositionIntegerตำแหน่งของคอลัมน์ โดยเริ่มต้นที่ 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnPositionIntegerตําแหน่งของคอลัมน์แรกที่จะลบ
howManyIntegerจำนวนคอลัมน์ที่จะลบ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowPositionIntegerตำแหน่งของแถว โดยเริ่มต้นที่ 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowPositionIntegerตำแหน่งของแถวแรกที่จะลบ
howManyIntegerจำนวนแถวที่จะลบ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sheetSheetแผ่นงานที่จะลบ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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 ที่สร้างใหม่อาจมีโควต้าที่เข้มงวดขึ้นชั่วคราว

พารามิเตอร์

ชื่อประเภทคำอธิบาย
contentTypeStringประเภท 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()

แสดงผลข้อมูลภายในออบเจ็กต์นี้เป็น BLOB

ขากลับ

Blob — ข้อมูลในรูปแบบ BLOB


getColumnWidth(columnPosition)

ดึงความกว้างเป็นพิกเซลของคอลัมน์ที่ระบุ

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];

// Columns start at 1
Logger.log(sheet.getColumnWidth(1));

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnPositionIntegerตําแหน่งของคอลัมน์ที่จะตรวจสอบ

ขากลับ

Integer — ความกว้างของคอลัมน์เป็นพิกเซล

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getCurrentCell()

แสดงผลเซลล์ปัจจุบันในชีตที่ใช้งานอยู่หรือ null หากไม่มีเซลล์ปัจจุบัน เซลล์ปัจจุบันคือเซลล์ที่โฟกัสใน UI ของ Google ชีตและไฮไลต์ด้วยเส้นขอบสีเข้ม อาจไม่มีเซลล์ปัจจุบันเกิน 1 เซลล์ เมื่อผู้ใช้เลือกช่วงเซลล์อย่างน้อย 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();
  }
}

พารามิเตอร์

ชื่อประเภทคำอธิบาย
typeProtectionTypeประเภทของพื้นที่คุ้มครอง ซึ่งอาจเป็น 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");

พารามิเตอร์

ชื่อประเภทคำอธิบาย
a1NotationStringช่วงที่จะส่งคืนตามที่ระบุไว้ในหมายเหตุ 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());
}

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อของช่วงที่จะรับ

ขากลับ

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']);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
a1NotationsString[]รายการช่วงที่จะส่งคืนตามที่ระบุไว้ในรูปแบบ 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));

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowPositionIntegerตําแหน่งของแถวที่ต้องการตรวจสอบ

ขากลับ

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());
}

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อของชีตที่จะรับ

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startRowIntegerตำแหน่งของแถวเริ่มต้น
startColumnIntegerตำแหน่งของคอลัมน์เริ่มต้น
numRowsIntegerจำนวนแถวที่จะแสดงค่า
numColumnsIntegerจำนวนคอลัมน์ที่จะแสดงผลค่า

ขากลับ

Object[][] — อาร์เรย์ของค่า 2 มิติ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnRangeช่วงของคอลัมน์ที่จะซ่อน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowRangeช่วงของแถวที่จะซ่อน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
afterPositionIntegerคอลัมน์ที่ควรเพิ่มคอลัมน์ใหม่

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
beforePositionIntegerคอลัมน์ที่ควรเพิ่มคอลัมน์ใหม่

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
afterPositionIntegerคอลัมน์ที่ควรเพิ่มคอลัมน์ใหม่
howManyIntegerจำนวนคอลัมน์ที่จะแทรก

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
beforePositionIntegerคอลัมน์ที่ควรเพิ่มคอลัมน์ใหม่
howManyIntegerจำนวนคอลัมน์ที่จะแทรก

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
specDataSourceSpecข้อกำหนดของแหล่งข้อมูลที่จะแทรก

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
blobSourceBlobSourceBLOB ที่มีเนื้อหารูปภาพ ประเภท MIME และชื่อ (ไม่บังคับ)
columnIntegerตำแหน่งคอลัมน์
rowIntegerตำแหน่งของแถว

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
blobSourceBlobSourceBLOB ที่มีเนื้อหารูปภาพ ประเภท MIME และชื่อ (ไม่บังคับ)
columnIntegerตำแหน่งคอลัมน์
rowIntegerตำแหน่งของแถว
offsetXIntegerค่าออฟเซ็ตแนวนอนจากมุมของเซลล์ หน่วยเป็นพิกเซล
offsetYIntegerค่าออฟเซ็ตแนวตั้งจากมุมของเซลล์ หน่วยเป็นพิกเซล

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
urlStringURL ของรูปภาพ
columnIntegerตำแหน่งคอลัมน์ของตาราง
rowIntegerตำแหน่งแถวของตาราง

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
urlStringURL ของรูปภาพ
columnIntegerตำแหน่งคอลัมน์
rowIntegerตำแหน่งของแถว
offsetXIntegerค่าออฟเซ็ตแนวนอนจากมุมของเซลล์ หน่วยเป็นพิกเซล
offsetYIntegerค่าออฟเซ็ตแนวตั้งจากมุมของเซลล์ หน่วยเป็นพิกเซล

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
afterPositionIntegerแถวที่ควรเพิ่มแถวใหม่

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
beforePositionIntegerแถวที่ควรเพิ่มแถวใหม่

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
afterPositionIntegerแถวที่ควรเพิ่มแถวใหม่
howManyIntegerจำนวนแถวที่จะแทรก

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
beforePositionIntegerแถวที่ควรเพิ่มแถวใหม่
howManyIntegerจำนวนแถวที่จะแทรก

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sheetIndexIntegerดัชนีของชีตที่สร้างใหม่ หากต้องการแทรกชีตเป็นแผ่นแรกในสเปรดชีต ให้ตั้งค่าเป็น 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});

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sheetIndexIntegerดัชนีของชีตที่สร้างใหม่ หากต้องการแทรกชีตเป็นแผ่นแรกในสเปรดชีต ให้ตั้งค่าเป็น 0
optionsObjectอาร์กิวเมนต์ขั้นสูงของ JavaScript ที่ไม่บังคับ

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
templateSheetระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตของชีตต้องเป็นหนึ่งในชีตของออบเจ็กต์สเปรดชีต

ขากลับ

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});

พารามิเตอร์

ชื่อประเภทคำอธิบาย
optionsObjectอาร์กิวเมนต์ขั้นสูง (ไม่บังคับ) ของ JavaScript ซึ่งแสดงอยู่ด้านล่าง

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
templateSheetระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตของชีตต้องเป็นหนึ่งในชีตของออบเจ็กต์สเปรดชีตนี้

ขากลับ

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');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sheetNameStringชื่อของชีตใหม่

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sheetNameStringชื่อของชีตใหม่
sheetIndexIntegerดัชนีของชีตที่สร้างใหม่ หากต้องการแทรกชีตเป็นแผ่นแรกในสเปรดชีต ให้ตั้งค่าเป็น 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});

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sheetNameStringชื่อของชีตใหม่
sheetIndexIntegerดัชนีของชีตที่แทรกใหม่ หากต้องการแทรกชีตเป็นแผ่นแรกในสเปรดชีต ให้ตั้งค่าเป็น 0
optionsObjectอาร์กิวเมนต์ขั้นสูงของ JavaScript ที่ไม่บังคับ

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
templateSheetระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตของชีตต้องเป็นหนึ่งในชีตของออบเจ็กต์สเปรดชีต

ขากลับ

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});

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sheetNameStringชื่อของชีตใหม่
optionsObjectอาร์กิวเมนต์ขั้นสูงของ JavaScript ที่ไม่บังคับ

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
templateSheetระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตของชีตต้องเป็นหนึ่งในชีตของออบเจ็กต์สเปรดชีต

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
specDataSourceSpecข้อกำหนดของแหล่งข้อมูลที่จะแทรก

ขากลับ

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));

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnPositionIntegerตําแหน่งของคอลัมน์ที่จะตรวจสอบ

ขากลับ

Booleantrue หากซ่อนคอลัมน์ไว้ จะเป็น 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());

ขากลับ

Booleantrue หากเปิดใช้งานการคำนวณแบบวนซ้ำ หากไม่เปิดใช้ 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));

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowPositionIntegerตําแหน่งของแถวที่ต้องการตรวจสอบ

ขากลับ

Booleantrue หากซ่อนแถวไว้ จะเป็น 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));

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowPositionIntegerตําแหน่งของแถวที่ต้องการตรวจสอบ

ขากลับ

Booleantrue หากซ่อนแถวไว้ จะเป็น 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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
posIntegerตำแหน่งดัชนีแบบ 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
chartEmbeddedChartแผนภูมิที่จะย้าย

ขากลับ

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 อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้

สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ออกจากรายการผู้มีสิทธิ์อ่านด้วย

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressStringอีเมลของผู้ใช้ที่จะนำออก

ขากลับ

SpreadsheetSpreadsheet นี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeEditor(user)

นำผู้ใช้ที่ระบุออกจากรายชื่อผู้แก้ไขของ Spreadsheet วิธีการนี้จะไม่บล็อกผู้ใช้จากการเข้าถึง Spreadsheet หากผู้ใช้อยู่ในกลุ่มผู้ใช้ที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Spreadsheet กับทั้งโดเมนของผู้ใช้ หรือหาก Spreadsheet อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้

สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ออกจากรายการผู้มีสิทธิ์อ่านด้วย

พารามิเตอร์

ชื่อประเภทคำอธิบาย
userUserตัวแทนของผู้ใช้ที่จะนำออก

ขากลับ

SpreadsheetSpreadsheet นี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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
}

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อเมนูที่จะนำออก

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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");

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อของช่วง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeViewer(emailAddress)

นำผู้ใช้รายดังกล่าวออกจากรายการผู้มีสิทธิ์อ่านและผู้แสดงความคิดเห็นสำหรับ Spreadsheet วิธีการนี้จะไม่มีผลหากผู้ใช้เป็นเอดิเตอร์ ไม่ใช่ผู้มีสิทธิ์อ่านหรือผู้แสดงความคิดเห็น นอกจากนี้ วิธีการนี้จะไม่บล็อกผู้ใช้จากการเข้าถึง Spreadsheet หากผู้ใช้อยู่ในกลุ่มผู้ใช้ที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Spreadsheet กับทั้งโดเมนของผู้ใช้ หรือหาก Spreadsheet อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้

สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ออกจากรายการเอดิเตอร์ด้วย

พารามิเตอร์

ชื่อประเภทคำอธิบาย
emailAddressStringอีเมลของผู้ใช้ที่จะนำออก

ขากลับ

SpreadsheetSpreadsheet นี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

removeViewer(user)

นำผู้ใช้รายดังกล่าวออกจากรายการผู้มีสิทธิ์อ่านและผู้แสดงความคิดเห็นสำหรับ Spreadsheet วิธีการนี้จะไม่มีผลหากผู้ใช้เป็นผู้แก้ไข ไม่ใช่ผู้ชม และไม่บล็อกผู้ใช้จากการเข้าถึง Spreadsheet หากผู้ใช้อยู่ในกลุ่มผู้ใช้ที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Spreadsheet กับทั้งโดเมนของผู้ใช้ หรือSpreadsheet อยู่ในไดรฟ์ที่แชร์ที่ผู้ใช้เข้าถึงได้

สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ออกจากรายการเอดิเตอร์ด้วย

พารามิเตอร์

ชื่อประเภทคำอธิบาย
userUserตัวแทนของผู้ใช้ที่จะนำออก

ขากลับ

SpreadsheetSpreadsheet นี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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");

พารามิเตอร์

ชื่อประเภทคำอธิบาย
newNameStringชื่อใหม่สำหรับเอกสาร

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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");

พารามิเตอร์

ชื่อประเภทคำอธิบาย
newNameStringชื่อใหม่ของชีตที่ใช้งานอยู่ในปัจจุบัน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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();

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rangeRangeช่วงที่จะตั้งค่าเป็นช่วงที่มีการใช้งาน

ขากลับ

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();

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rangeListRangeListรายการช่วงที่จะเลือก

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rangeRangeช่วงที่ตั้งค่าเป็นการเลือกที่ใช้งานอยู่

ขากลับ

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");

พารามิเตอร์

ชื่อประเภทคำอธิบาย
a1NotationStringช่วงที่จะตั้งค่าเป็นใช้งานอยู่ตามที่ระบุไว้ในสัญลักษณ์ 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]);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sheetSheetแผ่นงานที่จะตั้งเป็นแผ่นงานที่ใช้งานอยู่

ขากลับ

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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sheetSheetชีตใหม่ที่ใช้งานอยู่
restoreSelectionBooleanตัวเลือก 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnPositionIntegerตําแหน่งของคอลัมน์ที่กําหนดเพื่อตั้งค่า
widthIntegerความกว้างเป็นพิกเซลที่จะตั้งค่า

ขากลับ

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();

พารามิเตอร์

ชื่อประเภทคำอธิบาย
cellRangeเซลล์ที่จะตั้งค่าเป็นเซลล์ปัจจุบัน

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnsIntegerจำนวนคอลัมน์ที่จะตรึง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowsIntegerจำนวนแถวที่จะตรึง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
minThresholdNumberเกณฑ์การบรรจบขั้นต่ำ (ต้องไม่เป็นค่าลบ)

ขากลับ

Spreadsheet — สเปรดชีตนี้สำหรับการทำเชน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setIterativeCalculationEnabled(isEnabled)

ตั้งค่าว่าจะเปิดใช้งานการคำนวณแบบวนซ้ำในสเปรดชีตนี้หรือไม่ หากไม่ได้กำหนดจำนวนรอบการคำนวณสูงสุดและเกณฑ์การบรรจบกันไว้ก่อนหน้าเมื่อเปิดใช้งานการคำนวณ ค่าเริ่มต้นจะเป็น 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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
isEnabledBooleantrue หากควรเปิดใช้การคำนวณแบบวนซ้ำ หรือ 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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
maxIterationsIntegerจำนวนครั้งสูงสุดในการคำนวณซ้ำ (ระหว่าง 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());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อที่จะกำหนดช่วง
rangeRangeข้อกำหนดของช่วง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
recalculationIntervalRecalculationIntervalช่วงการคำนวณใหม่

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowPositionIntegerตําแหน่งของแถวที่จะเปลี่ยน
heightIntegerความสูงเป็นพิกเซลที่จะตั้งค่า

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
localeStringรหัสภาษาที่จะใช้ (เช่น "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]);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
themeSpreadsheetThemeธีมที่จะใช้

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
timezoneStringเขตเวลาที่ระบุในรูปแบบ "long" (ตัวอย่างเช่น "America/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.

พารามิเตอร์

ชื่อประเภทคำอธิบาย
userInterfaceObjectHtmlOutput

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnPositionIntegerคอลัมน์ที่จะจัดเรียง

ขากลับ

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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnPositionIntegerคอลัมน์ที่จะจัดเรียง
ascendingBooleantrue เพื่อจัดเรียงจากน้อยไปหามาก 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');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
msgStringข้อความที่จะแสดงในข้อความโทสต์

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
msgStringข้อความที่จะแสดงในข้อความโทสต์
titleStringชื่อของข้อความโทสต์ (ไม่บังคับ)

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
msgStringข้อความที่จะแสดงในข้อความโทสต์
titleStringชื่อของข้อความโทสต์ (ไม่บังคับ)
timeoutSecondsNumberระยะหมดเวลาในหน่วยวินาที หาก 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnRangeช่วงที่จะเลิกซ่อน หากซ่อนอยู่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowRangeช่วงที่จะเลิกซ่อน หากซ่อนอยู่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 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);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อของเมนูที่จะอัปเดต
subMenusObject[]อาร์เรย์ของ JavaScript ที่มีพารามิเตอร์ name และ functionName คุณใช้ฟังก์ชันจากไลบรารีที่รวมอยู่ได้ เช่น Library.libFunction1

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

waitForAllDataExecutionsCompletion(timeoutInSeconds)

รอจนกว่าการดำเนินการปัจจุบันทั้งหมดในสเปรดชีตจะเสร็จสมบูรณ์ และหมดเวลาหลังจากการดำเนินการครบจำนวนวินาทีที่ระบุ จะแสดงข้อยกเว้นหากการดำเนินการไม่เสร็จสมบูรณ์เมื่อหมดเวลา แต่ไม่ได้ยกเลิกการเรียกใช้ข้อมูล

พารามิเตอร์

ชื่อประเภทคำอธิบาย
timeoutInSecondsIntegerเวลาที่รอการเรียกใช้ข้อมูล หน่วยเป็นวินาที ความยาวสูงสุดคือ 300 วินาที

การให้สิทธิ์

สคริปต์ที่ใช้วิธีการนี้จะต้องมีการให้สิทธิ์ตามขอบเขตต่อไปนี้อย่างน้อย 1 รายการ

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

วิธีการที่เลิกใช้งานแล้ว