Class Sheet

ชีต

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

เมธอด

วิธีการประเภทการแสดงผลรายละเอียดแบบย่อ
activate()Sheetเปิดใช้งานชีตนี้
addDeveloperMetadata(key)Sheetเพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ที่ระบุลงในชีต
addDeveloperMetadata(key, visibility)Sheetเพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์และการเปิดเผยที่ระบุลงในชีต
addDeveloperMetadata(key, value)Sheetเพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์และค่าที่ระบุลงในชีต
addDeveloperMetadata(key, value, visibility)Sheetเพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ ค่า และระดับการเข้าถึงที่ระบุลงในชีต
appendRow(rowContents)Sheetเพิ่มแถวที่ด้านล่างของเขตข้อมูลปัจจุบันในชีต
asDataSourceSheet()DataSourceSheetแสดงผลชีตเป็น DataSourceSheet หากชีตเป็นประเภท SheetType.DATASOURCE หรือ null ในกรณีอื่นๆ
autoResizeColumn(columnPosition)Sheetตั้งค่าความกว้างของคอลัมน์ที่ระบุให้พอดีกับเนื้อหา
autoResizeColumns(startColumn, numColumns)Sheetกำหนดความกว้างของคอลัมน์ทั้งหมดโดยเริ่มที่ตำแหน่งคอลัมน์ที่ระบุเพื่อให้พอดีกับเนื้อหา
autoResizeRows(startRow, numRows)Sheetกำหนดความสูงของแถวทั้งหมดโดยเริ่มที่ตำแหน่งแถวที่ระบุเพื่อให้พอดีกับเนื้อหา
clear()Sheetล้างข้อมูลเนื้อหาและการจัดรูปแบบในชีต
clear(options)Sheetล้างเนื้อหาและ/หรือรูปแบบของชีตตามที่ระบุด้วยตัวเลือกขั้นสูงที่กำหนด
clearConditionalFormatRules()voidนํากฎรูปแบบตามเงื่อนไขทั้งหมดออกจากชีต
clearContents()Sheetล้างเนื้อหาในชีต แต่จะเก็บข้อมูลการจัดรูปแบบไว้
clearFormats()Sheetล้างการจัดรูปแบบชีตโดยคงเนื้อหาไว้
clearNotes()Sheetล้างโน้ตทั้งหมดในชีต
collapseAllColumnGroups()Sheetยุบกลุ่มคอลัมน์ทั้งหมดในชีต
collapseAllRowGroups()Sheetยุบกลุ่มแถวทั้งหมดในชีต
copyTo(spreadsheet)Sheetคัดลอกชีตไปยังสเปรดชีตที่ระบุ ซึ่งอาจเป็นสเปรดชีตเดียวกันกับแหล่งที่มาก็ได้
createDeveloperMetadataFinder()DeveloperMetadataFinderแสดงผล DeveloperMetadataFinder สำหรับค้นหาข้อมูลเมตาของนักพัฒนาแอปภายในขอบเขตของ ชีตนี้
createTextFinder(findText)TextFinderสร้างเครื่องมือค้นหาข้อความสำหรับชีต ซึ่งสามารถค้นหาและแทนที่ข้อความภายในชีตได้
deleteColumn(columnPosition)Sheetลบคอลัมน์ในตำแหน่งคอลัมน์ที่ระบุ
deleteColumns(columnPosition, howMany)voidลบคอลัมน์จำนวนหนึ่งโดยเริ่มจากตำแหน่งคอลัมน์ที่ระบุ
deleteRow(rowPosition)Sheetลบแถวในตำแหน่งแถวที่ระบุ
deleteRows(rowPosition, howMany)voidลบจำนวนแถวที่เริ่มต้นที่ตำแหน่งแถวที่ระบุ
expandAllColumnGroups()Sheetขยายกลุ่มคอลัมน์ทั้งหมดในชีต
expandAllRowGroups()Sheetขยายกลุ่มแถวทั้งหมดในชีต
expandColumnGroupsUpToDepth(groupDepth)Sheetขยายกลุ่มคอลัมน์ทั้งหมดจนถึงระดับความลึกที่ระบุ และยุบกลุ่มอื่นๆ ทั้งหมด
expandRowGroupsUpToDepth(groupDepth)Sheetขยายกลุ่มแถวทั้งหมดจนถึงระดับที่ระบุ และยุบกลุ่มอื่นๆ ทั้งหมด
getActiveCell()Rangeแสดงผลเซลล์ที่ใช้งานอยู่ในชีตนี้
getActiveRange()Rangeแสดงช่วงที่เลือกในชีตที่ใช้งานอยู่ หรือ null หากไม่มีช่วงที่ใช้งานอยู่
getActiveRangeList()RangeListแสดงรายการช่วงที่ใช้งานอยู่ในชีตที่ใช้งานอยู่ หรือ null หากไม่มีช่วงที่ใช้งานอยู่
getBandings()Banding[]แสดงการแบนทั้งหมดในชีตนี้
getCharts()EmbeddedChart[]แสดงผลอาร์เรย์ของแผนภูมิในชีตนี้
getColumnGroup(columnIndex, groupDepth)Groupแสดงผลกลุ่มคอลัมน์ที่ดัชนีและความลึกของกลุ่มที่ระบุ
getColumnGroupControlPosition()GroupControlTogglePositionแสดงผล GroupControlTogglePosition สำหรับกลุ่มคอลัมน์ทั้งหมดในชีต
getColumnGroupDepth(columnIndex)Integerแสดงผลความลึกของกลุ่มของคอลัมน์ที่ดัชนีที่ระบุ
getColumnWidth(columnPosition)Integerรับความกว้างเป็นพิกเซลของคอลัมน์ที่ระบุ
getConditionalFormatRules()ConditionalFormatRule[]รับกฎการจัดรูปแบบตามเงื่อนไขทั้งหมดในชีตนี้
getCurrentCell()Rangeแสดงผลเซลล์ปัจจุบันในชีตที่ใช้งานอยู่หรือ null หากไม่มีเซลล์ปัจจุบัน
getDataRange()Rangeแสดงผล Range ที่สอดคล้องกับมิติข้อมูลที่มีข้อมูล
getDataSourceFormulas()DataSourceFormula[]รับสูตรแหล่งข้อมูลทั้งหมด
getDataSourcePivotTables()DataSourcePivotTable[]รับตาราง Pivot ของแหล่งข้อมูลทั้งหมด
getDataSourceTables()DataSourceTable[]รับตารางแหล่งข้อมูลทั้งหมด
getDeveloperMetadata()DeveloperMetadata[]รับข้อมูลเมตานักพัฒนาแอปทั้งหมดที่เชื่อมโยงกับชีตนี้
getDrawings()Drawing[]แสดงผลอาร์เรย์ของภาพวาดในชีต
getFilter()Filterแสดงตัวกรองในชีตนี้ หรือ null หากไม่มีตัวกรอง
getFormUrl()Stringแสดง URL ของแบบฟอร์มที่ส่งคำตอบไปยังชีตนี้ หรือ null หากชีตนี้ไม่มีแบบฟอร์มที่เชื่อมโยง
getFrozenColumns()Integerแสดงผลจำนวนคอลัมน์ที่ตรึง
getFrozenRows()Integerแสดงผลจำนวนแถวที่ตรึง
getImages()OverGridImage[]แสดงรูปภาพทั้งหมดที่อยู่นอกตารางกริดในชีต
getIndex()Integerรับตำแหน่งของชีตในสเปรดชีตหลัก
getLastColumn()Integerแสดงตำแหน่งของคอลัมน์สุดท้ายที่มีเนื้อหา
getLastRow()Integerแสดงตำแหน่งของแถวสุดท้ายที่มีเนื้อหา
getMaxColumns()Integerแสดงผลจำนวนคอลัมน์ปัจจุบันในชีตโดยไม่คำนึงถึงเนื้อหา
getMaxRows()Integerแสดงผลจำนวนแถวปัจจุบันในชีตโดยไม่คำนึงถึงเนื้อหา
getName()Stringแสดงผลชื่อชีต
getNamedRanges()NamedRange[]รับช่วงที่ตั้งชื่อทั้งหมดในชีตนี้
getParent()Spreadsheetแสดง Spreadsheet ที่มีชีตนี้
getPivotTables()PivotTable[]แสดงตาราง Pivot ทั้งหมดในชีตนี้
getProtections(type)Protection[]รับอาร์เรย์ของออบเจ็กต์ที่แสดงช่วงที่ป้องกันทั้งหมดในชีต หรืออาร์เรย์ที่มีองค์ประกอบเดียวซึ่งแสดงการป้องกันในชีตเอง
getRange(row, column)Rangeแสดงผลช่วงที่มีเซลล์ซ้ายบนที่พิกัดที่ระบุ
getRange(row, column, numRows)Rangeแสดงผลช่วงที่มีเซลล์ด้านซ้ายบนที่พิกัดที่ระบุ และมีจำนวน แถวที่ระบุ
getRange(row, column, numRows, numColumns)Rangeแสดงผลช่วงที่มีเซลล์ด้านซ้ายบนที่พิกัดที่กำหนดโดยมีจำนวนแถว และคอลัมน์ที่กำหนด
getRange(a1Notation)Rangeแสดงผลช่วงตามที่ระบุในรูปแบบ A1 หรือ R1C1
getRangeList(a1Notations)RangeListแสดงผลคอลเล็กชัน RangeList ที่แสดงช่วงในชีตเดียวกันซึ่งระบุโดยรายการสัญกรณ์ A1 หรือสัญกรณ์ R1C1 ที่ไม่ว่าง
getRowGroup(rowIndex, groupDepth)Groupแสดงผลกลุ่มแถวที่ดัชนีและความลึกของกลุ่มที่ระบุ
getRowGroupControlPosition()GroupControlTogglePositionแสดงผล GroupControlTogglePosition สำหรับกลุ่มแถวทั้งหมดในชีต
getRowGroupDepth(rowIndex)Integerแสดงผลระดับกลุ่มของแถวที่ดัชนีที่ระบุ
getRowHeight(rowPosition)Integerรับความสูงเป็นพิกเซลของแถวที่ระบุ
getSelection()Selectionแสดงผล Selection ปัจจุบันในสเปรดชีต
getSheetId()Integerแสดงผลรหัสของชีตที่ออบเจ็กต์นี้แสดง
getSheetName()Stringแสดงผลชื่อชีต
getSheetValues(startRow, startColumn, numRows, numColumns)Object[][]แสดงผลตารางกริดสี่เหลี่ยมของค่าสำหรับช่วงนี้โดยเริ่มที่พิกัดที่ระบุ
getSlicers()Slicer[]แสดงผลอาร์เรย์ของ Slicer ในชีต
getTabColorObject()Colorรับสีแท็บชีต หรือ null หากแท็บชีตไม่มีสี
getType()SheetTypeแสดงผลประเภทของชีต
hasHiddenGridlines()Booleanแสดงผล true หากซ่อนเส้นตารางของชีตไว้ หรือแสดงผล false ในกรณีอื่นๆ
hideColumn(column)voidซ่อนคอลัมน์ในช่วงที่ระบุ
hideColumns(columnIndex)voidซ่อนคอลัมน์เดียวที่ดัชนีที่ระบุ
hideColumns(columnIndex, numColumns)voidซ่อนคอลัมน์ที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์โดยเริ่มจากดัชนีที่ระบุ
hideRow(row)voidซ่อนแถวในช่วงที่ระบุ
hideRows(rowIndex)voidซ่อนแถวที่ดัชนีที่ระบุ
hideRows(rowIndex, numRows)voidซ่อนแถวที่ต่อเนื่องกันอย่างน้อย 1 แถวโดยเริ่มจากดัชนีที่ระบุ
hideSheet()Sheetซ่อนชีตนี้
insertChart(chart)voidเพิ่มแผนภูมิใหม่ลงในชีตนี้
insertColumnAfter(afterPosition)Sheetแทรกคอลัมน์หลังตำแหน่งคอลัมน์ที่ระบุ
insertColumnBefore(beforePosition)Sheetแทรกคอลัมน์ก่อนตำแหน่งคอลัมน์ที่ระบุ
insertColumns(columnIndex)voidแทรกคอลัมน์ว่างในชีตที่ตำแหน่งที่ระบุ
insertColumns(columnIndex, numColumns)voidแทรกคอลัมน์ว่างที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์ในชีตโดยเริ่มจากตำแหน่งที่ระบุ
insertColumnsAfter(afterPosition, howMany)Sheetแทรกคอลัมน์ตามจำนวนที่ระบุหลังจากตำแหน่งคอลัมน์ที่ระบุ
insertColumnsBefore(beforePosition, howMany)Sheetแทรกคอลัมน์จำนวนหนึ่งก่อนตำแหน่งคอลัมน์ที่ระบุ
insertImage(blobSource, column, row)OverGridImageแทรก BlobSource เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ
insertImage(blobSource, column, row, offsetX, offsetY)OverGridImageแทรก BlobSource เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ โดยมีออฟเซ็ต พิกเซล
insertImage(url, column, row)OverGridImageแทรกรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ
insertImage(url, column, row, offsetX, offsetY)OverGridImageแทรกรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ โดยมีค่าออฟเซ็ตเป็นพิกเซล
insertRowAfter(afterPosition)Sheetแทรกแถวหลังตำแหน่งแถวที่ระบุ
insertRowBefore(beforePosition)Sheetแทรกแถวก่อนตำแหน่งแถวที่ระบุ
insertRows(rowIndex)voidแทรกแถวว่างในชีตที่ตำแหน่งที่ระบุ
insertRows(rowIndex, numRows)voidแทรกแถวว่างที่ต่อเนื่องกันอย่างน้อย 1 แถวในชีตโดยเริ่มจากตำแหน่งที่ระบุ
insertRowsAfter(afterPosition, howMany)Sheetแทรกจำนวนแถวหลังจากตำแหน่งแถวที่ระบุ
insertRowsBefore(beforePosition, howMany)Sheetแทรกจำนวนแถวก่อนตำแหน่งแถวที่ระบุ
insertSlicer(range, anchorRowPos, anchorColPos)Slicerเพิ่ม Slicer ใหม่ลงในชีตนี้
insertSlicer(range, anchorRowPos, anchorColPos, offsetX, offsetY)Slicerเพิ่ม Slicer ใหม่ลงในชีตนี้
isColumnHiddenByUser(columnPosition)Booleanแสดงผลว่าผู้ใช้ซ่อนคอลัมน์ที่ระบุหรือไม่
isRightToLeft()Booleanแสดงผล true หากเลย์เอาต์ชีตนี้เป็นจากขวาไปซ้าย
isRowHiddenByFilter(rowPosition)Booleanแสดงว่าแถวที่ระบุซ่อนอยู่ตามตัวกรอง (ไม่ใช่มุมมองตัวกรอง) หรือไม่
isRowHiddenByUser(rowPosition)Booleanแสดงผลว่าผู้ใช้ซ่อนแถวที่ระบุหรือไม่
isSheetHidden()Booleanแสดง true หากชีตซ่อนอยู่
moveColumns(columnSpec, destinationIndex)voidย้ายคอลัมน์ที่เลือกตามช่วงที่ระบุไปยังตำแหน่งที่ระบุโดย destinationIndex
moveRows(rowSpec, destinationIndex)voidย้ายแถวที่เลือกตามช่วงที่ระบุไปยังตำแหน่งที่ระบุโดย destinationIndex
newChart()EmbeddedChartBuilderแสดงผล Builder เพื่อสร้างแผนภูมิใหม่สำหรับชีตนี้
protect()Protectionสร้างออบเจ็กต์ที่ป้องกันไม่ให้มีการแก้ไขชีตได้ ยกเว้นผู้ใช้ที่มี สิทธิ์
removeChart(chart)voidนำแผนภูมิออกจากชีตหลัก
setActiveRange(range)Rangeกำหนดช่วงที่ระบุเป็นactive rangeในชีตที่ใช้งานอยู่ โดยมีเซลล์ซ้ายบนสุดในช่วงเป็นcurrent cell
setActiveRangeList(rangeList)RangeListตั้งค่ารายการช่วงที่ระบุเป็น active ranges ในชีตที่ใช้งานอยู่
setActiveSelection(range)Rangeตั้งค่าภูมิภาคที่เลือกที่ใช้งานอยู่สำหรับชีตนี้
setActiveSelection(a1Notation)Rangeตั้งค่าการเลือกที่ใช้งานอยู่ตามที่ระบุในรูปแบบ A1 หรือ R1C1
setColumnGroupControlPosition(position)Sheetกำหนดตำแหน่งของปุ่มเปิด/ปิดการควบคุมกลุ่มคอลัมน์ในชีต
setColumnWidth(columnPosition, width)Sheetกำหนดความกว้างของคอลัมน์ที่ระบุเป็นพิกเซล
setColumnWidths(startColumn, numColumns, width)Sheetกำหนดความกว้างของคอลัมน์ที่ระบุในหน่วยพิกเซล
setConditionalFormatRules(rules)voidแทนที่กฎการจัดรูปแบบตามเงื่อนไขที่มีอยู่ในชีตทั้งหมดด้วยกฎที่ป้อน
setCurrentCell(cell)Rangeตั้งค่าเซลล์ที่ระบุเป็น current cell
setFrozenColumns(columns)voidตรึงจำนวนคอลัมน์ที่ระบุ
setFrozenRows(rows)voidตรึงจำนวนแถวที่ระบุ
setHiddenGridlines(hideGridlines)Sheetซ่อนหรือแสดงเส้นตารางแผ่นงาน
setName(name)Sheetตั้งชื่อชีต
setRightToLeft(rightToLeft)Sheetตั้งค่าหรือยกเลิกการตั้งค่าเลย์เอาต์ชีตเป็นจากขวาไปซ้าย
setRowGroupControlPosition(position)Sheetตั้งค่าตำแหน่งของปุ่มเปิด/ปิดการควบคุมกลุ่มแถวในชีต
setRowHeight(rowPosition, height)Sheetกำหนดความสูงของแถวที่ระบุเป็นพิกเซล
setRowHeights(startRow, numRows, height)Sheetกำหนดความสูงของแถวที่ระบุเป็นพิกเซล
setRowHeightsForced(startRow, numRows, height)Sheetกำหนดความสูงของแถวที่ระบุเป็นพิกเซล
setTabColor(color)Sheetตั้งค่าสีแท็บแผ่นงาน
setTabColorObject(color)Sheetตั้งค่าสีแท็บแผ่นงาน
showColumns(columnIndex)voidเลิกซ่อนคอลัมน์ที่ดัชนีที่ระบุ
showColumns(columnIndex, numColumns)voidเลิกซ่อนคอลัมน์ที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์โดยเริ่มจากดัชนีที่ระบุ
showRows(rowIndex)voidเลิกซ่อนแถวที่ดัชนีที่ระบุ
showRows(rowIndex, numRows)voidเลิกซ่อนแถวที่ต่อเนื่องกันอย่างน้อย 1 แถวโดยเริ่มจากดัชนีที่ระบุ
showSheet()Sheetทำให้ชีตปรากฏ
sort(columnPosition)Sheetจัดเรียงชีตตามคอลัมน์จากน้อยไปมาก
sort(columnPosition, ascending)Sheetจัดเรียงชีตตามคอลัมน์
unhideColumn(column)voidเลิกซ่อนคอลัมน์ในช่วงที่กำหนด
unhideRow(row)voidเลิกซ่อนแถวในช่วงที่กำหนด
updateChart(chart)voidอัปเดตแผนภูมิในชีตนี้

เอกสารโดยละเอียด

activate()

เปิดใช้งานชีตนี้ ไม่ได้แก้ไขชีตเอง แต่แก้ไขเฉพาะแนวคิดของชีตที่ใช้งานอยู่ของชีตหลัก

// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.activate();

รีเทิร์น

Sheet — ชีตที่เพิ่งเปิดใช้งาน


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', );  // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Adds the key 'NAME' to the developer metadata for the sheet. sheet.addDeveloperMetadata('NAME');  // Gets the updated metadata info and logs it to the console. console.log(sheet.getDeveloperMetadata()[0].getKey());

พารามิเตอร์

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

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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', );  // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Adds the key 'NAME' and sets the developer metadata visibility to PROJECT // for the sheet. sheet.addDeveloperMetadata(     'NAME',     SpreadsheetApp.DeveloperMetadataVisibility.PROJECT, );  // Gets the updated metadata info and logs it to the console. const developerMetaData = sheet.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log(developerMetaData.getVisibility().toString());

พารามิเตอร์

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

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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', );  // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Adds the key 'COMPANY' with the value 'TECH' to the developer metadata for // the sheet. sheet.addDeveloperMetadata('COMPANY', 'TECH');  // Gets the updated metadata info and logs it to the console. const developerMetaData = sheet.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log(developerMetaData.getValue());

พารามิเตอร์

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

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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', );  // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Adds the key 'COMPANY' with the value 'TECH' to the developer metadata and // sets the visibility to DOCUMENT for the sheet. sheet.addDeveloperMetadata(     'COMPANY',     'TECH',     SpreadsheetApp.DeveloperMetadataVisibility.DOCUMENT, );  // Gets the updated metadata info and logs it to the console. const developerMetaData = sheet.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log(developerMetaData.getValue()); console.log(developerMetaData.getVisibility().toString());

พารามิเตอร์

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

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

appendRow(rowContents)

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

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

asDataSourceSheet()

แสดงผลชีตเป็น DataSourceSheet หากชีตเป็นประเภท SheetType.DATASOURCE หรือ null ในกรณีอื่นๆ

// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can useSpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl(     'https://docs.google.com/spreadsheets/d/abc123456/edit', );  // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Gets the data source sheet value if the sheet is of type // SpreadsheetApp.SheetType.DATASOURCE, otherwise this returns a null value. const dataSourceSheet = sheet.asDataSourceSheet();  // Gets the data source sheet value and logs it to the console. console.log(dataSourceSheet); console.log(sheet.getType().toString());

รีเทิร์น

DataSourceSheet - ชีตแหล่งข้อมูล

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

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

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

autoResizeColumn(columnPosition)

ตั้งค่าความกว้างของคอลัมน์ที่ระบุให้พอดีกับเนื้อหา

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

autoResizeColumns(startColumn, numColumns)

กำหนดความกว้างของคอลัมน์ทั้งหมดโดยเริ่มที่ตำแหน่งคอลัมน์ที่ระบุเพื่อให้พอดีกับเนื้อหา

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // Sets the first 15 columns to a width that fits their text. sheet.autoResizeColumns(1, 15);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startColumnIntegerคอลัมน์เริ่มต้นที่จะปรับขนาดอัตโนมัติ
numColumnsIntegerจำนวนคอลัมน์ที่จะปรับขนาดอัตโนมัติ

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

autoResizeRows(startRow, numRows)

กำหนดความสูงของแถวทั้งหมดโดยเริ่มที่ตำแหน่งแถวที่ระบุเพื่อให้พอดีกับเนื้อหา

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // Sets the first 15 rows to a height that fits their text. sheet.autoResizeRows(1, 15);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startRowIntegerแถวเริ่มต้นที่จะปรับขนาดอัตโนมัติ
numRowsIntegerจำนวนแถวที่จะปรับขนาดอัตโนมัติ

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

clear()

ล้างข้อมูลเนื้อหาและการจัดรูปแบบในชีต

// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.clear();

รีเทิร์น

Sheet — แผ่นงานที่ล้างแล้ว

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

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

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

clear(options)

ล้างเนื้อหาและ/หรือรูปแบบของชีตตามที่ระบุด้วยตัวเลือกขั้นสูงที่กำหนด

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; sheet.clear({formatOnly: true, contentsOnly: true});

พารามิเตอร์

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

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

ชื่อประเภทคำอธิบาย
contentsOnlyBooleanจะล้างเนื้อหาหรือไม่
formatOnlyBooleanเลือกว่าจะล้างรูปแบบไหม

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

clearConditionalFormatRules()

นํากฎรูปแบบตามเงื่อนไขทั้งหมดออกจากชีต เทียบเท่ากับการเรียกใช้ setConditionalFormatRules(rules) โดยมีอาร์เรย์ว่างเป็นอินพุต

const sheet = SpreadsheetApp.getActiveSheet(); sheet.clearConditionalFormatRules();

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

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

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

clearContents()

ล้างเนื้อหาในชีต แต่จะเก็บข้อมูลการจัดรูปแบบไว้

// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.clearContents();

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

clearFormats()

ล้างการจัดรูปแบบชีตโดยคงเนื้อหาไว้

การจัดรูปแบบหมายถึงวิธีจัดรูปแบบข้อมูลตามที่ตัวเลือกในเมนู "รูปแบบ" อนุญาต (เช่น ตัวหนา ตัวเอียง การจัดรูปแบบตามเงื่อนไข) ไม่ใช่ความกว้างหรือความสูงของเซลล์

// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.clearFormats();

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

clearNotes()

ล้างโน้ตทั้งหมดในชีต

// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.clearNotes();

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

collapseAllColumnGroups()

ยุบกลุ่มคอลัมน์ทั้งหมดในชีต

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // All column groups on the sheet are collapsed. sheet.collapseAllColumnGroups();

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

collapseAllRowGroups()

ยุบกลุ่มแถวทั้งหมดในชีต

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // All row groups on the sheet are collapsed. sheet.collapseAllRowGroups();

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

copyTo(spreadsheet)

คัดลอกชีตไปยังสเปรดชีตที่ระบุ ซึ่งอาจเป็นสเปรดชีตเดียวกันกับแหล่งที่มาก็ได้ แผ่นงานที่คัดลอกจะมีชื่อว่า "สำเนาของ [ชื่อเดิม]"

const source = SpreadsheetApp.getActiveSpreadsheet(); const sheet = source.getSheets()[0];  const destination = SpreadsheetApp.openById('ID_GOES HERE'); sheet.copyTo(destination);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
spreadsheetSpreadsheetสเปรดชีตที่จะคัดลอกชีตนี้ไป ซึ่งอาจเป็นสเปรดชีตเดียวกันกับ แหล่งที่มาก็ได้

รีเทิร์น

Sheet - ชีตใหม่สำหรับการเชื่อมโยง

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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', );  // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Adds developer metadata for testing. sheet.addDeveloperMetadata('CITY', 'PARIS');  // Creates the developer metadata finder. const metadatafinder = sheet.createDeveloperMetadataFinder();  // Finds the metadata with value 'PARIS' and displays its key in the console. console.log(metadatafinder.withValue('PARIS').find()[0].getKey());

รีเทิร์น

DeveloperMetadataFinder — เครื่องมือค้นหาข้อมูลเมตาของนักพัฒนาซอฟต์แวร์เพื่อค้นหาข้อมูลเมตาในขอบเขตของชีตนี้


createTextFinder(findText)

สร้างเครื่องมือค้นหาข้อความสำหรับชีต ซึ่งสามารถค้นหาและแทนที่ข้อความภายในชีตได้

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // Creates  a text finder. const textFinder = sheet.createTextFinder('dog');  // Returns the first occurrence of 'dog' in the sheet. const firstOccurrence = textFinder.findNext();  // Replaces the last found occurrence of 'dog' with 'cat' and returns the number // of occurrences replaced. const numOccurrencesReplaced = firstOccurrence.replaceWith('cat');

พารามิเตอร์

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

รีเทิร์น

TextFinderTextFinder ของชีต


deleteColumn(columnPosition)

ลบคอลัมน์ในตำแหน่งคอลัมน์ที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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)

ลบคอลัมน์จำนวนหนึ่งโดยเริ่มจากตำแหน่งคอลัมน์ที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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)

ลบแถวในตำแหน่งแถวที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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)

ลบจำนวนแถวที่เริ่มต้นที่ตำแหน่งแถวที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

expandAllColumnGroups()

ขยายกลุ่มคอลัมน์ทั้งหมดในชีต วิธีนี้ต้องมีกลุ่มคอลัมน์อย่างน้อย 1 กลุ่ม

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // All column groups on the sheet are expanded. sheet.expandAllColumnGroups();

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

expandAllRowGroups()

ขยายกลุ่มแถวทั้งหมดในชีต วิธีนี้ต้องมีกลุ่มแถวอย่างน้อย 1 กลุ่ม

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // All row groups on the sheet are expanded. sheet.expandAllRowGroups();

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

expandColumnGroupsUpToDepth(groupDepth)

ขยายกลุ่มคอลัมน์ทั้งหมดจนถึงระดับความลึกที่ระบุ และยุบกลุ่มอื่นๆ ทั้งหมด

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // All column groups of depth 2 and lower are expanded, and groups with depth // 3 and higher are collapsed. sheet.expandColumnGroupsUpToDepth(2);

พารามิเตอร์

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

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

expandRowGroupsUpToDepth(groupDepth)

ขยายกลุ่มแถวทั้งหมดจนถึงระดับที่ระบุ และยุบกลุ่มอื่นๆ ทั้งหมด

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // All row groups of depth 2 and lower are expanded, and groups with depth // 3 and higher are collapsed. sheet.expandRowGroupsUpToDepth(2);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
groupDepthIntegerความลึกของกลุ่มที่จะขยายกลุ่มแถว

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

getActiveCell()

แสดงผลเซลล์ที่ใช้งานอยู่ในชีตนี้

หมายเหตุ: ขอแนะนำให้ใช้ getCurrentCell() ซึ่งจะแสดงผลเซลล์ที่ไฮไลต์ในปัจจุบัน

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Returns the active cell const cell = sheet.getActiveCell();

รีเทิร์น

Range — เซลล์ที่ใช้งานอยู่ในปัจจุบัน

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

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

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

getActiveRange()

แสดงช่วงที่เลือกในชีตที่ใช้งานอยู่ หรือ null หากไม่มีช่วงที่ใช้งานอยู่ หากเลือกหลายช่วง วิธีนี้จะแสดงเฉพาะช่วงที่เลือกสุดท้าย

คำว่า "ช่วงที่ใช้งานอยู่" หมายถึงช่วงที่ผู้ใช้เลือกในชีตที่ใช้งานอยู่ แต่ในฟังก์ชันที่กำหนดเองจะหมายถึงเซลล์ที่กำลังคำนวณใหม่

const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const activeRange = sheet.getActiveRange();

รีเทิร์น

Range - ช่วงที่ใช้งานอยู่

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

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

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

ดูเพิ่มเติม


getActiveRangeList()

แสดงรายการช่วงที่ใช้งานอยู่ในชีตที่ใช้งานอยู่ หรือ null หากไม่มีช่วงที่ใช้งานอยู่

หากเลือกช่วงเดียว ฟังก์ชันนี้จะทำงานเป็นgetActiveRange()

const sheet = SpreadsheetApp.getActiveSheet(); // Returns the list of active ranges. const activeRangeList = sheet.getActiveRangeList();

รีเทิร์น

RangeList — รายการช่วงที่ใช้งานอยู่

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

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

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

ดูเพิ่มเติม


getBandings()

แสดงการแบนทั้งหมดในชีตนี้

// 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 a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Gets the banding info for the sheet. const bandings = sheet.getBandings();  // Gets info on the bandings' second row color and logs it to the console. for (const banding of bandings) {   console.log(banding.getSecondRowColor()); }

รีเทิร์น

Banding[] — แถบทั้งหมดในชีตนี้

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

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

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

getCharts()

แสดงผลอาร์เรย์ของแผนภูมิในชีตนี้

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; const charts = sheet.getCharts();  for (const i in charts) {   const chart = charts[i];   // Do something with the chart }

รีเทิร์น

EmbeddedChart[] — อาร์เรย์ของแผนภูมิ

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

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

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

getColumnGroup(columnIndex, groupDepth)

แสดงผลกลุ่มคอลัมน์ที่ดัชนีและความลึกของกลุ่มที่ระบุ

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // Returns the group whose control index is at column 2 and has a depth of 1, or // null if the group doesn’t exist. const columnGroup = sheet.getColumnGroup(2, 1);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnIndexIntegerดัชนีคอลัมน์ของปุ่มเปิด/ปิดการควบคุมกลุ่มหรือดัชนีภายในกลุ่ม
groupDepthIntegerความลึกของกลุ่ม

รีเทิร์น

Group — กลุ่มคอลัมน์ที่ดัชนีและความลึกของตัวควบคุม หรือแสดงข้อยกเว้นหากกลุ่ม ไม่มีอยู่

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

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

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

getColumnGroupControlPosition()

แสดงผล GroupControlTogglePosition สำหรับกลุ่มคอลัมน์ทั้งหมดในชีต

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // GroupControlTogglePosition.AFTER if the column grouping control toggle is // shown after the group. const columnGroupControlPosition = sheet.getColumnGroupControlPosition();

รีเทิร์น

GroupControlTogglePositiontrue หากปุ่มเปิด/ปิดการควบคุมการจัดกลุ่มคอลัมน์แสดงขึ้นหลังจากกลุ่มในชีตนี้ และ false ในกรณีอื่นๆ

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

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

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

getColumnGroupDepth(columnIndex)

แสดงผลความลึกของกลุ่มของคอลัมน์ที่ดัชนีที่ระบุ

ความลึกของกลุ่มจะระบุจำนวนกลุ่มที่ทับซ้อนกับคอลัมน์ ซึ่งอาจมีค่าตั้งแต่ 0 ถึง 8

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // 1 if there is a group over columns 1 through 3 const groupDepth = sheet.getColumnGroupDepth(1);

พารามิเตอร์

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

รีเทิร์น

Integer — ความลึกของกลุ่มของคอลัมน์ที่ดัชนีที่ระบุ

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

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

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

getColumnWidth(columnPosition)

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

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

getConditionalFormatRules()

รับกฎการจัดรูปแบบตามเงื่อนไขทั้งหมดในชีตนี้

// Logs the conditional format rules in a sheet. const rules = SpreadsheetApp.getActiveSheet().getConditionalFormatRules(); for (let i = 0; i < rules.length; i++) {   const rule = rules[i];   Logger.log(rule); }

รีเทิร์น

ConditionalFormatRule[] — อาร์เรย์ของกฎทั้งหมดในชีต

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

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

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

getCurrentCell()

แสดงผลเซลล์ปัจจุบันในชีตที่ใช้งานอยู่หรือ null หากไม่มีเซลล์ปัจจุบัน เซลล์ปัจจุบันคือเซลล์ที่โฟกัสใน UI ของ Google ชีต และมีการไฮไลต์ด้วยเส้นขอบสีเข้ม โดยจะมีเซลล์ปัจจุบันเพียงเซลล์เดียวเสมอ เมื่อผู้ใช้เลือกช่วงเซลล์อย่างน้อย 1 ช่วง เซลล์ใดเซลล์หนึ่งในการเลือกจะเป็นเซลล์ปัจจุบัน

const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // Returns the current highlighted cell in the one of the active ranges. const 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())

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // This represents ALL the data const range = sheet.getDataRange(); const values = range.getValues();  // This logs the spreadsheet in CSV format with a trailing comma for (let i = 0; i < values.length; i++) {   let row = '';   for (let 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

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

getDeveloperMetadata()

รับข้อมูลเมตานักพัฒนาแอปทั้งหมดที่เชื่อมโยงกับชีตนี้

// 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 a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Adds developer metadata for testing. sheet.addDeveloperMetadata('CITY', 'PARIS');  // Gets all the developer metadata for the sheet. const developerMetaDataList = sheet.getDeveloperMetadata();  // Logs the developer metadata to the console. for (const developerMetaData of developerMetaDataList) {   console.log(developerMetaData.getKey()); }

รีเทิร์น

DeveloperMetadata[] - ข้อมูลเมตาของนักพัฒนาแอปที่เชื่อมโยงกับชีตนี้

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

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

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

getDrawings()

แสดงผลอาร์เรย์ของภาพวาดในชีต

// 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 a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Gets all the drawings from the sheet. const allDrawings = sheet.getDrawings();  // Logs the number of drawings present on the sheet. console.log(allDrawings.length);

รีเทิร์น

Drawing[] — รายการภาพวาดในชีตนี้

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

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

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

getFilter()

แสดงตัวกรองในชีตนี้ หรือ null หากไม่มีตัวกรอง

// Gets the filter on the active sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter();

รีเทิร์น

Filter — ตัวกรอง

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

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

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

getFormUrl()

แสดง URL ของแบบฟอร์มที่ส่งคำตอบไปยังชีตนี้ หรือ null หากชีตนี้ไม่มีแบบฟอร์มที่เชื่อมโยง แสดงข้อยกเว้นหากผู้ใช้ไม่มีสิทธิ์แก้ไข สเปรดชีต

const sheet = SpreadsheetApp.getActiveSheet(); const url = sheet.getFormUrl();

รีเทิร์น

String — URL ของแบบฟอร์มที่จัดเก็บคำตอบไว้ในชีตนี้ หรือ null หากชีตนี้ไม่มีแบบฟอร์มที่เชื่อมโยง

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

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

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

getFrozenColumns()

แสดงผลจำนวนคอลัมน์ที่ตรึง

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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()

แสดงผลจำนวนแถวที่ตรึง

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

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

getIndex()

รับตำแหน่งของชีตในสเปรดชีตหลัก เริ่มที่ 1

const ss = SpreadsheetApp.getActiveSpreadsheet(); // Note that the JavaScript index is 0, but this logs 1 const sheet = ss.getSheets()[0]; // ... because spreadsheets are 1-indexed Logger.log(sheet.getIndex());

รีเทิร์น

Integer — ตำแหน่งของชีตในสเปรดชีตหลัก

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

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

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

getLastColumn()

แสดงตำแหน่งของคอลัมน์สุดท้ายที่มีเนื้อหา

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // This logs the value in the very last cell of this sheet const lastRow = sheet.getLastRow(); const lastColumn = sheet.getLastColumn(); const 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()

แสดงตำแหน่งของแถวสุดท้ายที่มีเนื้อหา

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // This logs the value in the very last cell of this sheet const lastRow = sheet.getLastRow(); const lastColumn = sheet.getLastColumn(); const lastCell = sheet.getRange(lastRow, lastColumn); Logger.log(lastCell.getValue());

รีเทิร์น

Integer — แถวสุดท้ายของชีตที่มีเนื้อหา

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

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

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

getMaxColumns()

แสดงผลจำนวนคอลัมน์ปัจจุบันในชีตโดยไม่คำนึงถึงเนื้อหา

// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); Logger.log(first.getMaxColumns());

รีเทิร์น

Integer - ความกว้างสูงสุดของชีต

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

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

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

getMaxRows()

แสดงผลจำนวนแถวปัจจุบันในชีตโดยไม่คำนึงถึงเนื้อหา

// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); Logger.log(first.getMaxRows());

รีเทิร์น

Integer — ความสูงสูงสุดของชีต

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

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

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

getName()

แสดงผลชื่อชีต

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; Logger.log(sheet.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. const namedRanges = SpreadsheetApp.getActiveSheet().getNamedRanges(); if (namedRanges.length > 1) {   Logger.log(namedRanges[0].getName()); }

รีเทิร์น

NamedRange[] — อาร์เรย์ของช่วงที่ตั้งชื่อทั้งหมดในชีต

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

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

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

getParent()

แสดง Spreadsheet ที่มีชีตนี้

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // parent is identical to ss const parent = sheet.getParent();

รีเทิร์น

Spreadsheet - สเปรดชีตหลัก

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

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

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

getPivotTables()

แสดงตาราง Pivot ทั้งหมดในชีตนี้

// 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 a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Gets all the pivot table info for the sheet. const pivotTables = sheet.getPivotTables();  // Logs the pivot tables to the console. for (const pivotTable of pivotTables) {   console.log(pivotTable.getSourceDataRange().getValues()); }

รีเทิร์น

PivotTable[] — ตาราง Pivot ในชีตนี้

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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. const sheet = SpreadsheetApp.getActiveSheet(); const protections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE); for (let i = 0; i < protections.length; i++) {   const protection = protections[i];   if (protection.canEdit()) {     protection.remove();   } }
// Remove sheet protection from the active sheet, if the user has permission to // edit it. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0]; 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(row, column)

แสดงผลช่วงที่มีเซลล์ซ้ายบนที่พิกัดที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Passing only two arguments returns a "range" with a single cell. const range = sheet.getRange(1, 1); const values = range.getValues(); Logger.log(values[0][0]);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowIntegerดัชนีแถวของเซลล์ที่จะแสดงผล โดยการจัดทำดัชนีแถวจะเริ่มต้นด้วย 1
columnIntegerดัชนีคอลัมน์ของเซลล์ที่จะแสดงผล โดยการจัดทำดัชนีคอลัมน์จะเริ่มต้นด้วย 1

รีเทิร์น

Range - ช่วงที่มีเฉพาะเซลล์นี้

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

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

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

getRange(row, column, numRows)

แสดงผลช่วงที่มีเซลล์ด้านซ้ายบนที่พิกัดที่ระบุ และมีจำนวน แถวที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // When the "numRows" argument is used, only a single column of data is // returned. const range = sheet.getRange(1, 1, 3); const values = range.getValues();  // Prints 3 values from the first column, starting from row 1. for (const row in values) {   for (const col in values[row]) {     Logger.log(values[row][col]);   } }

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowIntegerดัชนีแถวเริ่มต้นของช่วง โดยการจัดทำดัชนีแถวจะเริ่มต้นด้วย 1
columnIntegerดัชนีคอลัมน์ของช่วง โดยการจัดทำดัชนีคอลัมน์จะเริ่มต้นด้วย 1
numRowsIntegerจำนวนแถวที่จะแสดงผล

รีเทิร์น

Range — ช่วงที่มีคอลัมน์ข้อมูลเดียวที่มีจำนวนแถวที่ระบุ

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

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

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

getRange(row, column, numRows, numColumns)

แสดงผลช่วงที่มีเซลล์ด้านซ้ายบนที่พิกัดที่กำหนดโดยมีจำนวนแถว และคอลัมน์ที่กำหนด

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; const range = sheet.getRange(1, 1, 3, 3); const values = range.getValues();  // Print values from a 3x3 box. for (const row in values) {   for (const col in values[row]) {     Logger.log(values[row][col]);   } }

พารามิเตอร์

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

รีเทิร์น

Range — ช่วงที่สอดคล้องกับพื้นที่ที่ระบุ

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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" const ss = SpreadsheetApp.getActiveSpreadsheet(); const range = ss.getRange('Invoices!A1:D4');  // Get cell A1 on the first sheet const sheet = ss.getSheets()[0]; const cell = sheet.getRange('A1');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
a1NotationStringช่วงที่จะแสดงผลตามที่ระบุในรูปแบบ A1 หรือ R1C1

รีเทิร์น

Range — ช่วงที่ตำแหน่งที่กำหนด

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

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

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

getRangeList(a1Notations)

แสดงผลคอลเล็กชัน RangeList ที่แสดงช่วงในชีตเดียวกันซึ่งระบุโดยรายการสัญกรณ์ A1 หรือสัญกรณ์ R1C1 ที่ไม่ว่าง

// Get a list of ranges A1:D4, F1:H4. const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const 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

getRowGroup(rowIndex, groupDepth)

แสดงผลกลุ่มแถวที่ดัชนีและความลึกของกลุ่มที่ระบุ

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // Returns the group whose control index is at row 2 and has a depth of 1, or // null if the group doesn’t exist. const rowGroup = sheet.getRowGroup(2, 1);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowIndexIntegerดัชนีแถวของปุ่มเปิด/ปิดการควบคุมกลุ่มหรือดัชนีภายในกลุ่ม
groupDepthIntegerความลึกของกลุ่ม

รีเทิร์น

Group — กลุ่มแถวที่ดัชนีและความลึกของตัวควบคุม หรือแสดงข้อยกเว้นหากกลุ่ม ไม่มีอยู่

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

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

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

getRowGroupControlPosition()

แสดงผล GroupControlTogglePosition สำหรับกลุ่มแถวทั้งหมดในชีต

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // GroupControlTogglePosition.AFTER if the row grouping control toggle is shown // after the group. const rowGroupControlPosition = sheet.getRowGroupControlPosition();

รีเทิร์น

GroupControlTogglePositiontrue หากสลับการควบคุมการจัดกลุ่มแถวจะแสดงหลังกลุ่มในชีตนี้ และ false ในกรณีอื่นๆ

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

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

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

getRowGroupDepth(rowIndex)

แสดงผลระดับกลุ่มของแถวที่ดัชนีที่ระบุ

ความลึกของกลุ่มจะระบุจำนวนกลุ่มที่ทับซ้อนกับแถว โดยมีค่าตั้งแต่ 0 ถึง 8

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];  // 1 if there is a group over rows 1 through 3 const groupDepth = sheet.getRowGroupDepth(1);

พารามิเตอร์

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

รีเทิร์น

Integer — ความลึกของกลุ่มแถวที่ดัชนีที่ระบุ

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

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

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

getRowHeight(rowPosition)

รับความสูงเป็นพิกเซลของแถวที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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 ปัจจุบันในสเปรดชีต

const selection = SpreadsheetApp.getActiveSpreadsheet().getSelection(); const currentCell = selection.getCurrentCell();

รีเทิร์น

Selection — รายการที่เลือกในปัจจุบัน

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

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

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

getSheetId()

แสดงผลรหัสของชีตที่ออบเจ็กต์นี้แสดง

ซึ่งเป็นรหัสของชีตที่ไม่ซ้ำกันสำหรับสเปรดชีต รหัสคือจำนวนเต็มที่เพิ่มขึ้นอย่างต่อเนื่อง ซึ่งกำหนดเมื่อสร้างชีตและไม่ขึ้นอยู่กับตำแหน่งชีต ซึ่งจะมีประโยชน์เมื่อใช้ร่วมกับเมธอดต่างๆ เช่น Range.copyFormatToRange(gridId, column, columnEnd, row, rowEnd) ที่ใช้พารามิเตอร์ gridId แทนอินสแตนซ์ Sheet

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  Logger.log(sheet.getSheetId());

รีเทิร์น

Integer — รหัสของชีตที่ไม่ซ้ำกันในสเปรดชีต

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

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

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

getSheetName()

แสดงผลชื่อชีต

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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 ที่ระบุเป็นตำแหน่งแถวหรือคอลัมน์จะเทียบเท่ากับการรับแถวหรือคอลัมน์สุดท้าย ที่มีข้อมูลในชีต

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // The two samples below produce the same output let values = sheet.getSheetValues(1, 1, 3, 3); Logger.log(values);  const range = sheet.getRange(1, 1, 3, 3); values = range.getValues(); Logger.log(values);

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

getSlicers()

แสดงผลอาร์เรย์ของ Slicer ในชีต

// 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 a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Gets all slicers in the spreadsheet. const slicers = sheet.getSlicers();  // Logs the slicer titles to the console. for (const slicer of slicers) {   console.log(slicer.getTitle()); }

รีเทิร์น

Slicer[] — รายการ Slicer ในชีตนี้

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

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

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

getTabColorObject()

รับสีแท็บชีต หรือ null หากแท็บชีตไม่มีสี

// This example assumes there is a sheet named "Sheet1" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('Sheet1'); const color = first.getTabColorObject();

รีเทิร์น

Color — สีแท็บชีต หรือ null หากแท็บชีตไม่มีสี

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

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

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

getType()

แสดงผลประเภทของชีต

ประเภทชีตเริ่มต้นคือ SheetType.GRID ชีตที่มีออบเจ็กต์ฝังเพียงรายการเดียว เช่น EmbeddedChart จะเป็นชีต SheetType.OBJECT

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; Logger.log(sheet.getType());

รีเทิร์น

SheetType — ประเภทของชีต

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

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

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

hasHiddenGridlines()

แสดงผล true หากซ่อนเส้นตารางของชีตไว้ หรือแสดงผล false ในกรณีอื่นๆ เส้นตารางจะมองเห็นได้โดยค่าเริ่มต้น

// 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 a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Checks if the spreadsheet has hidden gridelines and logs the result to the // console. console.log(sheet.hasHiddenGridlines());

รีเทิร์น

Booleantrue หากซ่อนเส้นตารางไว้ หรือ false ในกรณีอื่นๆ

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

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

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

hideColumn(column)

ซ่อนคอลัมน์ในช่วงที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // This hides the first column let range = sheet.getRange('A1'); sheet.hideColumn(range);  // This hides the first 3 columns range = sheet.getRange('A:C'); sheet.hideColumn(range);

พารามิเตอร์

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

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

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

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

hideColumns(columnIndex)

ซ่อนคอลัมน์เดียวที่ดัชนีที่ระบุ ใช้อินเด็กซ์ 1 สำหรับเมธอดนี้

หากต้องการซ่อนคอลัมน์มากกว่า 1 คอลัมน์โดยใช้ดัชนี ให้ใช้ hideColumns(columnIndex, numColumns)

หากต้องการซ่อนคอลัมน์มากกว่า 1 คอลัมน์โดยใช้ช่วง ให้ใช้ hideColumn()

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Hides the first column sheet.hideColumns(1);

พารามิเตอร์

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

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

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

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

hideColumns(columnIndex, numColumns)

ซ่อนคอลัมน์ที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์โดยเริ่มจากดัชนีที่ระบุ ใช้อินเด็กซ์ 1 สำหรับเมธอดนี้

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Hides the first three columns sheet.hideColumns(1, 3);

พารามิเตอร์

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

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

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

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

hideRow(row)

ซ่อนแถวในช่วงที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // This hides the first row const range = sheet.getRange('A1'); sheet.hideRow(range);

พารามิเตอร์

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

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

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

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

hideRows(rowIndex)

ซ่อนแถวที่ดัชนีที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Hides the first row sheet.hideRows(1);

พารามิเตอร์

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

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

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

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

hideRows(rowIndex, numRows)

ซ่อนแถวที่ต่อเนื่องกันอย่างน้อย 1 แถวโดยเริ่มจากดัชนีที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Hides the first three rows sheet.hideRows(1, 3);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowIndexIntegerดัชนีเริ่มต้นของแถวที่จะซ่อน
numRowsIntegerจำนวนแถวที่จะซ่อน

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

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

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

hideSheet()

ซ่อนชีตนี้ ไม่มีผลหากซ่อนชีตอยู่แล้ว หากเรียกใช้เมธอดนี้ใน ชีตที่มองเห็นได้เท่านั้น เมธอดจะส่งข้อยกเว้น

const sheet = SpreadsheetApp.getActiveSheet(); sheet.hideSheet();

รีเทิร์น

Sheet — ชีตปัจจุบัน

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

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

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

insertChart(chart)

เพิ่มแผนภูมิใหม่ลงในชีตนี้

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // This creates a simple bar chart from the first three rows // of the first two columns of the spreadsheet const chart = sheet.newChart()                   .setChartType(Charts.ChartType.BAR)                   .addRange(sheet.getRange('A1:B4'))                   .setPosition(5, 5, 0, 0)                   .setOption('title', 'Dynamic Chart')                   .build(); sheet.insertChart(chart);

พารามิเตอร์

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

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

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

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

insertColumnAfter(afterPosition)

แทรกคอลัมน์หลังตำแหน่งคอลัมน์ที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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)

แทรกคอลัมน์ก่อนตำแหน่งคอลัมน์ที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

insertColumns(columnIndex)

แทรกคอลัมน์ว่างในชีตที่ตำแหน่งที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Shifts all columns by one sheet.insertColumns(1);

พารามิเตอร์

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

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

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

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

insertColumns(columnIndex, numColumns)

แทรกคอลัมน์ว่างที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์ในชีตโดยเริ่มจากตำแหน่งที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Shifts all columns by three sheet.insertColumns(1, 3);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnIndexIntegerดัชนีที่ระบุตำแหน่งที่จะแทรกคอลัมน์
numColumnsIntegerจำนวนคอลัมน์ที่จะแทรก

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

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

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

insertColumnsAfter(afterPosition, howMany)

แทรกคอลัมน์ตามจำนวนที่ระบุหลังจากตำแหน่งคอลัมน์ที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // Inserts two columns after the first column on the first sheet of the // spreadsheet. sheet.insertColumnsAfter(1, 2);

พารามิเตอร์

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

รีเทิร์น

Sheet - ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด

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

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

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

insertColumnsBefore(beforePosition, howMany)

แทรกคอลัมน์จำนวนหนึ่งก่อนตำแหน่งคอลัมน์ที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

insertImage(blobSource, column, row)

แทรก BlobSource เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ ระบบจะดึงข้อมูลขนาดรูปภาพ จากเนื้อหา Blob ขนาดของ BLOB สูงสุดที่รองรับคือ 2 MB

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  const binaryData = [];  // TODO(developer): Replace with your binary data. const 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)

แทรก BlobSource เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ โดยมีออฟเซ็ต พิกเซล ระบบจะดึงขนาดรูปภาพจากเนื้อหา Blob ขนาดของ BLOB ต้องไม่เกิน 2 MB

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  const binaryData = [];  // TODO(developer): Replace with your binary data. const 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 ที่ระบุต้องเข้าถึงได้แบบสาธารณะ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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 ที่ระบุต้องเข้าถึงได้แบบสาธารณะ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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)

แทรกแถวหลังตำแหน่งแถวที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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)

แทรกแถวก่อนตำแหน่งแถวที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

insertRows(rowIndex)

แทรกแถวว่างในชีตที่ตำแหน่งที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Shifts all rows down by one sheet.insertRows(1);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowIndexIntegerดัชนีที่ระบุตำแหน่งที่จะแทรกแถว

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

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

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

insertRows(rowIndex, numRows)

แทรกแถวว่างที่ต่อเนื่องกันอย่างน้อย 1 แถวในชีตโดยเริ่มจากตำแหน่งที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Shifts all rows down by three sheet.insertRows(1, 3);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowIndexIntegerดัชนีที่ระบุตำแหน่งที่จะแทรกแถว
numRowsIntegerจำนวนแถวที่จะแทรก

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

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

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

insertRowsAfter(afterPosition, howMany)

แทรกจำนวนแถวหลังจากตำแหน่งแถวที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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)

แทรกจำนวนแถวก่อนตำแหน่งแถวที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

insertSlicer(range, anchorRowPos, anchorColPos)

เพิ่ม Slicer ใหม่ลงในชีตนี้

// 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 a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Gets the range of the sheet. const range = sheet.getRange('A1:D10');  // Inserts the slicer with a random range into the sheet. const insertSlicers = sheet.insertSlicer(range.randomize(), 1, 10);  // Logs the insert slicer result to the console. console.log(insertSlicers);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rangeRangeช่วงที่สร้างตัวควบคุมตัวกรองทางด้านขวา
anchorRowPosIntegerด้านบนของตัวแบ่งส่วนข้อมูลจะยึดไว้ในแถวนี้
anchorColPosIntegerด้านบนของตัวแบ่งส่วนข้อมูลจะยึดไว้ในคอลัมน์นี้

รีเทิร์น

Slicer - ตัวควบคุมตัวกรองที่แทรกใหม่

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

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

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

insertSlicer(range, anchorRowPos, anchorColPos, offsetX, offsetY)

เพิ่ม Slicer ใหม่ลงในชีตนี้

// 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 a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Gets the range. const range = sheet.getRange('A1:D10');  // Inserts a slicer using the random range function. const insertSlicers = sheet.insertSlicer(range.randomize(), 1, 10, 0, 0);  // Logs the insert slicer result to the console. console.log(insertSlicers);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rangeRangeช่วงที่สร้างตัวควบคุมตัวกรองทางด้านขวา
anchorRowPosIntegerด้านบนของตัวแบ่งส่วนข้อมูลจะยึดไว้ในแถวนี้
anchorColPosIntegerด้านบนของตัวแบ่งส่วนข้อมูลจะยึดไว้ในคอลัมน์นี้
offsetXIntegerออฟเซ็ตแนวนอนจากมุมเซลล์เป็นพิกเซล
offsetYIntegerออฟเซ็ตแนวตั้งจากมุมของเซลล์ในหน่วยพิกเซล

รีเทิร์น

Slicer - ตัวควบคุมตัวกรองที่แทรกใหม่

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

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

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

isColumnHiddenByUser(columnPosition)

แสดงผลว่าผู้ใช้ซ่อนคอลัมน์ที่ระบุหรือไม่

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

isRightToLeft()

แสดงผล true หากเลย์เอาต์ชีตนี้เป็นจากขวาไปซ้าย แสดง false หากชีต ใช้เลย์เอาต์จากซ้ายไปขวาเริ่มต้น

// 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 a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Checks if a spreadsheet is ordered from right to left and logs the result to // the console. console.log(sheet.isRightToLeft());

รีเทิร์น

Booleantrue หากเป็นภาษาที่อ่านจากขวาไปซ้าย หรือ false ในกรณีอื่นๆ

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

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

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

isRowHiddenByFilter(rowPosition)

แสดงว่าแถวที่ระบุซ่อนอยู่ตามตัวกรอง (ไม่ใช่มุมมองตัวกรอง) หรือไม่

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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)

แสดงผลว่าผู้ใช้ซ่อนแถวที่ระบุหรือไม่

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

isSheetHidden()

แสดง true หากชีตซ่อนอยู่

const sheet = SpreadsheetApp.getActiveSheet(); if (sheet.isSheetHidden()) {   // do something... }

รีเทิร์น

Booleantrue หากชีตซ่อนอยู่ หรือ false หากชีตไม่ได้ซ่อนอยู่

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

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

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

moveColumns(columnSpec, destinationIndex)

ย้ายคอลัมน์ที่เลือกตามช่วงที่ระบุไปยังตำแหน่งที่ระบุโดย destinationIndex columnSpec ไม่จำเป็นต้องแสดงทั้งคอลัมน์หรือกลุ่มคอลัมน์ทั้งหมดอย่างถูกต้องเพื่อที่จะย้าย แต่จะเลือกคอลัมน์ทั้งหมดที่ช่วงครอบคลุม

// The code below moves rows A-B to destination index 5. // This results in those columns becoming columns C-D. const sheet = SpreadsheetApp.getActiveSheet(); // Selects column A and column B to be moved. const columnSpec = sheet.getRange('A1:B1'); sheet.moveColumns(columnSpec, 5);

พารามิเตอร์

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

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

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

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

moveRows(rowSpec, destinationIndex)

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

// The code below moves rows 1-2 to destination index 5. // This results in those rows becoming rows 3-4. const sheet = SpreadsheetApp.getActiveSheet(); // Selects row 1 and row 2 to be moved. const rowSpec = sheet.getRange('A1:A2'); sheet.moveRows(rowSpec, 5);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowSpecRangeช่วงที่ครอบคลุมแถวที่ควรย้าย
destinationIndexIntegerดัชนีที่ควรย้ายแถวไป โปรดทราบว่าดัชนีนี้อิงตามพิกัดก่อนที่จะย้ายแถว ระบบจะเลื่อนข้อมูลที่มีอยู่ลงมาเพื่อ เว้นที่ว่างสำหรับแถวที่ย้าย ในขณะที่นำแถวต้นฉบับออกจากตารางกริด ดังนั้น ข้อมูลอาจไปอยู่ในดัชนีอื่นที่ไม่ใช่ดัชนีที่ระบุไว้แต่แรก

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

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

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

newChart()

แสดงผล Builder เพื่อสร้างแผนภูมิใหม่สำหรับชีตนี้

ตัวอย่างนี้แสดงวิธีสร้างแผนภูมิใหม่

const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B8'); const chartBuilder = sheet.newChart(); chartBuilder.addRange(range)     .setChartType(Charts.ChartType.LINE)     .setPosition(2, 2, 0, 0)     .setOption('title', 'My Line Chart!'); sheet.insertChart(chartBuilder.build());

รีเทิร์น

EmbeddedChartBuilder - เครื่องมือสร้างเพื่อสร้างแผนภูมิใหม่


protect()

สร้างออบเจ็กต์ที่ป้องกันไม่ให้มีการแก้ไขชีตได้ ยกเว้นผู้ใช้ที่มี สิทธิ์ จนกว่าสคริปต์จะเปลี่ยนรายชื่อผู้แก้ไขชีตจริงๆ (โดยการเรียกใช้ Protection.removeEditor(emailAddress), Protection.removeEditor(user), Protection.removeEditors(emailAddresses), Protection.addEditor(emailAddress), Protection.addEditor(user), Protection.addEditors(emailAddresses) หรือการตั้งค่า ค่าใหม่สำหรับ Protection.setDomainEdit(editable)) สิทธิ์จะเหมือนกับสิทธิ์ของ สเปรดชีตเอง ซึ่งหมายความว่าชีตจะยังคงไม่ได้รับการปกป้อง หากชีตได้รับการป้องกันอยู่แล้ว วิธีนี้จะแสดงออบเจ็กต์ที่แสดงการตั้งค่าการป้องกันที่มีอยู่ ชีตที่ป้องกันอาจมีภูมิภาคที่ไม่ได้ป้องกัน

// Protect the active sheet, then remove all other users from the list of // editors. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.protect().setDescription('Sample protected sheet');  // Ensure the current user is an editor before removing others. Otherwise, if // the user's edit permission comes from a group, the script throws an exception // upon removing the group. const me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) {   protection.setDomainEdit(false); }

รีเทิร์น

Protection - ออบเจ็กต์ที่แสดงการตั้งค่าการป้องกัน

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

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

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

removeChart(chart)

นำแผนภูมิออกจากชีตหลัก

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // This removes all the embedded charts from the spreadsheet const charts = sheet.getCharts(); for (const i in charts) {   sheet.removeChart(charts[i]); }

พารามิเตอร์

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

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

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

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

setActiveRange(range)

กำหนดช่วงที่ระบุเป็นactive rangeในชีตที่ใช้งานอยู่ โดยมีเซลล์ซ้ายบนสุดในช่วงเป็นcurrent cell

const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const range = sheet.getRange('A1:D4'); sheet.setActiveRange(range);  const selection = sheet.getSelection(); // Current cell: A1 const currentCell = selection.getCurrentCell(); // Active Range: A1:D4 const 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

const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['D4', 'B2:C4']); sheet.setActiveRangeList(rangeList);  const selection = sheet.getSelection(); // Current cell: B2 const currentCell = selection.getCurrentCell(); // Active range: B2:C4 const activeRange = selection.getActiveRange(); // Active range list: [D4, B2:C4] const activeRangeList = selection.getActiveRangeList();

พารามิเตอร์

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

รีเทิร์น

RangeList — รายการช่วงที่เลือกใหม่

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

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

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

setActiveSelection(range)

ตั้งค่าภูมิภาคที่เลือกที่ใช้งานอยู่สำหรับชีตนี้

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  const 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

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

setColumnGroupControlPosition(position)

กำหนดตำแหน่งของปุ่มเปิด/ปิดการควบคุมกลุ่มคอลัมน์ในชีต

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; sheet.setColumnGroupControlPosition(     SpreadsheetApp.GroupControlTogglePosition.AFTER, );

พารามิเตอร์

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

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

setColumnWidth(columnPosition, width)

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

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

setColumnWidths(startColumn, numColumns, width)

กำหนดความกว้างของคอลัมน์ที่ระบุในหน่วยพิกเซล

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // Sets the first three columns to a width of 200 pixels sheet.setColumnWidths(1, 3, 200);

พารามิเตอร์

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

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

setConditionalFormatRules(rules)

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

// Remove one of the existing conditional format rules. const sheet = SpreadsheetApp.getActiveSheet(); const rules = sheet.getConditionalFormatRules(); rules.splice(1, 1);  // Deletes the 2nd format rule. sheet.setConditionalFormatRules(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rulesConditionalFormatRule[]กฎการจัดรูปแบบตามเงื่อนไขใหม่

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

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

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

setCurrentCell(cell)

ตั้งค่าเซลล์ที่ระบุเป็น current cell

หากเซลล์ที่ระบุอยู่ในช่วงที่เลือกไว้แล้ว ช่วงนั้นจะกลายเป็น ช่วงที่ใช้งานอยู่โดยมีเซลล์ดังกล่าวเป็นเซลล์ปัจจุบัน

หากเซลล์ที่ระบุไม่อยู่ในช่วงที่เลือก ระบบจะนำการเลือกที่มีอยู่ออก และเซลล์นั้นจะกลายเป็นเซลล์ปัจจุบันและช่วงที่ใช้งานอยู่

หมายเหตุ: Range ที่ระบุต้องประกอบด้วยเซลล์เดียว ไม่เช่นนั้นระบบจะแสดงข้อยกเว้น

const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const cell = sheet.getRange('B5'); sheet.setCurrentCell(cell);  const selection = sheet.getSelection(); // Current cell: B5 const currentCell = selection.getCurrentCell();

พารามิเตอร์

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

รีเทิร์น

Range — เซลล์ปัจจุบันที่ตั้งค่าใหม่

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

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

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

setFrozenColumns(columns)

ตรึงจำนวนคอลัมน์ที่ระบุ หากเป็น 0 ระบบจะไม่ตรึงคอลัมน์ใดๆ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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 ระบบจะไม่ตรึงแถวใดเลย

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

setHiddenGridlines(hideGridlines)

ซ่อนหรือแสดงเส้นตารางแผ่นงาน

// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can us eSpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl(     'https://docs.google.com/spreadsheets/d/abc123456/edit', );  // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Hides the gridlines in the sheet. sheet.setHiddenGridlines(true);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
hideGridlinesBooleanหาก true ให้ซ่อนเส้นตารางในชีตนี้ มิฉะนั้นให้แสดง เส้นตาราง

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

setName(name)

ตั้งชื่อชีต

// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.setName('not first anymore');

พารามิเตอร์

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

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

setRightToLeft(rightToLeft)

ตั้งค่าหรือยกเลิกการตั้งค่าเลย์เอาต์ชีตเป็นจากขวาไปซ้าย

// 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 a sheet by its name. const sheet = ss.getSheetByName('Sheet1');  // Sets the sheet layout, so that the sheet is ordered from right to left. sheet.setRightToLeft(true);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rightToLeftBooleanหากเป็น true ระบบจะตั้งค่าเลย์เอาต์ชีตเป็นจากขวาไปซ้าย โดยมีเซลล์ A1 อยู่ที่ มุมขวาบน หากเป็น false ระบบจะตั้งค่าเลย์เอาต์ชีตเป็นค่าเริ่มต้น จากซ้ายไปขวา โดยมีเซลล์ A1 อยู่ที่ด้านซ้ายบน

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

setRowGroupControlPosition(position)

ตั้งค่าตำแหน่งของปุ่มเปิด/ปิดการควบคุมกลุ่มแถวในชีต

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; sheet.setRowGroupControlPosition(     SpreadsheetApp.GroupControlTogglePosition.AFTER, );

พารามิเตอร์

ชื่อประเภทคำอธิบาย
positionGroupControlTogglePositionตำแหน่งของปุ่มเปิด/ปิดการควบคุมกลุ่มแถว

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

setRowHeight(rowPosition, height)

กำหนดความสูงของแถวที่ระบุเป็นพิกเซล โดยค่าเริ่มต้น แถวจะขยายให้พอดีกับเนื้อหาของเซลล์ หากต้องการบังคับให้แถวมีความสูงที่ระบุ ให้ใช้ setRowHeightsForced(startRow, numRows, height)

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

setRowHeights(startRow, numRows, height)

กำหนดความสูงของแถวที่ระบุเป็นพิกเซล โดยค่าเริ่มต้น แถวจะขยายให้พอดีกับเนื้อหาของเซลล์ หากต้องการบังคับให้แถวมีความสูงที่ระบุ ให้ใช้ setRowHeightsForced(startRow, numRows, height)

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // Sets the first three rows to a height of 20 pixels sheet.setRowHeights(1, 3, 20);

พารามิเตอร์

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

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

setRowHeightsForced(startRow, numRows, height)

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

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // Sets the first three rows to a height of 5 pixels. sheet.setRowHeightsForced(1, 3, 5);

พารามิเตอร์

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

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

setTabColor(color)

ตั้งค่าสีแท็บแผ่นงาน

// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.setTabColor('ff0000');  // Set the color to red. first.setTabColor(null);      // Unset the color.

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorStringรหัสสีในรูปแบบ CSS (เช่น '#ffffff' หรือ 'white') หรือ null เพื่อรีเซ็ตสีแท็บ

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

setTabColorObject(color)

ตั้งค่าสีแท็บแผ่นงาน

// This example assumes there is a sheet named "Sheet1" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('Sheet1'); const color = SpreadsheetApp.newColor()                   .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)                   .build(); first.setTabColorObject(color);  // Set the color to theme accent 1. first.setTabColorObject(null);   // Unset the color.

พารามิเตอร์

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

รีเทิร์น

Sheet — แผ่นงานนี้สำหรับการเชื่อมโยง

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

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

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

showColumns(columnIndex)

เลิกซ่อนคอลัมน์ที่ดัชนีที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Unhides the first column sheet.showColumns(1);

พารามิเตอร์

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

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

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

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

showColumns(columnIndex, numColumns)

เลิกซ่อนคอลัมน์ที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์โดยเริ่มจากดัชนีที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Unhides the first three columns sheet.showColumns(1, 3);

พารามิเตอร์

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

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

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

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

showRows(rowIndex)

เลิกซ่อนแถวที่ดัชนีที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Unhides the first row sheet.showRows(1);

พารามิเตอร์

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

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

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

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

showRows(rowIndex, numRows)

เลิกซ่อนแถวที่ต่อเนื่องกันอย่างน้อย 1 แถวโดยเริ่มจากดัชนีที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Unhides the first three rows sheet.showRows(1, 3);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowIndexIntegerดัชนีเริ่มต้นของแถวที่จะเลิกซ่อน
numRowsIntegerจำนวนแถวที่จะเลิกซ่อน

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

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

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

showSheet()

ทำให้ชีตปรากฏ ไม่มีผลหากชีตมองเห็นได้อยู่แล้ว

const sheet = SpreadsheetApp.getActiveSheet(); sheet.showSheet();

รีเทิร์น

Sheet — ชีตปัจจุบัน

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

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

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

sort(columnPosition)

จัดเรียงชีตตามคอลัมน์จากน้อยไปมาก

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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)

จัดเรียงชีตตามคอลัมน์ ใช้พารามิเตอร์เพื่อระบุการเรียงจากน้อยไปมากหรือมากไปน้อย

const ss = SpreadsheetApp.getActiveSpreadsheet(); const 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

unhideColumn(column)

เลิกซ่อนคอลัมน์ในช่วงที่กำหนด

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // This unhides the first column if it was previously hidden const range = sheet.getRange('A1'); sheet.unhideColumn(range);

พารามิเตอร์

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

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

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

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

unhideRow(row)

เลิกซ่อนแถวในช่วงที่กำหนด

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // This unhides the first row if it was previously hidden const range = sheet.getRange('A1'); sheet.unhideRow(range);

พารามิเตอร์

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

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

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

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

updateChart(chart)

อัปเดตแผนภูมิในชีตนี้

const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0];  // This code is going to loop through all the charts and change them to // column charts const charts = sheet.getCharts(); for (const i in charts) {   const chart = charts[i];   const newChart = chart.modify().setChartType(Charts.ChartType.COLUMN).build();   sheet.updateChart(newChart); }

พารามิเตอร์

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

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

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

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

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