Class Range

ช่วง

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

เมธอด

วิธีการประเภทการแสดงผลรายละเอียดแบบย่อ
activate()Rangeตั้งค่าช่วงที่ระบุเป็น active range โดยมีเซลล์ด้านบนซ้ายในช่วงเป็น current cell
activateAsCurrentCell()Rangeตั้งค่าเซลล์ที่ระบุเป็น current cell
addDeveloperMetadata(key)Rangeเพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ที่ระบุลงในช่วง
addDeveloperMetadata(key, visibility)Rangeเพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์และการเปิดเผยที่ระบุลงในช่วง
addDeveloperMetadata(key, value)Rangeเพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์และค่าที่ระบุลงในช่วง
addDeveloperMetadata(key, value, visibility)Rangeเพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ ค่า และระดับการเข้าถึงที่ระบุลงในช่วง
applyColumnBanding()Bandingใช้ธีมการแรเงาคอลัมน์เริ่มต้นกับช่วง
applyColumnBanding(bandingTheme)Bandingใช้ธีมการแรเงาคอลัมน์ที่ระบุกับช่วง
applyColumnBanding(bandingTheme, showHeader, showFooter)Bandingใช้ธีมการแบ่งแถวคอลัมน์ที่ระบุกับช่วงที่มีการตั้งค่าส่วนหัวและส่วนท้ายที่ระบุ
applyRowBanding()Bandingใช้ธีมการจัดแถวตามค่าเริ่มต้นกับช่วง
applyRowBanding(bandingTheme)Bandingใช้ธีมการแรเงาแถวที่ระบุกับช่วง
applyRowBanding(bandingTheme, showHeader, showFooter)Bandingใช้ธีมการจัดแถวที่ระบุกับช่วงที่มีการตั้งค่าส่วนหัวและส่วนท้ายที่ระบุ
autoFill(destination, series)voidกรอกข้อมูลใน destinationRange โดยอิงตามข้อมูลในช่วงนี้
autoFillToNeighbor(series)voidคำนวณช่วงที่จะกรอกข้อมูลใหม่โดยอิงตามเซลล์ที่อยู่ใกล้เคียง และกรอกช่วงนั้นโดยอัตโนมัติ ด้วยค่าใหม่โดยอิงตามข้อมูลที่มีอยู่ในช่วงนี้
breakApart()Rangeแยกเซลล์หลายคอลัมน์ในช่วงเป็นเซลล์เดี่ยวอีกครั้ง
canEdit()Booleanกำหนดว่าผู้ใช้มีสิทธิ์แก้ไขทุกเซลล์ในช่วงหรือไม่
check()Rangeเปลี่ยนสถานะของช่องทำเครื่องหมายในช่วงเป็น "เลือกแล้ว"
clear()Rangeล้างช่วงของเนื้อหาและรูปแบบ
clear(options)Rangeล้างช่วงของเนื้อหา รูปแบบ กฎการตรวจสอบข้อมูล และ/หรือความคิดเห็นตามที่ระบุด้วย ตัวเลือกขั้นสูงที่กำหนด
clearContent()Rangeล้างเนื้อหาของช่วงโดยคงการจัดรูปแบบไว้
clearDataValidations()Rangeล้างกฎการตรวจสอบข้อมูลสำหรับช่วง
clearFormat()Rangeล้างการจัดรูปแบบสำหรับช่วงนี้
clearNote()Rangeล้างหมายเหตุในเซลล์ที่ระบุ
collapseGroups()Rangeยุบกลุ่มทั้งหมดที่อยู่ในช่วงทั้งหมด
copyFormatToRange(gridId, column, columnEnd, row, rowEnd)voidคัดลอกการจัดรูปแบบของช่วงไปยังตำแหน่งที่ระบุ
copyFormatToRange(sheet, column, columnEnd, row, rowEnd)voidคัดลอกการจัดรูปแบบของช่วงไปยังตำแหน่งที่ระบุ
copyTo(destination)voidคัดลอกข้อมูลจากช่วงเซลล์ไปยังช่วงเซลล์อื่น
copyTo(destination, copyPasteType, transposed)voidคัดลอกข้อมูลจากช่วงเซลล์ไปยังช่วงเซลล์อื่น
copyTo(destination, options)voidคัดลอกข้อมูลจากช่วงเซลล์ไปยังช่วงเซลล์อื่น
copyValuesToRange(gridId, column, columnEnd, row, rowEnd)voidคัดลอกเนื้อหาของช่วงไปยังตำแหน่งที่ระบุ
copyValuesToRange(sheet, column, columnEnd, row, rowEnd)voidคัดลอกเนื้อหาของช่วงไปยังตำแหน่งที่ระบุ
createDataSourcePivotTable(dataSource)DataSourcePivotTableสร้างตาราง Pivot แหล่งข้อมูลที่ว่างเปล่าจากแหล่งข้อมูล โดยยึดเซลล์แรกใน ช่วงนี้
createDataSourceTable(dataSource)DataSourceTableสร้างตารางแหล่งข้อมูลว่างจากแหล่งข้อมูล โดยยึดเซลล์แรกใน ช่วงนี้เป็นหลัก
createDeveloperMetadataFinder()DeveloperMetadataFinderแสดงผล DeveloperMetadataFinderApi สำหรับค้นหาข้อมูลเมตาของนักพัฒนาแอปภายในขอบเขตของช่วงนี้
createFilter()Filterสร้างตัวกรองและนำไปใช้กับช่วงที่ระบุในชีต
createPivotTable(sourceData)PivotTableสร้างตาราง Pivot ว่างจาก sourceData ที่ระบุซึ่งยึดไว้ที่เซลล์แรก ในช่วงนี้
createTextFinder(findText)TextFinderสร้างเครื่องมือค้นหาข้อความสำหรับช่วง ซึ่งสามารถค้นหาและแทนที่ข้อความในช่วงนี้ได้
deleteCells(shiftDimension)voidลบช่วงของเซลล์นี้
expandGroups()Rangeขยายกลุ่มที่ยุบซึ่งช่วงหรือปุ่มเปิด/ปิดควบคุมตัดกับช่วงนี้
getA1Notation()Stringแสดงผลคำอธิบายสตริงของช่วงในรูปแบบ A1
getBackground()Stringแสดงสีพื้นหลังของเซลล์ซ้ายบนสุดในช่วง (เช่น '#ffffff')
getBackgroundObject()Colorแสดงผลสีพื้นหลังของเซลล์ด้านซ้ายบนในช่วง
getBackgroundObjects()Color[][]แสดงผลสีพื้นหลังของเซลล์ในช่วง
getBackgrounds()String[][]แสดงผลสีพื้นหลังของเซลล์ในช่วง (เช่น '#ffffff')
getBandings()Banding[]แสดงผลการแบนทั้งหมดที่ใช้กับเซลล์ใดๆ ในช่วงนี้
getCell(row, column)Rangeแสดงผลเซลล์ที่กำหนดภายในช่วง
getColumn()Integerแสดงตำแหน่งคอลัมน์เริ่มต้นของช่วงนี้
getDataRegion()Rangeแสดงผลสำเนาของช่วงที่ขยายในทิศทางหลักทั้ง 4 Direction เพื่อครอบคลุมเซลล์ที่อยู่ติดกันทั้งหมด ซึ่งมีข้อมูลอยู่
getDataRegion(dimension)Rangeแสดงผลสำเนาของช่วงที่ขยาย Direction.UP และ Direction.DOWN หากมิติข้อมูลที่ระบุคือ Dimension.ROWS หรือ Direction.NEXT และ Direction.PREVIOUS หากมิติข้อมูลคือ Dimension.COLUMNS
getDataSourceFormula()DataSourceFormulaแสดงผล DataSourceFormula สำหรับเซลล์แรกในช่วง หรือ null หาก เซลล์ไม่มีสูตรแหล่งข้อมูล
getDataSourceFormulas()DataSourceFormula[]แสดงผล DataSourceFormula สำหรับเซลล์ในช่วง
getDataSourcePivotTables()DataSourcePivotTable[]รับตาราง Pivot ของแหล่งข้อมูลทั้งหมดที่ตัดกับช่วง
getDataSourceTables()DataSourceTable[]รับตารางแหล่งข้อมูลทั้งหมดที่ตัดกับช่วง
getDataSourceUrl()Stringแสดง URL ของข้อมูลในช่วงนี้ ซึ่งใช้เพื่อสร้างแผนภูมิและการค้นหาได้
getDataTable()DataTableส่งคืนข้อมูลภายในออบเจ็กต์นี้เป็น DataTable
getDataTable(firstRowIsHeader)DataTableแสดงผลข้อมูลภายในช่วงนี้เป็น DataTable
getDataValidation()DataValidationแสดงผลกฎการตรวจสอบข้อมูลสำหรับเซลล์ด้านซ้ายบนในช่วง
getDataValidations()DataValidation[][]แสดงผลกฎการตรวจสอบข้อมูลสำหรับเซลล์ทั้งหมดในช่วง
getDeveloperMetadata()DeveloperMetadata[]รับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่เชื่อมโยงกับช่วงนี้
getDisplayValue()Stringแสดงผลค่าที่แสดงของเซลล์ซ้ายบนสุดในช่วง
getDisplayValues()String[][]แสดงผลตารางกริดสี่เหลี่ยมของค่าสำหรับช่วงนี้
getFilter()Filterแสดงตัวกรองในชีตที่ช่วงนี้เป็นของ หรือ null หากไม่มีตัวกรองในชีต
getFontColorObject()Colorแสดงผลสีแบบอักษรของเซลล์ที่มุมซ้ายบนของช่วง
getFontColorObjects()Color[][]แสดงผลสีแบบอักษรของเซลล์ในช่วง
getFontFamilies()String[][]แสดงผลชุดแบบอักษรของเซลล์ในช่วง
getFontFamily()Stringแสดงผลตระกูลแบบอักษรของเซลล์ที่มุมซ้ายบนของช่วง
getFontLine()Stringรับรูปแบบเส้นของเซลล์ที่มุมซ้ายบนของช่วง ('underline', 'line-through' หรือ 'none')
getFontLines()String[][]รับรูปแบบเส้นของเซลล์ในช่วง ('underline', 'line-through' หรือ 'none')
getFontSize()Integerแสดงผลขนาดแบบอักษรในหน่วยพอยต์ของเซลล์ที่มุมบนซ้ายของช่วง
getFontSizes()Integer[][]แสดงผลขนาดแบบอักษรของเซลล์ในช่วง
getFontStyle()Stringแสดงผลรูปแบบแบบอักษร ('italic' หรือ 'normal') ของเซลล์ที่มุมซ้ายบน ของช่วง
getFontStyles()String[][]แสดงรูปแบบแบบอักษรของเซลล์ในช่วง
getFontWeight()Stringแสดงผลความหนาของแบบอักษร (ปกติ/ตัวหนา) ของเซลล์ที่มุมซ้ายบนของช่วง
getFontWeights()String[][]แสดงผลความหนาของแบบอักษรของเซลล์ในช่วง
getFormula()Stringแสดงสูตร (รูปแบบ A1) สำหรับเซลล์บนซ้ายของช่วง หรือสตริงว่างหากเซลล์ว่างหรือไม่มีสูตร
getFormulaR1C1()Stringแสดงผลสูตร (สัญกรณ์ R1C1) สำหรับเซลล์ที่ระบุ หรือ null หากไม่มี
getFormulas()String[][]แสดงผลสูตร (รูปแบบ A1) สำหรับเซลล์ในช่วง
getFormulasR1C1()String[][]แสดงผลสูตร (สัญกรณ์ R1C1) สำหรับเซลล์ในช่วง
getGridId()Integerแสดงผลรหัสตารางกริดของชีตหลักของช่วง
getHeight()Integerแสดงผลความสูงของช่วง
getHorizontalAlignment()Stringแสดงการจัดแนวข้อความในแนวนอน (ซ้าย/กึ่งกลาง/ขวา) ของเซลล์ที่มุมซ้ายบน ของช่วง
getHorizontalAlignments()String[][]แสดงผลการจัดแนวแนวนอนของเซลล์ในช่วง
getLastColumn()Integerแสดงตำแหน่งคอลัมน์สิ้นสุด
getLastRow()Integerแสดงผลตำแหน่งแถวสิ้นสุด
getMergedRanges()Range[]แสดงผลอาร์เรย์ของออบเจ็กต์ Range ที่แสดงถึงเซลล์ที่ผสานซึ่งอยู่ภายในช่วงปัจจุบันทั้งหมด หรือมีเซลล์อย่างน้อย 1 เซลล์ในช่วงปัจจุบัน
getNextDataCell(direction)Rangeโดยเริ่มจากเซลล์ในคอลัมน์และแถวแรกของช่วง ฟังก์ชันจะแสดงผลเซลล์ถัดไปใน ทิศทางที่ระบุซึ่งเป็นขอบของช่วงเซลล์ที่ต่อเนื่องกันซึ่งมีข้อมูลอยู่ หรือเซลล์ ที่ขอบของสเปรดชีตในทิศทางนั้น
getNote()Stringแสดงหมายเหตุที่เชื่อมโยงกับช่วงที่ระบุ
getNotes()String[][]แสดงหมายเหตุที่เชื่อมโยงกับเซลล์ในช่วง
getNumColumns()Integerแสดงผลจำนวนคอลัมน์ในช่วงนี้
getNumRows()Integerแสดงผลจำนวนแถวในช่วงนี้
getNumberFormat()Stringรับการจัดรูปแบบตัวเลขหรือวันที่ของเซลล์ด้านซ้ายบนของช่วงที่ระบุ
getNumberFormats()String[][]แสดงผลรูปแบบตัวเลขหรือวันที่สำหรับเซลล์ในช่วง
getRichTextValue()RichTextValueแสดงผลค่าข้อความ Rich Text สำหรับเซลล์ซ้ายบนสุดของช่วง หรือ null หากค่าเซลล์ไม่ใช่ข้อความ
getRichTextValues()RichTextValue[][]แสดงผลค่าข้อความที่มีรูปแบบสำหรับเซลล์ในช่วง
getRow()Integerแสดงผลตำแหน่งแถวสำหรับช่วงนี้
getRowIndex()Integerแสดงผลตำแหน่งแถวสำหรับช่วงนี้
getSheet()Sheetแสดงผลชีตที่ช่วงนี้เป็นของ
getTextDirection()TextDirectionแสดงผลทิศทางข้อความสำหรับเซลล์ซ้ายบนสุดของช่วง
getTextDirections()TextDirection[][]แสดงผลทิศทางข้อความสำหรับเซลล์ในช่วง
getTextRotation()TextRotationแสดงการตั้งค่าการหมุนข้อความสำหรับเซลล์ด้านซ้ายบนของช่วง
getTextRotations()TextRotation[][]แสดงผลการตั้งค่าการหมุนข้อความสำหรับเซลล์ในช่วง
getTextStyle()TextStyleแสดงรูปแบบข้อความสำหรับเซลล์ซ้ายบนสุดของช่วง
getTextStyles()TextStyle[][]แสดงผลรูปแบบข้อความสำหรับเซลล์ในช่วง
getValue()Objectแสดงค่าของเซลล์ซ้ายบนสุดในช่วง
getValues()Object[][]แสดงผลตารางกริดสี่เหลี่ยมของค่าสำหรับช่วงนี้
getVerticalAlignment()Stringแสดงการจัดแนวตั้ง (บน/กลาง/ล่าง) ของเซลล์ที่มุมซ้ายบนของ ช่วง
getVerticalAlignments()String[][]แสดงผลการจัดแนวตั้งของเซลล์ในช่วง
getWidth()Integerแสดงผลความกว้างของช่วงในคอลัมน์
getWrap()Booleanแสดงว่าข้อความในเซลล์มีการตัดข้อความหรือไม่
getWrapStrategies()WrapStrategy[][]แสดงผลกลยุทธ์การตัดข้อความสำหรับเซลล์ในช่วง
getWrapStrategy()WrapStrategyแสดงผลกลยุทธ์การตัดข้อความสำหรับเซลล์ซ้ายบนสุดของช่วง
getWraps()Boolean[][]แสดงว่าข้อความในเซลล์มีการตัดข้อความหรือไม่
insertCells(shiftDimension)Rangeแทรกเซลล์ว่างลงในช่วงนี้
insertCheckboxes()Rangeแทรกช่องทำเครื่องหมายในแต่ละเซลล์ในช่วงที่กำหนดค่าด้วย true สำหรับช่องที่เลือกและ false สำหรับช่องที่ไม่ได้เลือก
insertCheckboxes(checkedValue)Rangeแทรกช่องทําเครื่องหมายลงในแต่ละเซลล์ในช่วง โดยกําหนดค่าที่กําหนดเองสําหรับช่องที่เลือกและ สตริงว่างสําหรับช่องที่ไม่ได้เลือก
insertCheckboxes(checkedValue, uncheckedValue)Rangeแทรกช่องทําเครื่องหมายลงในแต่ละเซลล์ในช่วงที่กําหนดค่าด้วยค่าที่กําหนดเองสําหรับสถานะที่เลือกและไม่ได้เลือก
isBlank()Booleanแสดงผล true หากช่วงว่างเปล่าทั้งหมด
isChecked()Booleanแสดงผลว่าเซลล์ทั้งหมดในช่วงมีสถานะช่องทำเครื่องหมายเป็น "เลือก" หรือไม่
isEndColumnBounded()Booleanกำหนดว่าจุดสิ้นสุดของช่วงจะผูกกับคอลัมน์ใดคอลัมน์หนึ่งหรือไม่
isEndRowBounded()Booleanกำหนดว่าจุดสิ้นสุดของช่วงจะเชื่อมโยงกับแถวใดแถวหนึ่งหรือไม่
isPartOfMerge()Booleanแสดงผล true หากเซลล์ในช่วงปัจจุบันทับซ้อนกับเซลล์ที่ผสาน
isStartColumnBounded()Booleanกำหนดว่าจุดเริ่มต้นของช่วงจะเชื่อมโยงกับคอลัมน์ใดคอลัมน์หนึ่งหรือไม่
isStartRowBounded()Booleanกำหนดว่าจุดเริ่มต้นของช่วงจะเชื่อมโยงกับแถวใดแถวหนึ่งหรือไม่
merge()Rangeผสานเซลล์ในช่วงเข้าด้วยกันเป็นบล็อกเดียว
mergeAcross()Rangeผสานเซลล์ในช่วงในคอลัมน์ของช่วง
mergeVertically()Rangeผสานเซลล์ในช่วงเข้าด้วยกัน
moveTo(target)voidตัดและวาง (ทั้งรูปแบบและค่า) จากช่วงนี้ไปยังช่วงเป้าหมาย
offset(rowOffset, columnOffset)Rangeแสดงผลช่วงใหม่ที่ออฟเซ็ตจากช่วงนี้ตามจำนวนแถวและคอลัมน์ที่ระบุ (ซึ่งอาจเป็นค่าลบ)
offset(rowOffset, columnOffset, numRows)Rangeแสดงผลช่วงใหม่ที่สัมพันธ์กับช่วงปัจจุบัน โดยมีจุดบนซ้ายที่ออฟเซ็ต จากช่วงปัจจุบันตามแถวและคอลัมน์ที่ระบุ และมีความสูงในเซลล์ตามที่ระบุ
offset(rowOffset, columnOffset, numRows, numColumns)Rangeแสดงผลช่วงใหม่ที่สัมพันธ์กับช่วงปัจจุบัน โดยมีจุดบนซ้ายซึ่งออฟเซ็ต จากช่วงปัจจุบันตามแถวและคอลัมน์ที่ระบุ และมีความสูงและความกว้างที่ระบุใน เซลล์
protect()Protectionสร้างออบเจ็กต์ที่ป้องกันไม่ให้แก้ไขช่วงได้ ยกเว้นผู้ใช้ที่มี สิทธิ์
randomize()Rangeสุ่มลำดับของแถวในช่วงที่ระบุ
removeCheckboxes()Rangeนำช่องทำเครื่องหมายทั้งหมดออกจากช่วง
removeDuplicates()Rangeนำแถวภายในช่วงนี้ที่มีค่าที่ซ้ำกับค่าในแถวก่อนหน้าออก
removeDuplicates(columnsToCompare)Rangeนำแถวภายในช่วงนี้ซึ่งมีค่าในคอลัมน์ที่ระบุซึ่งซ้ำกับค่าในแถวก่อนหน้าออก
setBackground(color)Rangeตั้งค่าสีพื้นหลังของเซลล์ทั้งหมดในช่วงในรูปแบบ CSS (เช่น '#ffffff' หรือ 'white')
setBackgroundObject(color)Rangeตั้งค่าสีพื้นหลังของเซลล์ทั้งหมดในช่วง
setBackgroundObjects(color)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของสีพื้นหลัง (ต้องตรงกับมิติข้อมูลของช่วงนี้)
setBackgroundRGB(red, green, blue)Rangeตั้งค่าพื้นหลังเป็นสีที่ระบุโดยใช้ค่า RGB (จำนวนเต็มระหว่าง 0 ถึง 255 รวม)
setBackgrounds(color)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของสีพื้นหลัง (ต้องตรงกับมิติข้อมูลของช่วงนี้)
setBorder(top, left, bottom, right, vertical, horizontal)Rangeตั้งค่าพร็อพเพอร์ตี้เส้นขอบ
setBorder(top, left, bottom, right, vertical, horizontal, color, style)Rangeตั้งค่าพร็อพเพอร์ตี้เส้นขอบด้วยสีและ/หรือรูปแบบ
setDataValidation(rule)Rangeตั้งกฎการตรวจสอบข้อมูล 1 กฎสำหรับเซลล์ทั้งหมดในช่วง
setDataValidations(rules)Rangeตั้งค่ากฎการตรวจสอบข้อมูลสำหรับเซลล์ทั้งหมดในช่วง
setFontColor(color)Rangeตั้งค่าสีแบบอักษรในรูปแบบ CSS (เช่น '#ffffff' หรือ 'white')
setFontColorObject(color)Rangeตั้งค่าสีแบบอักษรของช่วงที่ระบุ
setFontColorObjects(colors)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของสีแบบอักษร (ต้องตรงกับขนาดของช่วงนี้)
setFontColors(colors)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของสีแบบอักษร (ต้องตรงกับขนาดของช่วงนี้)
setFontFamilies(fontFamilies)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของชุดแบบอักษร (ต้องตรงกับขนาดของช่วงนี้)
setFontFamily(fontFamily)Rangeตั้งค่าชุดแบบอักษร เช่น "Arial" หรือ "Helvetica"
setFontLine(fontLine)Rangeตั้งค่ารูปแบบเส้นของแบบอักษรในช่วงที่ระบุ ('underline', 'line-through' หรือ 'none')
setFontLines(fontLines)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของรูปแบบเส้น (ต้องตรงกับขนาดของช่วงนี้)
setFontSize(size)Rangeกำหนดขนาดแบบอักษร โดยขนาดคือขนาดจุดที่จะใช้
setFontSizes(sizes)Rangeกำหนดตารางกริดสี่เหลี่ยมของขนาดแบบอักษร (ต้องตรงกับมิติข้อมูลของช่วงนี้)
setFontStyle(fontStyle)Rangeกำหนดรูปแบบแบบอักษรสำหรับช่วงที่ระบุ ('italic' หรือ 'normal')
setFontStyles(fontStyles)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของรูปแบบแบบอักษร (ต้องตรงกับขนาดของช่วงนี้)
setFontWeight(fontWeight)Rangeกำหนดความหนาของแบบอักษรสำหรับช่วงที่ระบุ (ปกติ/หนา)
setFontWeights(fontWeights)Rangeกำหนดตารางกริดสี่เหลี่ยมของความหนาแบบอักษร (ต้องตรงกับมิติข้อมูลของช่วงนี้)
setFormula(formula)Rangeอัปเดตสูตรสำหรับช่วงนี้
setFormulaR1C1(formula)Rangeอัปเดตสูตรสำหรับช่วงนี้
setFormulas(formulas)Rangeตั้งค่าตารางสูตรสี่เหลี่ยมผืนผ้า (ต้องตรงกับมิติข้อมูลของช่วงนี้)
setFormulasR1C1(formulas)Rangeตั้งค่าตารางสูตรสี่เหลี่ยมผืนผ้า (ต้องตรงกับมิติข้อมูลของช่วงนี้)
setHorizontalAlignment(alignment)Rangeตั้งค่าการจัดแนวแนวนอน (จากซ้ายไปขวา) สำหรับช่วงที่ระบุ (ซ้าย/กึ่งกลาง/ขวา)
setHorizontalAlignments(alignments)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของการจัดแนวนอน
setNote(note)Rangeตั้งค่าโน้ตเป็นค่าที่ระบุ
setNotes(notes)Rangeตั้งค่าตารางโน้ตสี่เหลี่ยมผืนผ้า (ต้องตรงกับขนาดของช่วงนี้)
setNumberFormat(numberFormat)Rangeตั้งค่ารูปแบบตัวเลขหรือวันที่เป็นสตริงการจัดรูปแบบที่ระบุ
setNumberFormats(numberFormats)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของรูปแบบตัวเลขหรือวันที่ (ต้องตรงกับมิติข้อมูลของช่วงนี้)
setRichTextValue(value)Rangeกำหนดค่าข้อความที่มีรูปแบบสำหรับเซลล์ในช่วง
setRichTextValues(values)Rangeตั้งค่าตารางสี่เหลี่ยมของค่าข้อความที่มีรูปแบบ
setShowHyperlink(showHyperlink)Rangeตั้งค่าว่าจะให้ช่วงแสดงไฮเปอร์ลิงก์หรือไม่
setTextDirection(direction)Rangeตั้งค่าทิศทางข้อความสำหรับเซลล์ในช่วง
setTextDirections(directions)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของทิศทางข้อความ
setTextRotation(degrees)Rangeตั้งค่าการหมุนข้อความสำหรับเซลล์ในช่วง
setTextRotation(rotation)Rangeตั้งค่าการหมุนข้อความสำหรับเซลล์ในช่วง
setTextRotations(rotations)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของการหมุนข้อความ
setTextStyle(style)Rangeตั้งค่ารูปแบบข้อความสำหรับเซลล์ในช่วง
setTextStyles(styles)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของรูปแบบข้อความ
setValue(value)Rangeกำหนดค่าของช่วง
setValues(values)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของค่า (ต้องตรงกับมิติข้อมูลของช่วงนี้)
setVerticalAlignment(alignment)Rangeตั้งค่าการจัดแนวในแนวตั้ง (จากบนลงล่าง) สำหรับช่วงที่ระบุ (บน/กลาง/ล่าง)
setVerticalAlignments(alignments)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของการจัดแนวตั้ง (ต้องตรงกับขนาดของช่วงนี้)
setVerticalText(isVertical)Rangeกำหนดว่าจะซ้อนข้อความสำหรับเซลล์ในช่วงหรือไม่
setWrap(isWrapEnabled)Rangeตั้งค่าการตัดข้อความในเซลล์ของช่วงที่ระบุ
setWrapStrategies(strategies)Rangeตั้งค่าตารางสี่เหลี่ยมผืนผ้าของกลยุทธ์การตัดคำ
setWrapStrategy(strategy)Rangeตั้งค่ากลยุทธ์การตัดข้อความสำหรับเซลล์ในช่วง
setWraps(isWrapEnabled)Rangeกำหนดตารางสี่เหลี่ยมผืนผ้าของนโยบายการตัดคำ (ต้องตรงกับขนาดของช่วงนี้)
shiftColumnGroupDepth(delta)Rangeเปลี่ยนความลึกของการจัดกลุ่มคอลัมน์ของช่วงตามจำนวนที่ระบุ
shiftRowGroupDepth(delta)Rangeเปลี่ยนความลึกของการจัดกลุ่มแถวของช่วงตามจำนวนที่ระบุ
sort(sortSpecObj)Rangeจัดเรียงเซลล์ในช่วงที่กำหนดตามคอลัมน์และลำดับที่ระบุ
splitTextToColumns()voidแยกคอลัมน์ข้อความออกเป็นหลายคอลัมน์ตามตัวคั่นที่ระบบตรวจหาโดยอัตโนมัติ
splitTextToColumns(delimiter)voidแบ่งคอลัมน์ข้อความออกเป็นหลายคอลัมน์โดยใช้สตริงที่ระบุเป็นตัวคั่นที่กำหนดเอง
splitTextToColumns(delimiter)voidแยกคอลัมน์ข้อความออกเป็นหลายคอลัมน์ตามตัวคั่นที่ระบุ
trimWhitespace()Rangeตัดช่องว่าง (เช่น ช่องว่าง แท็บ หรือบรรทัดใหม่) ในทุกเซลล์ในช่วงนี้
uncheck()Rangeเปลี่ยนสถานะของช่องทำเครื่องหมายในช่วงเป็น "ไม่ได้เลือก"

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

activate()

ตั้งค่าช่วงที่ระบุเป็น active range โดยมีเซลล์ด้านบนซ้ายในช่วงเป็น current cell

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getRange('A1:D10');
range.activate();

const selection = sheet.getSelection();
// Current cell: A1
const currentCell = selection.getCurrentCell();
// Active Range: A1:D10
const activeRange = selection.getActiveRange();

รีเทิร์น

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


activateAsCurrentCell()

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

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

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

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

// Gets the first sheet of the spreadsheet.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];

// Gets the cell B5 and sets it as the active cell.
const range = sheet.getRange('B5');
const currentCell = range.activateAsCurrentCell();

// Logs the activated cell.
console.log(currentCell.getA1Notation());

รีเทิร์น

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

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

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

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

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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets row 2 on the sheet.
const range = sheet.getRange('2:2');

// Adds the key 'NAME' to the developer metadata for row 2.
range.addDeveloperMetadata('NAME');

// Gets the metadata and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());

พารามิเตอร์

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

รีเทิร์น

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

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets row 2 on Sheet1.
const range = sheet.getRange('2:2');

// Adds the key 'NAME' and sets the developer metadata visibility to 'DOCUMENT'
// for row 2 on Sheet1.
range.addDeveloperMetadata(
    'NAME',
    SpreadsheetApp.DeveloperMetadataVisibility.DOCUMENT,
);

// Gets the updated metadata info and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getVisibility().toString());

พารามิเตอร์

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

รีเทิร์น

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

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets row 2 of Sheet1.
const range = sheet.getRange('2:2');

// Adds the key 'NAME' and sets the value to 'GOOGLE' for the metadata of row 2.
range.addDeveloperMetadata('NAME', 'GOOGLE');

// Gets the metadata and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getValue());

พารามิเตอร์

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

รีเทิร์น

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

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets row 2 on the sheet.
const range = sheet.getRange('2:2');

// Adds the key 'NAME', sets the value to 'GOOGLE', and sets the visibility
// to PROJECT for row 2 on the sheet.
range.addDeveloperMetadata(
    'NAME',
    'GOOGLE',
    SpreadsheetApp.DeveloperMetadataVisibility.PROJECT,
);

// Gets the updated metadata info and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getValue());
console.log(developerMetaData.getVisibility().toString());

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

applyColumnBanding()

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

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets row 2 on the sheet.
const range = sheet.getRange('2:2');

// Applies column banding to row 2.
const colBanding = range.applyColumnBanding();

// Gets the first banding on the sheet and logs the color of the header column.
console.log(
    sheet.getBandings()[0]
        .getHeaderColumnColorObject()
        .asRgbColor()
        .asHexString(),
);

// Gets the first banding on the sheet and logs the color of the second column.
console.log(
    sheet.getBandings()[0]
        .getSecondColumnColorObject()
        .asRgbColor()
        .asHexString(),
);

รีเทิร์น

Banding — การแบ่งประเภทใหม่

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

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

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

applyColumnBanding(bandingTheme)

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

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets row 2 on the sheet.
const range = sheet.getRange('2:2');

// Applies the INDIGO color banding theme to the columns in row 2.
const colBanding = range.applyColumnBanding(SpreadsheetApp.BandingTheme.INDIGO);

// Gets the first banding on the sheet and logs the color of the second column.
console.log(
    sheet.getBandings()[0]
        .getSecondColumnColorObject()
        .asRgbColor()
        .asHexString(),
);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
bandingThemeBandingThemeธีมสีที่จะใช้กับคอลัมน์ในช่วง

รีเทิร์น

Banding — การแบ่งประเภทใหม่

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

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

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

applyColumnBanding(bandingTheme, showHeader, showFooter)

ใช้ธีมการแบ่งแถวคอลัมน์ที่ระบุกับช่วงที่มีการตั้งค่าส่วนหัวและส่วนท้ายที่ระบุ

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets rows 12-22 on the sheet.
const range = sheet.getRange('12:22');

// Applies the BLUE color banding theme to rows 12-22.
// Sets the header visibility to false and the footer visibility to true.
const colBanding = range.applyColumnBanding(
    SpreadsheetApp.BandingTheme.BLUE,
    false,
    true,
);

// Gets the banding color and logs it to the console.
console.log(
    sheet.getBandings()[0]
        .getSecondColumnColorObject()
        .asRgbColor()
        .asHexString(),
);

// Gets the header color object and logs it to the console. Returns null because
// the header visibility is set to false.
console.log(sheet.getBandings()[0].getHeaderColumnColorObject());

// Gets the footer color and logs it to the console.
console.log(
    sheet.getBandings()[0]
        .getFooterColumnColorObject()
        .asRgbColor()
        .asHexString(),
);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
bandingThemeBandingThemeธีมสีที่จะใช้กับคอลัมน์ในช่วง
showHeaderBooleanหาก true ระบบจะใช้สีส่วนหัวของธีมการแบนด์กับคอลัมน์แรก
showFooterBooleanหาก true จะมีการใช้สีส่วนท้ายของธีมการแบนด์กับคอลัมน์สุดท้าย

รีเทิร์น

Banding — การแบ่งประเภทใหม่

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

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

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

applyRowBanding()

ใช้ธีมการจัดแถวตามค่าเริ่มต้นกับช่วง โดยค่าเริ่มต้น การแบนด์จะมีส่วนหัวและไม่มีสีส่วนท้าย

// Opens the spreadsheet 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 rows 1-30 on Sheet1.
const range = sheet.getRange('1:30');

// Applies row banding to rows 1-30.
range.applyRowBanding();

// Gets the hex color of the second banded row.
const secondRowColor =
    range.getBandings()[0].getSecondRowColorObject().asRgbColor().asHexString();

// Logs the hex color to console.
console.log(secondRowColor);

รีเทิร์น

Banding - แถบสี

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

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

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

applyRowBanding(bandingTheme)

ใช้ธีมการแรเงาแถวที่ระบุกับช่วง โดยค่าเริ่มต้น การแบนด์จะมีส่วนหัวและไม่มีสีส่วนท้าย

// Opens the spreadsheet 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 rows 1-30 on Sheet1.
const range = sheet.getRange('1:30');

// Applies the INDIGO row banding theme to rows 1-30.
range.applyRowBanding(SpreadsheetApp.BandingTheme.INDIGO);

// Gets the hex color of the second banded row.
const secondRowColor =
    range.getBandings()[0].getSecondRowColorObject().asRgbColor().asHexString();

// Logs the hex color to console.
console.log(secondRowColor);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
bandingThemeBandingThemeธีมสีที่จะใช้กับแถวในช่วง

รีเทิร์น

Banding — การแบ่งประเภทใหม่

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

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

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

applyRowBanding(bandingTheme, showHeader, showFooter)

ใช้ธีมการจัดแถวที่ระบุกับช่วงที่มีการตั้งค่าส่วนหัวและส่วนท้ายที่ระบุ

// Opens the spreadsheet 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 rows 1-30 on Sheet1.
const range = sheet.getRange('1:30');

// Applies the INDIGO row banding to rows 1-30 and
// specifies to hide the header and show the footer.
range.applyRowBanding(SpreadsheetApp.BandingTheme.INDIGO, false, true);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
bandingThemeBandingThemeธีมสีที่จะใช้กับแถวในช่วง
showHeaderBooleanหาก true ระบบจะใช้สีส่วนหัวของธีมแถบสีกับแถวแรก
showFooterBooleanหากเป็น true ระบบจะใช้สีส่วนท้ายของธีมแถบสีกับแถวสุดท้าย

รีเทิร์น

Banding — การแบ่งประเภทใหม่

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

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

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

autoFill(destination, series)

กรอกข้อมูลใน destinationRange โดยอิงตามข้อมูลในช่วงนี้ ค่าใหม่ จะกำหนดโดยseriesประเภทที่ระบุด้วย ช่วงปลายทางต้องมีช่วงนี้และขยายช่วงนี้ในทิศทางเดียวเท่านั้น เช่น การดำเนินการต่อไปนี้จะเติม A1:A20 ด้วยชุดตัวเลขที่เพิ่มขึ้นตามค่าปัจจุบันใน A1:A4

const sheet = SpreadsheetApp.getActiveSheet();

// Has values [1, 2, 3, 4].
const sourceRange = sheet.getRange('A1:A4');
// The range to fill with values.
const destination = sheet.getRange('A1:A20');

// Inserts new values in A5:A20, continuing the pattern expressed in A1:A4
sourceRange.autoFill(destination, SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
destinationRangeช่วงที่จะป้อนค่าโดยอัตโนมัติ ช่วงปลายทางควร มีช่วงนี้และขยายในทิศทางเดียวเท่านั้น (ขึ้น ลง ซ้าย หรือ ขวา)
seriesAutoFillSeriesประเภทของชุดการเติมข้อความอัตโนมัติที่ควรใช้ในการคำนวณค่าใหม่ ผลลัพธ์ของอนุกรมนี้จะแตกต่างกันไปตามประเภทและปริมาณของข้อมูลต้นฉบับ

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

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

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

autoFillToNeighbor(series)

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

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

เช่น หาก A1:A20 มีชุดตัวเลขที่เพิ่มขึ้นและมีการเรียกใช้เมธอดนี้ ในช่วง B1:B4 ซึ่งมีชุดวันที่ ระบบจะแทรกค่าใหม่ลงใน B5:B20 เท่านั้น ด้วยวิธีนี้ ค่าใหม่เหล่านี้จะ "ติด" อยู่กับเซลล์ที่มีค่าในคอลัมน์ A

const sheet = SpreadsheetApp.getActiveSheet();

// A1:A20 has values [1, 2, 3, ... 20].
// B1:B4 has values [1/1/2017, 1/2/2017, ...]
const sourceRange = sheet.getRange('B1:B4');

// Results in B5:B20 having values [1/5/2017, ... 1/20/2017]
sourceRange.autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);

พารามิเตอร์

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

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

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

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

breakApart()

แยกเซลล์หลายคอลัมน์ในช่วงเป็นเซลล์เดี่ยวอีกครั้ง

การเรียกใช้ฟังก์ชันนี้ในช่วงจะเทียบเท่ากับการเลือกช่วงแล้วคลิกรูปแบบ > ผสานเซลล์ > เลิกผสาน

// Opens the spreadsheet 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 range A1:C6 on Sheet1.
const range = sheet.getRange('A1:C6');

// Unmerges the range A1:C6 into individual cells.
range.breakApart();

รีเทิร์น

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

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

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

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

canEdit()

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

// Opens the spreadsheet 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 range A1:C6 on Sheet1.
const range = sheet.getRange('A1:C6');

// Logs whether the user has permission to edit every cell in the range.
console.log(range.canEdit());

รีเทิร์น

Booleantrue หากผู้ใช้มีสิทธิ์แก้ไขทุกเซลล์ในช่วง false มิเช่นนั้น

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

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

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

check()

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

// Changes the state of cells which currently contain either the checked or
// unchecked value configured in the range A1:B10 to 'checked'.
const range = SpreadsheetApp.getActive().getRange('A1:B10');
range.check();

รีเทิร์น

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

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

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

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

clear()

ล้างช่วงของเนื้อหาและรูปแบบ

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

const range = sheet.getRange('A1:D10');
range.clear();

รีเทิร์น

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

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

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

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

clear(options)

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

// The code below clears range C2:G7 in the active sheet, but preserves the
// format, data validation rules, and comments.
SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 5).clear({
  contentsOnly: true
});

พารามิเตอร์

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

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

ชื่อประเภทคำอธิบาย
commentsOnlyBooleanจะล้างเฉพาะความคิดเห็นไหม
contentsOnlyBooleanจะล้างเฉพาะเนื้อหาหรือไม่
formatOnlyBooleanจะล้างเฉพาะรูปแบบหรือไม่ โปรดทราบว่าการล้าง รูปแบบจะล้างกฎการตรวจสอบข้อมูลด้วย
validationsOnlyBooleanเลือกว่าจะล้างเฉพาะกฎการตรวจสอบข้อมูลหรือไม่
skipFilteredRowsBooleanกำหนดว่าจะไม่ล้างแถวที่กรองหรือไม่

รีเทิร์น

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

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

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

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

clearContent()

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

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

const range = sheet.getRange('A1:D10');
range.clearContent();

รีเทิร์น

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

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

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

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

clearDataValidations()

ล้างกฎการตรวจสอบข้อมูลสำหรับช่วง

// Clear the data validation rules for cells A1:B5.
const range = SpreadsheetApp.getActive().getRange('A1:B5');
range.clearDataValidations();

รีเทิร์น

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

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

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

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

clearFormat()

ล้างการจัดรูปแบบสำหรับช่วงนี้

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

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

const range = sheet.getRange('A1:D10');
range.clearFormat();

รีเทิร์น

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

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

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

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

clearNote()

ล้างหมายเหตุในเซลล์ที่ระบุ

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

const range = sheet.getRange('A1:D10');
range.clearNote();

รีเทิร์น

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

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

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

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

collapseGroups()

ยุบกลุ่มทั้งหมดที่อยู่ในช่วงทั้งหมด หากไม่มีกลุ่มใดอยู่ภายในช่วงทั้งหมด ระบบจะยุบกลุ่มที่ขยายลึกที่สุดซึ่งอยู่ภายในช่วงบางส่วน

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();

// All row and column groups within the range are collapsed.
range.collapseGroups();

รีเทิร์น

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

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

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

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

copyFormatToRange(gridId, column, columnEnd, row, rowEnd)

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

ดูคำอธิบายโดยละเอียดเกี่ยวกับพารามิเตอร์ gridId ได้ที่ getGridId()

const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];

const range = source.getRange('B2:D4');

// This copies the formatting in B2:D4 in the source sheet to
// D4:F6 in the sheet with gridId 1555299895. Note that you can get the gridId
// of a sheet by calling sheet.getSheetId() or range.getGridId().
range.copyFormatToRange(1555299895, 4, 6, 4, 6);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
gridIdIntegerรหัสที่ไม่ซ้ำกันของชีตภายในสเปรดชีต โดยไม่คำนึงถึงตำแหน่ง
columnIntegerคอลัมน์แรกของช่วงเป้าหมาย
columnEndIntegerคอลัมน์สุดท้ายของช่วงเป้าหมาย
rowIntegerแถวเริ่มต้นของช่วงเป้าหมาย
rowEndIntegerแถวสุดท้ายของช่วงเป้าหมาย

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

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

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

ดูเพิ่มเติม


copyFormatToRange(sheet, column, columnEnd, row, rowEnd)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];
const destination = ss.getSheets()[1];

const range = source.getRange('B2:D4');

// This copies the formatting in B2:D4 in the source sheet to
// D4:F6 in the second sheet
range.copyFormatToRange(destination, 4, 6, 4, 6);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sheetSheetชีตเป้าหมาย
columnIntegerคอลัมน์แรกของช่วงเป้าหมาย
columnEndIntegerคอลัมน์สุดท้ายของช่วงเป้าหมาย
rowIntegerแถวเริ่มต้นของช่วงเป้าหมาย
rowEndIntegerแถวสุดท้ายของช่วงเป้าหมาย

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

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

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

copyTo(destination)

คัดลอกข้อมูลจากช่วงเซลล์ไปยังช่วงเซลล์อื่น ระบบจะคัดลอกทั้งค่าและการจัดรูปแบบ

// The code below copies the first 5 columns over to the 6th column.
const sheet = SpreadsheetApp.getActiveSheet();
const rangeToCopy = sheet.getRange(1, 1, sheet.getMaxRows(), 5);
rangeToCopy.copyTo(sheet.getRange(1, 6));

พารามิเตอร์

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

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

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

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

copyTo(destination, copyPasteType, transposed)

คัดลอกข้อมูลจากช่วงเซลล์ไปยังช่วงเซลล์อื่น

// The code below copies only the values of the first 5 columns over to the 6th
// column.
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange('A:E').copyTo(
    sheet.getRange('F1'),
    SpreadsheetApp.CopyPasteType.PASTE_VALUES,
    false,
);

พารามิเตอร์

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

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

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

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

copyTo(destination, options)

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

// The code below copies only the values of the first 5 columns over to the 6th
// column.
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange('A:E').copyTo(sheet.getRange('F1'), {contentsOnly: true});

พารามิเตอร์

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

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

ชื่อประเภทคำอธิบาย
formatOnlyBooleanระบุว่าควรคัดลอกเฉพาะรูปแบบ
contentsOnlyBooleanระบุว่าควรคัดลอกเฉพาะเนื้อหา

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

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

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

copyValuesToRange(gridId, column, columnEnd, row, rowEnd)

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

ดูคำอธิบายโดยละเอียดเกี่ยวกับพารามิเตอร์ gridId ได้ที่ getGridId()

const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];

const range = source.getRange('B2:D4');

// This copies the data in B2:D4 in the source sheet to
// D4:F6 in the sheet with gridId 0
range.copyValuesToRange(0, 4, 6, 4, 6);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
gridIdIntegerรหัสที่ไม่ซ้ำกันของชีตภายในสเปรดชีต โดยไม่คำนึงถึงตำแหน่ง
columnIntegerคอลัมน์แรกของช่วงเป้าหมาย
columnEndIntegerคอลัมน์สุดท้ายของช่วงเป้าหมาย
rowIntegerแถวเริ่มต้นของช่วงเป้าหมาย
rowEndIntegerแถวสุดท้ายของช่วงเป้าหมาย

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

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

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

ดูเพิ่มเติม


copyValuesToRange(sheet, column, columnEnd, row, rowEnd)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];
const destination = ss.getSheets()[1];

const range = source.getRange('B2:D4');

// This copies the data in B2:D4 in the source sheet to
// D4:F6 in the second sheet
range.copyValuesToRange(destination, 4, 6, 4, 6);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sheetSheetชีตเป้าหมาย
columnIntegerคอลัมน์แรกของช่วงเป้าหมาย
columnEndIntegerคอลัมน์สุดท้ายของช่วงเป้าหมาย
rowIntegerแถวเริ่มต้นของช่วงเป้าหมาย
rowEndIntegerแถวสุดท้ายของช่วงเป้าหมาย

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

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

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

createDataSourcePivotTable(dataSource)

สร้างตาราง Pivot แหล่งข้อมูลที่ว่างเปล่าจากแหล่งข้อมูล โดยยึดเซลล์แรกใน ช่วงนี้

ตัวอย่างนี้แสดงวิธีสร้างและกำหนดค่าตาราง Pivot แหล่งข้อมูลใหม่

const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const anchorCell = spreadsheet.getSheets()[0].getRange('A1');
const dataSource = spreadsheet.getDataSources()[0];

const pivotTable = anchorCell.createDataSourcePivotTable(dataSource);
pivotTable.addRowGroup('dataColumnA');
pivotTable.addColumnGroup('dataColumnB');
pivotTable.addPivotValue(
    'dataColumnC',
    SpreadsheetApp.PivotTableSummarizeFunction.SUM,
);
pivotTable.addFilter(
    'dataColumnA',
    SpreadsheetApp.newFilterCriteria().whenTextStartsWith('A').build(),
);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dataSourceDataSourceแหล่งข้อมูลที่จะสร้างตาราง Pivot

รีเทิร์น

DataSourcePivotTable — ตาราง Pivot ของแหล่งข้อมูลที่สร้างขึ้นใหม่

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

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

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

createDataSourceTable(dataSource)

สร้างตารางแหล่งข้อมูลว่างจากแหล่งข้อมูล โดยยึดเซลล์แรกใน ช่วงนี้เป็นหลัก

ตัวอย่างนี้แสดงวิธีสร้างและกำหนดค่าตารางแหล่งข้อมูลใหม่

const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const anchorCell = spreadsheet.getSheets()[0].getRange('A1');
const dataSource = spreadsheet.getDataSources()[0];

const dataSourceTable =
    anchorCell.createDataSourceTable(dataSource)
        .addColumns('dataColumnA', 'dataColumnB', 'dataColumnC')
        .addSortSpec('dataColumnA', true)    // ascending=true
        .addSortSpec('dataColumnB', false);  // ascending=false

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dataSourceDataSourceแหล่งข้อมูลที่จะสร้างตาราง Pivot

รีเทิร์น

DataSourceTable — ตารางแหล่งข้อมูลที่สร้างขึ้นใหม่

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

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

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

createDeveloperMetadataFinder()

แสดงผล DeveloperMetadataFinderApi สำหรับค้นหาข้อมูลเมตาของนักพัฒนาแอปภายในขอบเขตของช่วงนี้ ข้อมูลเมตาจะอยู่ในขอบเขตของช่วงก็ต่อเมื่อข้อมูลเมตาทั้งหมดอยู่ในช่วงนั้น เช่น ข้อมูลเมตาที่เชื่อมโยงกับแถว "3:3" จะไม่อยู่ในขอบเขตของช่วง "A1:D5" แต่อยู่ในขอบเขตของช่วง "1:5"

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:C6.
const range = sheet.getRange('A1:C6');

// Creates a developer metadata finder to search for metadata in the scope of
// this range.
const developerMetaDataFinder = range.createDeveloperMetadataFinder();

// Logs information about the developer metadata finder to the console.
const developerMetaData = developerMetaDataFinder.find()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getValue());
console.log(developerMetaData.getVisibility().toString());

รีเทิร์น

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


createFilter()

สร้างตัวกรองและนำไปใช้กับช่วงที่ระบุในชีต คุณสร้างตัวกรองในชีตได้ไม่เกิน 1 รายการ หากต้องการเข้าถึงและแก้ไขตัวกรองหลังจากสร้างแล้ว ให้ใช้ getFilter() หรือ Sheet.getFilter()

const ss = SpreadsheetApp.getActiveSheet();
const range = ss.getRange('A1:C20');

// Creates a new filter and applies it to the range A1:C20 on the active sheet.
function createFilter() {
  range.createFilter();
}
// Gets the filter and applies criteria that only shows cells that aren't empty.
function getFilterAddCriteria() {
  const filter = range.getFilter();
  const criteria =
      SpreadsheetApp.newFilterCriteria().whenCellNotEmpty().build();
  filter.setColumnFilterCriteria(2, criteria);
}
ใช้วิธีนี้เพื่อสร้างตัวกรองสำหรับชีต Grid ซึ่งเป็นชีตประเภทเริ่มต้น ชีตตารางกริดคือชีตที่ไม่ได้เชื่อมต่อกับฐานข้อมูล หากต้องการสร้างตัวกรองประเภทอื่นๆ โปรดดูข้อมูลต่อไปนี้

รีเทิร์น

Filter - ตัวกรองใหม่

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

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

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

createPivotTable(sourceData)

สร้างตาราง Pivot ว่างจาก sourceData ที่ระบุซึ่งยึดไว้ที่เซลล์แรก ในช่วงนี้

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets cell A1 as a range in order to place the pivot table.
const range = sheet.getRange('A1');

// Gets the range of the source data for the pivot table.
const dataRange = sheet.getRange('E12:G20');

// Creates an empty pivot table from the specified source data.
const pivotTable = range.createPivotTable(dataRange);

// Logs the values from the pivot table's source data to the console.
console.log(pivotTable.getSourceDataRange().getValues());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sourceDataRangeข้อมูลที่จะใช้สร้างตาราง Pivot

รีเทิร์น

PivotTable - PivotTable ที่สร้างขึ้นใหม่

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

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

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

createTextFinder(findText)

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

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();

// Creates  a text finder for the range.
const textFinder = range.createTextFinder('dog');

// Returns the first occurrence of 'dog'.
const firstOccurrence = textFinder.findNext();

// Replaces the last found occurrence of 'dog' with 'cat' and returns the number
// of occurrences replaced.
const numOccurrencesReplaced = textFinder.replaceWith('cat');

พารามิเตอร์

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

รีเทิร์น

TextFinder - TextFinder สำหรับช่วง


deleteCells(shiftDimension)

ลบช่วงของเซลล์นี้ ระบบจะเลื่อนข้อมูลที่มีอยู่ในชีตตามมิติข้อมูลที่ระบุ ไปยังช่วงที่ลบ

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

const range = sheet.getRange('A1:D10');
range.deleteCells(SpreadsheetApp.Dimension.COLUMNS);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
shiftDimensionDimensionมิติข้อมูลที่จะเลื่อนข้อมูลที่มีอยู่

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

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

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

expandGroups()

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

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();

// All row and column groups within the range are expanded.
range.expandGroups();

รีเทิร์น

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

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

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

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

getA1Notation()

แสดงผลคำอธิบายสตริงของช่วงในรูปแบบ A1

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange(1, 1, 2, 5);

// Logs "A1:E2"
Logger.log(range.getA1Notation());

รีเทิร์น

String — สตริงคำอธิบายของช่วงในรูปแบบ A1

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

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

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

getBackground()

แสดงสีพื้นหลังของเซลล์ซ้ายบนสุดในช่วง (เช่น '#ffffff')

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

const cell = sheet.getRange('B5');
Logger.log(cell.getBackground());

รีเทิร์น

String — รหัสสีของพื้นหลัง

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

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

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

getBackgroundObject()

แสดงผลสีพื้นหลังของเซลล์ด้านซ้ายบนในช่วง

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

const cell = sheet.getRange('B5');
Logger.log(cell.getBackgroundObject().asRgbColor().asHexString());

รีเทิร์น

Color — สีพื้นหลังของเซลล์ด้านซ้ายบนในช่วง

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

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

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

getBackgroundObjects()

แสดงผลสีพื้นหลังของเซลล์ในช่วง

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

const range = sheet.getRange('B5:C6');
const bgColors = range.getBackgroundObjects();
for (const i in bgColors) {
  for (const j in bgColors[i]) {
    Logger.log(bgColors[i][j].asRgbColor().asHexString());
  }
}

รีเทิร์น

Color[][] — อาร์เรย์สองมิติของสีพื้นหลัง

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

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

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

getBackgrounds()

แสดงผลสีพื้นหลังของเซลล์ในช่วง (เช่น '#ffffff')

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

const range = sheet.getRange('B5:C6');
const bgColors = range.getBackgrounds();
for (const i in bgColors) {
  for (const j in bgColors[i]) {
    Logger.log(bgColors[i][j]);
  }
}

รีเทิร์น

String[][] — อาร์เรย์สองมิติของรหัสสีของพื้นหลัง

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Sets a range.
const range = sheet.getRange('A1:K50');

// Gets the banding info for the range.
const bandings = range.getBandings();

// Logs the second row color for each banding 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

getCell(row, column)

แสดงผลเซลล์ที่กำหนดภายในช่วง

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

const range = sheet.getRange('B2:D4');

// The row and column here are relative to the range
// getCell(1,1) in this code returns the cell at B2
const cell = range.getCell(1, 1);
Logger.log(cell.getValue());

พารามิเตอร์

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

รีเทิร์น

Range — ช่วงที่มีเซลล์เดียวที่พิกัดที่ระบุ

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

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

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

getColumn()

แสดงตำแหน่งคอลัมน์เริ่มต้นของช่วงนี้

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

const range = sheet.getRange('B2:D4');
// Logs "2.0"
Logger.log(range.getColumn());

รีเทิร์น

Integer — ตำแหน่งคอลัมน์เริ่มต้นของช่วงในสเปรดชีต

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

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

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

getDataRegion()

แสดงผลสำเนาของช่วงที่ขยายในทิศทางหลักทั้ง 4 Direction เพื่อครอบคลุมเซลล์ที่อยู่ติดกันทั้งหมด ซึ่งมีข้อมูลอยู่ หากช่วงล้อมรอบด้วยเซลล์ว่างที่ไม่รวมเซลล์ตามแนวทแยง ระบบจะแสดงผลช่วงนั้นเอง ซึ่งคล้ายกับการเลือกช่วงและ พิมพ์ Ctrl+A ในเอดิเตอร์

// Assume the active spreadsheet is blank.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
sheet.getRange('C2').setValue(100);
sheet.getRange('B3').setValue(100);
sheet.getRange('D3').setValue(100);
sheet.getRange('C4').setValue(100);
// Logs "B2:D4"
Logger.log(sheet.getRange('C3').getDataRegion().getA1Notation());

รีเทิร์น

Range — เขตข้อมูลของช่วงหรือช่วงสำหรับทั้งสเปรดชีต

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

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

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

getDataRegion(dimension)

แสดงผลสำเนาของช่วงที่ขยาย Direction.UP และ Direction.DOWN หากมิติข้อมูลที่ระบุคือ Dimension.ROWS หรือ Direction.NEXT และ Direction.PREVIOUS หากมิติข้อมูลคือ Dimension.COLUMNS การขยายช่วง จะขึ้นอยู่กับการตรวจหาข้อมูลที่อยู่ถัดจากช่วงซึ่งจัดระเบียบเหมือนตาราง ช่วงที่ขยาย ครอบคลุมเซลล์ที่อยู่ติดกันทั้งหมดที่มีข้อมูลในมิติข้อมูลที่ระบุ รวมถึงขอบเขตของตาราง หากช่วงเดิมล้อมรอบด้วยเซลล์ว่างตามมิติข้อมูลที่ระบุ ระบบจะแสดงผลช่วงนั้นเอง วิธีนี้คล้ายกับการเลือกช่วงและพิมพ์ Ctrl+Space สำหรับคอลัมน์หรือ Shift+Space สำหรับแถวในเครื่องมือแก้ไข

// Assume the active spreadsheet is blank.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
sheet.getRange('C2').setValue(100);
sheet.getRange('B3').setValue(100);
sheet.getRange('D3').setValue(100);
sheet.getRange('C4').setValue(100);
// Logs "C2:C4"
Logger.log(
    sheet.getRange('C3')
        .getDataRegion(SpreadsheetApp.Dimension.ROWS)
        .getA1Notation(),
);
// Logs "B3:D3"
Logger.log(
    sheet.getRange('C3')
        .getDataRegion(SpreadsheetApp.Dimension.COLUMNS)
        .getA1Notation(),
);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dimensionDimensionมิติข้อมูลที่จะขยายช่วง

รีเทิร์น

Range — ภูมิภาคข้อมูลของช่วงหรือช่วงที่ครอบคลุมแต่ละคอลัมน์หรือแต่ละแถวที่ครอบคลุมโดยช่วงเดิม

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

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

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

getDataSourceFormula()

แสดงผล DataSourceFormula สำหรับเซลล์แรกในช่วง หรือ null หาก เซลล์ไม่มีสูตรแหล่งข้อมูล

// 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 the range A1 on Sheet1.
const range = sheet.getRange('A1');

// Gets the data source formula from cell A1.
const dataSourceFormula = range.getDataSourceFormula();

// Gets the formula.
const formula = dataSourceFormula.getFormula();

// Logs the formula.
console.log(formula);

รีเทิร์น

DataSourceFormulaDataSourceFormula ของเซลล์

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

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

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

getDataSourceFormulas()

แสดงผล DataSourceFormula สำหรับเซลล์ในช่วง

// 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 the range A1:B5 on Sheet1.
const range = sheet.getRange('A1:B5');

// Gets an array of the data source formulas in the range A1:B5.
const dataSourceFormulas = range.getDataSourceFormulas();

// Logs the first formula in the array.
console.log(dataSourceFormulas[0].getFormula());

รีเทิร์น

DataSourceFormula[] - อาร์เรย์ของ 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 the range A1:G50 on Sheet1.
const range = sheet.getRange('A1:G50');

// Gets an array of the data source pivot tables in the range A1:G50.
const dataSourcePivotTables = range.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 the range A1:G50 on Sheet1.
const range = sheet.getRange('A1:G50');

// Gets the first data source table in the range A1:G50.
const dataSourceTable = range.getDataSourceTables()[0];

// Logs the time of the last completed data execution on the data source table.
console.log(dataSourceTable.getStatus().getLastExecutionTime());

รีเทิร์น

DataSourceTable[] - รายการตารางแหล่งข้อมูล

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

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

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

getDataSourceUrl()

แสดง URL ของข้อมูลในช่วงนี้ ซึ่งใช้เพื่อสร้างแผนภูมิและการค้นหาได้

Code.gs

function doGet() {
  const ss = SpreadsheetApp.openById(
      '1khO6hBWTNNyvyyxvob7aoZTI9ZvlqqASNeq0e29Tw2c',
  );
  const sheet = ss.getSheetByName('ContinentData');
  const range = sheet.getRange('A1:B8');

  const template = HtmlService.createTemplateFromFile('piechart');
  template.dataSourceUrl = range.getDataSourceUrl();
  return template.evaluate();
}

piechart.html

<!DOCTYPE html>
<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      // Load the Visualization API and the corechart package.
      google.charts.load('current', {'packages': ['corechart']});

      // Set a callback to run when the Google Visualization API is loaded.
      google.charts.setOnLoadCallback(queryData);

      function queryData() {
        var query = new google.visualization.Query('<?= dataSourceUrl ?>');
        query.send(drawChart);
      }

      // Callback that creates and populates a data table,
      // instantiates the pie chart, passes in the data and
      // draws it.
      function drawChart(response) {
        if (response.isError()) {
          alert('Error: ' + response.getMessage() + ' ' + response.getDetailedMessage());
          return;
        }
        var data = response.getDataTable();

        // Set chart options.
        var options = {
          title: 'Population by Continent',
          width: 400,
          height: 300
        };

        // Instantiate and draw the chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
  </head>
  <body>
    <!-- Div that holds the pie chart. -->
    <div id="chart_div"></div>
  </body>
</html>

รีเทิร์น

String — URL ของช่วงนี้เป็นแหล่งข้อมูลที่ส่งไปยัง API อื่นๆ ได้ เช่น แผนภูมิ

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

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

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

getDataTable()

ส่งคืนข้อมูลภายในออบเจ็กต์นี้เป็น DataTable

// 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 the range A1:B7 on Sheet1.
const range = sheet.getRange('A1:B7');

// Gets the range A1:B7 as a data table. The values in each column must be of
// the same type.
const datatable = range.getDataTable();

// Uses the Charts service to build a bar chart from the data table.
// This doesn't build an embedded chart. To do that, use
// sheet.newChart().addRange() instead.
const chart = Charts.newBarChart()
                  .setDataTable(datatable)
                  .setOption('title', 'Your Chart Title Here')
                  .build();

รีเทิร์น

DataTable — ข้อมูลเป็นตารางข้อมูล


getDataTable(firstRowIsHeader)

แสดงผลข้อมูลภายในช่วงนี้เป็น DataTable

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:B7');

// Calling this method with "true" sets the first line to be the title of the
// axes
const datatable = range.getDataTable(true);

// Note that this doesn't build an EmbeddedChart, so you can't just use
// Sheet#insertChart(). To do that, use sheet.newChart().addRange() instead.
const chart = Charts.newBarChart()
                  .setDataTable(datatable)
                  .setOption('title', 'Your Title Here')
                  .build();

พารามิเตอร์

ชื่อประเภทคำอธิบาย
firstRowIsHeaderBooleanจะถือว่าแถวแรกเป็นส่วนหัวหรือไม่

รีเทิร์น

DataTable — ข้อมูลเป็นตารางข้อมูล

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

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

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

getDataValidation()

แสดงผลกฎการตรวจสอบข้อมูลสำหรับเซลล์ด้านซ้ายบนในช่วง หากไม่ได้ตั้งค่าการตรวจสอบข้อมูลในเซลล์ เมธอดนี้จะแสดงผล null

// Log information about the data validation rule for cell A1.
const cell = SpreadsheetApp.getActive().getRange('A1');
const rule = cell.getDataValidation();
if (rule != null) {
  const criteria = rule.getCriteriaType();
  const args = rule.getCriteriaValues();
  Logger.log('The data validation rule is %s %s', criteria, args);
} else {
  Logger.log('The cell does not have a data validation rule.');
}

รีเทิร์น

DataValidation — กฎการตรวจสอบข้อมูลสำหรับเซลล์ด้านซ้ายบนในช่วง

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

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

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

getDataValidations()

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

// Change existing data validation rules that require a date in 2013 to require
// a date in 2014.
const oldDates = [new Date('1/1/2013'), new Date('12/31/2013')];
const newDates = [new Date('1/1/2014'), new Date('12/31/2014')];
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns());
const rules = range.getDataValidations();

for (let i = 0; i < rules.length; i++) {
  for (let j = 0; j < rules[i].length; j++) {
    const rule = rules[i][j];

    if (rule != null) {
      const criteria = rule.getCriteriaType();
      const args = rule.getCriteriaValues();

      if (criteria === SpreadsheetApp.DataValidationCriteria.DATE_BETWEEN &&
          args[0].getTime() === oldDates[0].getTime() &&
          args[1].getTime() === oldDates[1].getTime()) {
        // Create a builder from the existing rule, then change the dates.
        rules[i][j] = rule.copy().withCriteria(criteria, newDates).build();
      }
    }
  }
}
range.setDataValidations(rules);

รีเทิร์น

DataValidation[][] - อาร์เรย์สองมิติของกฎการตรวจสอบข้อมูลที่เชื่อมโยงกับเซลล์ใน ช่วง

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

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets row 2 on Sheet1.
const range = sheet.getRange('2:2');

// Adds metadata to row 2.
range.addDeveloperMetadata('NAME', 'GOOGLE');

// Logs the metadata to console.
for (const metadata of range.getDeveloperMetadata()) {
  console.log(`${metadata.getKey()}: ${metadata.getValue()}`);
}

รีเทิร์น

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

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

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

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

getDisplayValue()

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

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets cell A30 and sets its value to 'Test code.'
const cell = sheet.getRange('A30');
cell.setValue('Test code');

// Gets the value and logs it to the console.
console.log(cell.getDisplayValue());

รีเทิร์น

String — ค่าที่แสดงในเซลล์นี้

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

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

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

getDisplayValues()

แสดงผลตารางกริดสี่เหลี่ยมของค่าสำหรับช่วงนี้

แสดงผลอาร์เรย์ 2 มิติของค่าที่แสดง โดยจัดทำดัชนีตามแถว แล้วจึงตามคอลัมน์ ค่าคือออบเจ็กต์ String ค่าที่แสดงจะพิจารณาการจัดรูปแบบวันที่ เวลา และสกุลเงิน รวมถึงรูปแบบที่สเปรดชีตใช้โดยอัตโนมัติ ในการตั้งค่าภาษา เซลล์ว่างจะแสดงด้วยสตริงว่างในอาร์เรย์ โปรดทราบว่าแม้ว่าดัชนีช่วงจะเริ่มต้นที่ 1, 1 แต่อาร์เรย์ JavaScript จะจัดทำดัชนีจาก [0][0]

// The code below gets the displayed values for the range C2:G8
// in the active spreadsheet.  Note that this is a JavaScript array.
const values =
    SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getDisplayValues();
Logger.log(values[0][0]);

รีเทิร์น

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

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

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

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

getFilter()

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

const ss = SpreadsheetApp.getActiveSheet();
const range = ss.getRange('A1:C20');
// Gets the existing filter on the sheet that the given range belongs to.
const filter = range.getFilter();

รีเทิร์น

Filter — ตัวกรอง

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

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

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

getFontColorObject()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontColorObject().asRgbColor().asHexString());

รีเทิร์น

Color — สีแบบอักษรของเซลล์ซ้ายบนสุดในช่วง

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

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

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

getFontColorObjects()

แสดงผลสีแบบอักษรของเซลล์ในช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontColorObjects();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j].asRgbColor().asHexString());
  }
}

รีเทิร์น

Color[][] — อาร์เรย์ 2 มิติของสีแบบอักษรที่เชื่อมโยงกับเซลล์ในช่วง

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

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

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

getFontFamilies()

แสดงผลชุดแบบอักษรของเซลล์ในช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontFamilies();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

รีเทิร์น

String[][] — อาร์เรย์ 2 มิติของชุดแบบอักษรที่เชื่อมโยงกับเซลล์ในช่วง

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

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

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

getFontFamily()

แสดงผลตระกูลแบบอักษรของเซลล์ที่มุมซ้ายบนของช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontFamily());

รีเทิร์น

String — ชุดแบบอักษรของเซลล์

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

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

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

getFontLine()

รับรูปแบบเส้นของเซลล์ที่มุมซ้ายบนของช่วง ('underline', 'line-through' หรือ 'none')

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontLine());

รีเทิร์น

String — บรรทัดแบบอักษร

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

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

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

getFontLines()

รับรูปแบบเส้นของเซลล์ในช่วง ('underline', 'line-through' หรือ 'none')

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontLines();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

รีเทิร์น

String[][] — อาร์เรย์ 2 มิติของเส้นแบบอักษรที่เชื่อมโยงกับเซลล์ในช่วง

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

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

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

getFontSize()

แสดงผลขนาดแบบอักษรในหน่วยพอยต์ของเซลล์ที่มุมบนซ้ายของช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontSize());

รีเทิร์น

Integer — ขนาดแบบอักษรในหน่วยพอยต์

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

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

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

getFontSizes()

แสดงผลขนาดแบบอักษรของเซลล์ในช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontSizes();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

รีเทิร์น

Integer[][] — อาร์เรย์ 2 มิติของขนาดแบบอักษรของข้อความที่เชื่อมโยงกับเซลล์ในช่วง

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

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

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

getFontStyle()

แสดงผลรูปแบบแบบอักษร ('italic' หรือ 'normal') ของเซลล์ที่มุมซ้ายบน ของช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontStyle());

รีเทิร์น

String — รูปแบบแบบอักษรของข้อความในเซลล์

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

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

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

getFontStyles()

แสดงรูปแบบแบบอักษรของเซลล์ในช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontStyles();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

รีเทิร์น

String[][] — อาร์เรย์ 2 มิติของรูปแบบแบบอักษรของข้อความที่เชื่อมโยงกับเซลล์ในช่วง

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

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

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

getFontWeight()

แสดงผลความหนาของแบบอักษร (ปกติ/ตัวหนา) ของเซลล์ที่มุมซ้ายบนของช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getFontWeight());

รีเทิร์น

String — น้ำหนักแบบอักษรของข้อความในเซลล์

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

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

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

getFontWeights()

แสดงผลความหนาของแบบอักษรของเซลล์ในช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getFontWeights();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

รีเทิร์น

String[][] — อาร์เรย์ 2 มิติของความหนาแบบอักษรของข้อความที่เชื่อมโยงกับเซลล์ในช่วง

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

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

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

getFormula()

แสดงสูตร (รูปแบบ A1) สำหรับเซลล์บนซ้ายของช่วง หรือสตริงว่างหากเซลล์ว่างหรือไม่มีสูตร

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

// This assumes you have a function in B5 that sums up
// B2:B4
const range = sheet.getRange('B5');

// Logs the calculated value and the formula
Logger.log(
    'Calculated value: %s Formula: %s',
    range.getValue(),
    range.getFormula(),
);

รีเทิร์น

String — สูตรสำหรับเซลล์

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

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

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

getFormulaR1C1()

แสดงผลสูตร (สัญกรณ์ R1C1) สำหรับเซลล์ที่ระบุ หรือ null หากไม่มี

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

const range = sheet.getRange('B5');
const formula = range.getFormulaR1C1();
Logger.log(formula);

รีเทิร์น

String — สูตรในรูปแบบ R1C1

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

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

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

getFormulas()

แสดงผลสูตร (รูปแบบ A1) สำหรับเซลล์ในช่วง รายการในอาร์เรย์ 2 มิติคือ สตริงว่างสำหรับเซลล์ที่ไม่มีสูตร

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

const range = sheet.getRange('B5:C6');
const formulas = range.getFormulas();
for (const i in formulas) {
  for (const j in formulas[i]) {
    Logger.log(formulas[i][j]);
  }
}

รีเทิร์น

String[][] — อาร์เรย์ 2 มิติของสูตรในรูปแบบสตริง

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

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

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

getFormulasR1C1()

แสดงผลสูตร (สัญกรณ์ R1C1) สำหรับเซลล์ในช่วง รายการในอาร์เรย์ 2 มิติคือ null สำหรับเซลล์ที่ไม่มีสูตร

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

const range = sheet.getRange('B5:C6');
const formulas = range.getFormulasR1C1();
for (const i in formulas) {
  for (const j in formulas[i]) {
    Logger.log(formulas[i][j]);
  }
}

รีเทิร์น

String[][] — อาร์เรย์ 2 มิติของสูตรในสัญกรณ์ R1C1

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

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

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

getGridId()

แสดงผลรหัสตารางกริดของชีตหลักของช่วง รหัสเป็นค่าจำนวนเต็มแบบสุ่มที่ไม่ติดลบ

// Log the grid ID of the first sheet (by tab position) in the spreadsheet.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getGridId());

รีเทิร์น

Integer — รหัสตารางกริดของชีตหลัก

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

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

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

getHeight()

แสดงผลความสูงของช่วง

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

const range = sheet.getRange('B2:D4');
// logs 3.0
Logger.log(range.getHeight());

รีเทิร์น

Integer — ความสูงของช่วง

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

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

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

getHorizontalAlignment()

แสดงการจัดแนวข้อความในแนวนอน (ซ้าย/กึ่งกลาง/ขวา) ของเซลล์ที่มุมซ้ายบน ของช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getHorizontalAlignment());

รีเทิร์น

String — การจัดแนวข้อความในเซลล์ในแนวนอน

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

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

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

getHorizontalAlignments()

แสดงผลการจัดแนวแนวนอนของเซลล์ในช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getHorizontalAlignments();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

รีเทิร์น

String[][] — อาร์เรย์ 2 มิติของการจัดแนวแนวนอนของข้อความที่เชื่อมโยงกับเซลล์ใน ช่วง

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

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

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

getLastColumn()

แสดงตำแหน่งคอลัมน์สิ้นสุด

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

const range = sheet.getRange('B2:D4');
// Logs "4.0"
Logger.log(range.getLastColumn());

รีเทิร์น

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

const range = sheet.getRange('B2:D4');
// Logs "4.0"
Logger.log(range.getLastRow());

รีเทิร์น

Integer — ตำแหน่งแถวสิ้นสุดของช่วงในสเปรดชีต

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

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

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

getMergedRanges()

แสดงผลอาร์เรย์ของออบเจ็กต์ Range ที่แสดงถึงเซลล์ที่ผสานซึ่งอยู่ภายในช่วงปัจจุบันทั้งหมด หรือมีเซลล์อย่างน้อย 1 เซลล์ในช่วงปัจจุบัน

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

const range = sheet.getRange('A1:B3');

const mergedRanges = range.getMergedRanges();
for (let i = 0; i < mergedRanges.length; i++) {
  Logger.log(mergedRanges[i].getA1Notation());
  Logger.log(mergedRanges[i].getDisplayValue());
}

รีเทิร์น

Range[] — อาร์เรย์ของออบเจ็กต์ Range ซึ่งแสดงเซลล์ที่ผสานที่ทับซ้อนกับช่วง


getNextDataCell(direction)

โดยเริ่มจากเซลล์ในคอลัมน์และแถวแรกของช่วง ฟังก์ชันจะแสดงผลเซลล์ถัดไปใน ทิศทางที่ระบุซึ่งเป็นขอบของช่วงเซลล์ที่ต่อเนื่องกันซึ่งมีข้อมูลอยู่ หรือเซลล์ ที่ขอบของสเปรดชีตในทิศทางนั้น ซึ่งเทียบเท่ากับการพิมพ์ Ctrl+[arrow key] ในเอดิเตอร์

// Assume the active spreadsheet is blank.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];

const range = sheet.getRange('C3:E5');
// Logs "C1"
Logger.log(range.getNextDataCell(SpreadsheetApp.Direction.UP).getA1Notation());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
directionDirectionทิศทางที่จะค้นหาเซลล์ขอบเขตข้อมูลถัดไป

รีเทิร์น

Range — เซลล์ขอบเขตข้อมูลหรือเซลล์ที่ขอบของสเปรดชีต

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

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

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

getNote()

แสดงหมายเหตุที่เชื่อมโยงกับช่วงที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getNote());

รีเทิร์น

String — หมายเหตุที่เชื่อมโยงกับเซลล์ที่ระบุ

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

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

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

getNotes()

แสดงหมายเหตุที่เชื่อมโยงกับเซลล์ในช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getNotes();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

รีเทิร์น

String[][] — อาร์เรย์ 2 มิติของหมายเหตุที่เชื่อมโยงกับเซลล์ในช่วง

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

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

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

getNumColumns()

แสดงผลจำนวนคอลัมน์ในช่วงนี้

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

const range = sheet.getRange('B2:D5');
Logger.log(range.getNumColumns());

รีเทิร์น

Integer — จำนวนคอลัมน์ในช่วงนี้

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

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

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

getNumRows()

แสดงผลจำนวนแถวในช่วงนี้

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

const range = sheet.getRange('B2:D5');
Logger.log(range.getNumRows());

รีเทิร์น

Integer — จำนวนแถวในช่วงนี้

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

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

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

getNumberFormat()

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

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

const cell = sheet.getRange('C4');
Logger.log(cell.getNumberFormat());

รีเทิร์น

String — รูปแบบตัวเลขของเซลล์ซ้ายบนของช่วง

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

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

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

getNumberFormats()

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

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

const range = sheet.getRange('B5:C6');
const formats = range.getNumberFormats();
for (const i in formats) {
  for (const j in formats[i]) {
    Logger.log(formats[i][j]);
  }
}

รีเทิร์น

String[][] — อาร์เรย์สองมิติของรูปแบบตัวเลข

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

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

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

getRichTextValue()

แสดงผลค่าข้อความ Rich Text สำหรับเซลล์ซ้ายบนสุดของช่วง หรือ null หากค่าเซลล์ไม่ใช่ข้อความ

// Gets the Rich Text value of cell D4.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('D4:F6');
const richText = range.getRichTextValue();
console.log(richText.getText());

รีเทิร์น

RichTextValue — ค่าข้อความ Rich Text ของเซลล์ซ้ายบนสุดในช่วง หรือ null หากค่าของเซลล์ ไม่ใช่ข้อความ

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

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

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

getRichTextValues()

แสดงผลค่าข้อความที่มีรูปแบบสำหรับเซลล์ในช่วง

// Gets the Rich Text values for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const values = range.getRichTextValues();

for (let i = 0; i < values.length; i++) {
  for (let j = 0; j < values[i].length; j++) {
    console.log(values[i][j].getText());
  }
}

รีเทิร์น

RichTextValue[][] — อาร์เรย์ 2 มิติของค่าข้อความที่มีรูปแบบ

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

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

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

getRow()

แสดงผลตำแหน่งแถวสำหรับช่วงนี้ เหมือนกับ getRowIndex()

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

const range = sheet.getRange('B2');
Logger.log(range.getRow());

รีเทิร์น

Integer — ตำแหน่งแถวของช่วง

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

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

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

getRowIndex()

แสดงผลตำแหน่งแถวสำหรับช่วงนี้ เหมือนกับ getRow()

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

const range = sheet.getRange('B2');
Logger.log(range.getRowIndex());

รีเทิร์น

Integer — ตำแหน่งแถวของช่วง

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

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

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

ดูเพิ่มเติม


getSheet()

แสดงผลชีตที่ช่วงนี้เป็นของ

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Gets the sheet that the range belongs to.
const rangeSheet = range.getSheet();

// Gets the sheet name and logs it to the console.
console.log(rangeSheet.getName());

รีเทิร์น

Sheet — ชีตที่ช่วงนี้เป็นของ

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

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

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

getTextDirection()

แสดงผลทิศทางข้อความสำหรับเซลล์ซ้ายบนสุดของช่วง แสดงผล null หากกำหนดทิศทางข้อความของเซลล์ด้วยการตรวจหาอัตโนมัติ

// Get the text direction of cell B1.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B1:D4');
Logger.log(range.getTextDirection());

รีเทิร์น

TextDirection — ทิศทางข้อความของเซลล์ซ้ายบนสุดในช่วง

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

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

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

getTextDirections()

แสดงผลทิศทางข้อความสำหรับเซลล์ในช่วง รายการในอาร์เรย์ 2 มิติคือ null สำหรับเซลล์ที่ใช้การตรวจหาอัตโนมัติ

// Get the text directions for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const directions = range.getTextDirections();

for (let i = 0; i < directions.length; i++) {
  for (let j = 0; j < directions[i].length; j++) {
    Logger.log(directions[i][j]);
  }
}

รีเทิร์น

TextDirection[][] — อาร์เรย์สองมิติของทิศทางข้อความ

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

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

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

getTextRotation()

แสดงการตั้งค่าการหมุนข้อความสำหรับเซลล์ด้านซ้ายบนของช่วง

// Log the text rotation settings for a cell.
const sheet = SpreadsheetApp.getActiveSheet();

const cell = sheet.getRange('A1');
Logger.log(cell.getTextRotation());

รีเทิร์น

TextRotation — การตั้งค่าการหมุนเวียนข้อความ

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

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

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

getTextRotations()

แสดงผลการตั้งค่าการหมุนข้อความสำหรับเซลล์ในช่วง

const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');

const results = range.getTextRotations();

for (const i in results) {
  for (const j in results[i]) {
    const rotation = results[i][j];
    Logger.log('Cell [%s, %s] has text rotation: %v', i, j, rotation);
  }
}

รีเทิร์น

TextRotation[][] — อาร์เรย์สองมิติของการหมุนข้อความที่เชื่อมโยงกับเซลล์ในช่วง

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

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

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

getTextStyle()

แสดงรูปแบบข้อความสำหรับเซลล์ซ้ายบนสุดของช่วง

// Get the text style of cell D4.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('D4:F6');
const style = range.getTextStyle();
Logger.log(style);

รีเทิร์น

TextStyle — รูปแบบข้อความของเซลล์ซ้ายบนสุดในช่วง

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

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

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

getTextStyles()

แสดงผลรูปแบบข้อความสำหรับเซลล์ในช่วง

// Get the text styles for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const styles = range.getTextStyles();

for (let i = 0; i < styles.length; i++) {
  for (let j = 0; j < styles[i].length; j++) {
    Logger.log(styles[i][j]);
  }
}

รีเทิร์น

TextStyle[][] - อาร์เรย์สองมิติของรูปแบบข้อความ

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

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

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

getValue()

แสดงค่าของเซลล์ซ้ายบนสุดในช่วง ค่าอาจเป็นประเภท Number, Boolean, Date หรือ String ขึ้นอยู่กับค่าของเซลล์ เซลล์ที่ว่าง จะแสดงผลสตริงว่าง

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Gets the value of the top-left cell in the range and logs it to the console.
console.log(range.getValue());

รีเทิร์น

Object — ค่าในเซลล์นี้

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

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

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

getValues()

แสดงผลตารางกริดสี่เหลี่ยมของค่าสำหรับช่วงนี้

แสดงผลอาร์เรย์ค่า 2 มิติที่จัดทำดัชนีตามแถว แล้วจึงตามคอลัมน์ ค่าอาจเป็นประเภท Number, Boolean, Date หรือ String ขึ้นอยู่กับค่าของเซลล์ เซลล์ว่างจะแสดงด้วยสตริงว่างในอาร์เรย์ โปรดทราบว่าดัชนีช่วงจะเริ่มต้นที่ 1, 1 แต่ดัชนีอาร์เรย์ JavaScript จะเริ่มต้นที่ [0][0]

// The code below gets the values for the range C2:G8
// in the active spreadsheet.  Note that this is a JavaScript array.
const values = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getValues();
Logger.log(values[0][0]);
ในเว็บแอป ค่า Date ไม่ใช่พารามิเตอร์ที่ถูกต้อง getValues() จะแสดงผลข้อมูลไปยังเว็บแอปไม่ได้หากช่วงมีเซลล์ที่มีค่า Date แต่ให้แปลงค่าทั้งหมดที่ดึงมาจากชีตเป็น JavaScript Primitive ที่รองรับ เช่น Number, Boolean หรือ String

รีเทิร์น

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

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

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

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

getVerticalAlignment()

แสดงการจัดแนวตั้ง (บน/กลาง/ล่าง) ของเซลล์ที่มุมซ้ายบนของ ช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getVerticalAlignment());

รีเทิร์น

String — การจัดแนวข้อความในเซลล์ในแนวตั้ง

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

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

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

getVerticalAlignments()

แสดงผลการจัดแนวตั้งของเซลล์ในช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getVerticalAlignments();

for (const i in results) {
  for (const j in results[i]) {
    Logger.log(results[i][j]);
  }
}

รีเทิร์น

String[][] — อาร์เรย์ 2 มิติของการจัดแนวข้อความในแนวตั้งที่เชื่อมโยงกับเซลล์ใน ช่วง

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

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

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

getWidth()

แสดงผลความกว้างของช่วงในคอลัมน์

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Gets the width of the range in number of columns and logs it to the console.
console.log(range.getWidth());

รีเทิร์น

Integer — จำนวนคอลัมน์ในช่วง

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

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

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

getWrap()

แสดงว่าข้อความในเซลล์มีการตัดข้อความหรือไม่ หากต้องการใช้กลยุทธ์การตัดคำที่ละเอียดยิ่งขึ้น ให้ใช้ getWrapStrategy()

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.getWrap());

รีเทิร์น

Boolean — ข้อความในเซลล์นี้จะตัดหรือไม่

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

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

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

getWrapStrategies()

แสดงผลกลยุทธ์การตัดข้อความสำหรับเซลล์ในช่วง

// Get the text wrapping strategies for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const strategies = range.getWrapStrategies();

for (let i = 0; i < strategies.length; i++) {
  for (let j = 0; j < strategies[i].length; j++) {
    Logger.log(strategies[i][j]);
  }
}

รีเทิร์น

WrapStrategy[][] - อาร์เรย์สองมิติของกลยุทธ์การตัดข้อความ

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

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

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

getWrapStrategy()

แสดงผลกลยุทธ์การตัดข้อความสำหรับเซลล์ซ้ายบนสุดของช่วง

// Get the text wrapping strategy of cell B1.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B1:D4');
Logger.log(range.getWrapStrategy());

รีเทิร์น

WrapStrategy — กลยุทธ์การตัดข้อความของเซลล์ซ้ายบนสุดในช่วง

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

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

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

getWraps()

แสดงว่าข้อความในเซลล์มีการตัดข้อความหรือไม่ หากต้องการใช้กลยุทธ์การตัดคำที่ละเอียดยิ่งขึ้น ให้ใช้ getWrapStrategies()

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

const results = range.getVerticalAlignments();

for (const i in results) {
  for (const j in results[i]) {
    const isWrapped = results[i][j];
    if (isWrapped) {
      Logger.log('Cell [%s, %s] has wrapped text', i, j);
    }
  }
}

รีเทิร์น

Boolean[][] — อาร์เรย์ 2 มิติของการจัดแนวข้อความในแนวตั้งที่เชื่อมโยงกับเซลล์ใน ช่วง

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

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

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

insertCells(shiftDimension)

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

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

const range = sheet.getRange('A1:D10');
range.insertCells(SpreadsheetApp.Dimension.COLUMNS);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
shiftDimensionDimensionมิติข้อมูลที่จะเลื่อนข้อมูลที่มีอยู่

รีเทิร์น

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

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

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

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

insertCheckboxes()

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

const range = SpreadsheetApp.getActive().getRange('A1:B10');

// Inserts checkboxes into each cell in the range A1:B10 configured with 'true'
// for checked and 'false' for unchecked. Also, sets the value of each cell in
// the range A1:B10 to 'false'.
range.insertCheckboxes();

รีเทิร์น

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

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

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

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

insertCheckboxes(checkedValue)

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

const range = SpreadsheetApp.getActive().getRange('A1:B10');

// Inserts checkboxes into each cell in the range A1:B10 configured with 'yes'
// for checked and the empty string for unchecked. Also, sets the value of each
// cell in the range A1:B10 to
//  the empty string.
range.insertCheckboxes('yes');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
checkedValueObjectค่าที่เลือกสำหรับการตรวจสอบข้อมูลของช่องทำเครื่องหมาย

รีเทิร์น

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

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

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

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

insertCheckboxes(checkedValue, uncheckedValue)

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

const range = SpreadsheetApp.getActive().getRange('A1:B10');

// Inserts checkboxes into each cell in the range A1:B10 configured with 'yes'
// for checked and 'no' for unchecked. Also, sets the value of each cell in the
// range A1:B10 to 'no'.
range.insertCheckboxes('yes', 'no');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
checkedValueObjectค่าที่เลือกสำหรับการตรวจสอบข้อมูลของช่องทำเครื่องหมาย
uncheckedValueObjectค่าที่ไม่ได้เลือกสำหรับการตรวจสอบข้อมูลของช่องทําเครื่องหมาย

รีเทิร์น

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

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

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

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

isBlank()

แสดงผล true หากช่วงว่างเปล่าทั้งหมด

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');

Logger.log(range.isBlank());

รีเทิร์น

Booleantrue หากช่วงว่างเปล่า หรือ false ในกรณีอื่นๆ

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

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

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

isChecked()

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

const range = SpreadsheetApp.getActive().getRange('A1:A3');

// Inserts checkboxes and sets each cell value to 'no' in the range A1:A3.
range.insertCheckboxes('yes', 'no');

const range1 = SpreadsheetApp.getActive().getRange('A1');
range1.setValue('yes');
// Sets the value of isRange1Checked as true as it contains the checked value.
const isRange1Checked = range1.isChecked();

const range2 = SpreadsheetApp.getActive().getRange('A2');
range2.setValue('no');
// Sets the value of isRange2Checked as false as it contains the unchecked
// value.
const isRange2Checked = range2.isChecked();

const range3 = SpreadsheetApp.getActive().getRange('A3');
range3.setValue('random');
// Sets the value of isRange3Checked as null, as it contains an invalid checkbox
// value.
const isRange3Checked = range3.isChecked();

รีเทิร์น

Booleantrue หากเลือกช่องทำเครื่องหมายในเซลล์ทั้งหมดใน ช่วง false หากไม่ได้เลือกช่องทำเครื่องหมายในเซลล์ทั้งหมดใน ช่วง หรือ null หากไม่ได้เลือกช่องทำเครื่องหมายในเซลล์ใดเซลล์หนึ่ง หรือไม่มี การตรวจสอบข้อมูลช่องทำเครื่องหมาย

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

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

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

isEndColumnBounded()

กำหนดว่าจุดสิ้นสุดของช่วงจะผูกกับคอลัมน์ใดคอลัมน์หนึ่งหรือไม่ เช่น สำหรับช่วง A1:B10 หรือ B:B ซึ่งเชื่อมโยงกับคอลัมน์ที่ส่วนท้ายของช่วง เมธอดนี้จะแสดงผล true สำหรับช่วง 3:7 หรือ A1:5 ซึ่งเชื่อมโยงกับแถวที่เฉพาะเจาะจงที่ส่วนท้ายของช่วงเท่านั้น เมธอดนี้จะแสดงผล 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Determines if the end of the range is bound to a particular column and logs
// it to the console.
console.log(range.isEndColumnBounded());

รีเทิร์น

Booleantrue หากจุดสิ้นสุดของช่วงเชื่อมโยงกับคอลัมน์ใดคอลัมน์หนึ่ง false ไม่เช่นนั้น

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

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

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

isEndRowBounded()

กำหนดว่าจุดสิ้นสุดของช่วงจะเชื่อมโยงกับแถวใดแถวหนึ่งหรือไม่ เช่น สำหรับช่วง A1:B10 หรือ 3:7 ซึ่งเชื่อมโยงกับแถวที่ส่วนท้ายของช่วง เมธอดนี้จะแสดงผล true สำหรับช่วง B:B หรือ A1:C ซึ่งเชื่อมโยงกับคอลัมน์ที่เฉพาะเจาะจงที่ส่วนท้ายของช่วงเท่านั้น เมธอดนี้จะแสดงผล 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Determines if the end of the range is bound to a particular row and logs it
// to the console.
console.log(range.isEndRowBounded());

รีเทิร์น

Booleantrue หากจุดสิ้นสุดของช่วงเชื่อมโยงกับแถวใดแถวหนึ่ง false ไม่เช่นนั้น

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

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

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

isPartOfMerge()

แสดงผล true หากเซลล์ในช่วงปัจจุบันทับซ้อนกับเซลล์ที่ผสาน

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

const range = sheet.getRange('A1:B3');

// True if any of the cells in A1:B3 is included in a merge.
const isPartOfMerge = range.isPartOfMerge();

รีเทิร์น

Booleantrue หากช่วงทับซ้อนกับเซลล์ที่ผสานใดๆ ไม่เช่นนั้นจะแสดงผล false


isStartColumnBounded()

กำหนดว่าจุดเริ่มต้นของช่วงจะเชื่อมโยงกับคอลัมน์ใดคอลัมน์หนึ่งหรือไม่ เช่น สำหรับช่วง A1:B10 หรือ B:B ซึ่งเชื่อมโยงกับคอลัมน์ที่จุดเริ่มต้นของช่วง เมธอดนี้จะแสดงผล true สำหรับช่วง 3:7 ซึ่งเชื่อมโยงกับแถวที่จุดเริ่มต้นของช่วงเท่านั้น เมธอดนี้จะแสดงผล 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Determines if the start of the range is bound to a particular column and logs
// it to the console.
console.log(range.isStartColumnBounded());

รีเทิร์น

Booleantrue หากจุดเริ่มต้นของช่วงเชื่อมโยงกับคอลัมน์ใดคอลัมน์หนึ่ง false ในกรณีอื่นๆ

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

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

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

isStartRowBounded()

กำหนดว่าจุดเริ่มต้นของช่วงจะเชื่อมโยงกับแถวใดแถวหนึ่งหรือไม่ เช่น สำหรับช่วง A1:B10 หรือ 3:7 ซึ่งเชื่อมโยงกับแถวที่จุดเริ่มต้นของช่วง วิธีนี้จะแสดงผล true สำหรับช่วง B:B ซึ่งเชื่อมโยงกับคอลัมน์ใดคอลัมน์หนึ่งที่จุดเริ่มต้นของช่วงเท่านั้น วิธีนี้จะแสดงผล 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');

// Determines if the start of the range is bound to a particular row and logs it
// to the console.
console.log(range.isStartRowBounded());

รีเทิร์น

Booleantrue หากจุดเริ่มต้นของช่วงเชื่อมโยงกับแถวใดแถวหนึ่ง false ไม่เช่นนั้น

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

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

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

merge()

ผสานเซลล์ในช่วงเข้าด้วยกันเป็นบล็อกเดียว

const sheet = SpreadsheetApp.getActiveSheet();

// The code below 2-dimensionally merges the cells in A1 to B3
sheet.getRange('A1:B3').merge();

รีเทิร์น

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

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

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

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

mergeAcross()

ผสานเซลล์ในช่วงในคอลัมน์ของช่วง

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

// The code below merges cells C5:E5 into one cell
const range1 = sheet.getRange('C5:E5');
range1.mergeAcross();

// The code below creates 2 horizontal cells, F5:H5 and F6:H6
const range2 = sheet.getRange('F5:H6');
range2.mergeAcross();

รีเทิร์น

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

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

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

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

mergeVertically()

ผสานเซลล์ในช่วงเข้าด้วยกัน

const sheet = SpreadsheetApp.getActiveSheet();

// The code below vertically merges the cells in A1 to A10
sheet.getRange('A1:A10').mergeVertically();

// The code below creates 3 merged columns: B1 to B10, C1 to C10, and D1 to D10
sheet.getRange('B1:D10').mergeVertically();

รีเทิร์น

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

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

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

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

moveTo(target)

ตัดและวาง (ทั้งรูปแบบและค่า) จากช่วงนี้ไปยังช่วงเป้าหมาย

// The code below moves the first 5 columns over to the 6th column
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange('A1:E').moveTo(sheet.getRange('F1'));

พารามิเตอร์

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

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

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

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

offset(rowOffset, columnOffset)

แสดงผลช่วงใหม่ที่ออฟเซ็ตจากช่วงนี้ตามจำนวนแถวและคอลัมน์ที่ระบุ (ซึ่งอาจเป็นค่าลบ) ช่วงใหม่มีขนาดเท่ากับช่วงเดิม

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

const cell = sheet.getRange('A1');

// newCell references B2
const newCell = cell.offset(1, 1);

พารามิเตอร์

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

รีเทิร์น

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


offset(rowOffset, columnOffset, numRows)

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

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

const cell = sheet.getRange('A1');

// newCell references B2:B3
const newRange = cell.offset(1, 1, 2);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowOffsetIntegerจำนวนแถวที่ลงมาจากเซลล์ซ้ายบนของช่วง ค่าลบ แสดงถึงแถวที่ขึ้นมาจากเซลล์ซ้ายบนของช่วง
columnOffsetIntegerจำนวนคอลัมน์ทางด้านขวาของเซลล์ซ้ายบนของช่วง ค่าลบ แสดงถึงคอลัมน์ทางด้านซ้ายของเซลล์ซ้ายบนของช่วง
numRowsIntegerความสูงในแถวของช่วงใหม่

รีเทิร์น

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


offset(rowOffset, columnOffset, numRows, numColumns)

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

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

const cell = sheet.getRange('A1');

// newCell references B2:C3
const newRange = cell.offset(1, 1, 2, 2);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rowOffsetIntegerจำนวนแถวที่ลงมาจากเซลล์ซ้ายบนของช่วง ค่าลบ แสดงถึงแถวที่ขึ้นมาจากเซลล์ซ้ายบนของช่วง
columnOffsetIntegerจำนวนคอลัมน์ทางด้านขวาของเซลล์ซ้ายบนของช่วง ค่าลบ แสดงถึงคอลัมน์ทางด้านซ้ายของเซลล์ซ้ายบนของช่วง
numRowsIntegerความสูงในแถวของช่วงใหม่
numColumnsIntegerความกว้างของช่วงใหม่ในคอลัมน์

รีเทิร์น

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


protect()

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

// Protect range A1:B10, then remove all other users from the list of editors.
const ss = SpreadsheetApp.getActive();
const range = ss.getRange('A1:B10');
const protection = range.protect().setDescription('Sample protected range');

// 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

randomize()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:C7');

// Randomizes the range
range.randomize();

รีเทิร์น

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

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

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

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

removeCheckboxes()

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

const range = SpreadsheetApp.getActive().getRange('A1:B10');

// Inserts checkboxes and sets each cell value to 'no' in the range A1:B10.
range.insertCheckboxes('yes', 'no');

const range1 = SpreadsheetApp.getActive().getRange('A1');
range1.setValue('yes');
// Removes the checkbox data validation in cell A1 and clears its value.
range1.removeCheckboxes();

const range2 = SpreadsheetApp.getActive().getRange('A2');
range2.setValue('random');
// Removes the checkbox data validation in cell A2 but does not clear its value.
range2.removeCheckboxes();

รีเทิร์น

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

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

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

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

removeDuplicates()

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B1:D7');

// Remove duplicate rows in the range.
range.removeDuplicates();

รีเทิร์น

Range — ช่วงที่ได้หลังจากการนำรายการที่ซ้ำกันออก ขนาดของช่วงจะลดลง 1 แถวสำหรับทุกแถวที่นำออก

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

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

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

removeDuplicates(columnsToCompare)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B1:D7');

// Remove rows which have duplicate values in column B.
range.removeDuplicates([2]);

// Remove rows which have duplicate values in both columns B and D.
range.removeDuplicates([2, 4]);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
columnsToCompareInteger[]คอลัมน์ที่จะวิเคราะห์ค่าที่ซ้ำกัน หากไม่ได้ระบุคอลัมน์ ระบบจะวิเคราะห์คอลัมน์ทั้งหมดเพื่อหาข้อมูลที่ซ้ำกัน

รีเทิร์น

Range — ช่วงที่ได้หลังจากการนำรายการที่ซ้ำกันออก ขนาดของช่วงจะลดลง 1 แถวสำหรับทุกแถวที่นำออก

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

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

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

setBackground(color)

ตั้งค่าสีพื้นหลังของเซลล์ทั้งหมดในช่วงในรูปแบบ CSS (เช่น '#ffffff' หรือ 'white')

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

const range = sheet.getRange('B2:D5');
range.setBackground('red');

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

setBackgroundObject(color)

ตั้งค่าสีพื้นหลังของเซลล์ทั้งหมดในช่วง

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const bgColor = SpreadsheetApp.newColor()
                    .setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND)
                    .build();

const range = sheet.getRange('B2:D5');
range.setBackgroundObject(bgColor);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorColorสีพื้นหลังที่จะตั้งค่า null ค่าจะรีเซ็ตสีพื้นหลัง

รีเทิร์น

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

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

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

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

setBackgroundObjects(color)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของสีพื้นหลัง (ต้องตรงกับมิติข้อมูลของช่วงนี้)

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

const colorAccent1 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)
                         .build();
const colorAccent2 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)
                         .build();
const colorAccent3 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)
                         .build();
const colorAccent4 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT4)
                         .build();

const colors = [
  [colorAccent1, colorAccent2],
  [colorAccent3, colorAccent4],
];

const cell = sheet.getRange('B5:C6');
cell.setBackgroundObjects(colors);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorColor[][]อาร์เรย์ของสีแบบ 2 มิติ ค่า null จะรีเซ็ตสี

รีเทิร์น

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

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

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

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

setBackgroundRGB(red, green, blue)

ตั้งค่าพื้นหลังเป็นสีที่ระบุโดยใช้ค่า RGB (จำนวนเต็มระหว่าง 0 ถึง 255 รวม)

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

const cell = sheet.getRange('B2');

// Sets the background to white
cell.setBackgroundRGB(255, 255, 255);

// Sets the background to red
cell.setBackgroundRGB(255, 0, 0);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
redIntegerค่าสีแดงในสัญกรณ์ RGB
greenIntegerค่าสีเขียวในสัญกรณ์ RGB
blueIntegerค่าสีน้ำเงินในสัญกรณ์ RGB

รีเทิร์น

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

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

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

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

setBackgrounds(color)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของสีพื้นหลัง (ต้องตรงกับมิติข้อมูลของช่วงนี้) สี อยู่ในรูปแบบ CSS (เช่น '#ffffff' หรือ 'white')

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

const colors = [
  ['red', 'white', 'blue'],
  ['#FF0000', '#FFFFFF', '#0000FF'],  // These are the hex equivalents
];

const cell = sheet.getRange('B5:D6');
cell.setBackgrounds(colors);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorString[][]อาร์เรย์ 2 มิติของสีในรูปแบบ CSS (เช่น '#ffffff' หรือ 'white') ค่า null จะรีเซ็ตสี

รีเทิร์น

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

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

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

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

setBorder(top, left, bottom, right, vertical, horizontal)

ตั้งค่าพร็อพเพอร์ตี้เส้นขอบ ค่าที่ใช้ได้คือ true (เปิด), false (ปิด) และ null (ไม่มีการเปลี่ยนแปลง)

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

const cell = sheet.getRange('B2');
// Sets borders on the top and bottom, but leaves the left and right unchanged
cell.setBorder(true, null, true, null, false, false);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
topBooleantrue สำหรับเส้นขอบ false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง
leftBooleantrue สำหรับเส้นขอบ false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง
bottomBooleantrue สำหรับเส้นขอบ false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง
rightBooleantrue สำหรับเส้นขอบ false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง
verticalBooleantrue สำหรับเส้นขอบแนวตั้งภายใน false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง
horizontalBooleantrue สำหรับเส้นขอบแนวนอนภายใน false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง

รีเทิร์น

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

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

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

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

setBorder(top, left, bottom, right, vertical, horizontal, color, style)

ตั้งค่าพร็อพเพอร์ตี้เส้นขอบด้วยสีและ/หรือรูปแบบ ค่าที่ใช้ได้คือ true (เปิด), false (ปิด) และ null (ไม่มีการเปลี่ยนแปลง) สำหรับสี ให้ใช้สัญกรณ์สีใน CSS (เช่น '#ffffff' หรือ 'white')

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

const cell = sheet.getRange('B2');
// Sets borders on the top and bottom, but leaves the left and right unchanged
// Also sets the color to "red", and the border to "DASHED".
cell.setBorder(
    true,
    null,
    true,
    null,
    false,
    false,
    'red',
    SpreadsheetApp.BorderStyle.DASHED,
);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
topBooleantrue สำหรับเส้นขอบ false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง
leftBooleantrue สำหรับเส้นขอบ false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง
bottomBooleantrue สำหรับเส้นขอบ false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง
rightBooleantrue สำหรับเส้นขอบ false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง
verticalBooleantrue สำหรับเส้นขอบแนวตั้งภายใน false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง
horizontalBooleantrue สำหรับเส้นขอบแนวนอนภายใน false สำหรับไม่มี null สำหรับไม่มีการเปลี่ยนแปลง
colorStringสีในรูปแบบ CSS (เช่น '#ffffff' หรือ 'white'), null สำหรับสีเริ่มต้น (สีดำ)
styleBorderStyleรูปแบบสำหรับเส้นขอบ null สำหรับรูปแบบเริ่มต้น (ทึบ)

รีเทิร์น

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

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

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

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

setDataValidation(rule)

ตั้งกฎการตรวจสอบข้อมูล 1 กฎสำหรับเซลล์ทั้งหมดในช่วง

// Set the data validation rule for cell A1 to require a value from B1:B10.
const cell = SpreadsheetApp.getActive().getRange('A1');
const range = SpreadsheetApp.getActive().getRange('B1:B10');
const rule =
    SpreadsheetApp.newDataValidation().requireValueInRange(range).build();
cell.setDataValidation(rule);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
ruleDataValidationกฎการตรวจสอบข้อมูลที่จะตั้งค่า หรือ null เพื่อนำการตรวจสอบข้อมูลออก

รีเทิร์น

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

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

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

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

setDataValidations(rules)

ตั้งค่ากฎการตรวจสอบข้อมูลสำหรับเซลล์ทั้งหมดในช่วง เมธอดนี้ใช้อาร์เรย์การตรวจสอบข้อมูลแบบ 2 มิติ ซึ่งจัดทำดัชนีตามแถวแล้วจึงตามคอลัมน์ มิติข้อมูลของอาร์เรย์ต้องสอดคล้องกับมิติข้อมูลของช่วง

// Set the data validation rules for Sheet1!A1:B5 to require a value from
// Sheet2!A1:A10.
const destinationRange =
    SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange('A1:B5');
const sourceRange =
    SpreadsheetApp.getActive().getSheetByName('Sheet2').getRange('A1:A10');
const rule =
    SpreadsheetApp.newDataValidation().requireValueInRange(sourceRange).build();
const rules = destinationRange.getDataValidations();
for (let i = 0; i < rules.length; i++) {
  for (let j = 0; j < rules[i].length; j++) {
    rules[i][j] = rule;
  }
}
destinationRange.setDataValidations(rules);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rulesDataValidation[][]อาร์เรย์ 2 มิติของกฎการตรวจสอบข้อมูลที่จะตั้งค่า null ค่า จะนำการตรวจสอบข้อมูลออก

รีเทิร์น

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

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

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

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

setFontColor(color)

ตั้งค่าสีแบบอักษรในรูปแบบ CSS (เช่น '#ffffff' หรือ 'white')

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

const cell = sheet.getRange('B2');
cell.setFontColor('red');

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

setFontColorObject(color)

ตั้งค่าสีแบบอักษรของช่วงที่ระบุ

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const color = SpreadsheetApp.newColor()
                  .setThemeColor(SpreadsheetApp.ThemeColorType.TEXT)
                  .build();

const cell = sheet.getRange('B2');
cell.setFontColor(color);

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

setFontColorObjects(colors)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของสีแบบอักษร (ต้องตรงกับขนาดของช่วงนี้)

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

const colorAccent1 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)
                         .build();
const colorAccent2 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)
                         .build();
const colorAccent3 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)
                         .build();
const colorAccent4 = SpreadsheetApp.newColor()
                         .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT4)
                         .build();

const colors = [
  [colorAccent1, colorAccent2],
  [colorAccent3, colorAccent4],
];

const cell = sheet.getRange('B5:C6');
cell.setFontColorObjects(colors);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorsColor[][]อาร์เรย์สี 2 มิติ null ค่าจะรีเซ็ตสีแบบอักษร

รีเทิร์น

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

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

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

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

setFontColors(colors)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของสีแบบอักษร (ต้องตรงกับขนาดของช่วงนี้) สีอยู่ในรูปแบบ CSS (เช่น '#ffffff' หรือ 'white')

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

const colors = [
  ['red', 'white', 'blue'],
  ['#FF0000', '#FFFFFF', '#0000FF'],  // These are the hex equivalents
];

const cell = sheet.getRange('B5:D6');
cell.setFontColors(colors);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorsObject[][]อาร์เรย์ 2 มิติของสีในรูปแบบ CSS (เช่น '#ffffff' หรือ 'white') ค่า null จะรีเซ็ตสี

รีเทิร์น

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

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

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

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

setFontFamilies(fontFamilies)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของชุดแบบอักษร (ต้องตรงกับขนาดของช่วงนี้) ตัวอย่างตระกูลฟอนต์ ได้แก่ "Arial" หรือ "Helvetica"

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

const fonts = [
  ['Arial', 'Helvetica', 'Verdana'],
  ['Courier New', 'Arial', 'Helvetica'],
];

const cell = sheet.getRange('B2:D3');
cell.setFontFamilies(fonts);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
fontFamiliesObject[][]อาร์เรย์สองมิติของชุดแบบอักษร null ค่าจะรีเซ็ต ชุดแบบอักษร

รีเทิร์น

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

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

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

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

setFontFamily(fontFamily)

ตั้งค่าชุดแบบอักษร เช่น "Arial" หรือ "Helvetica"

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

const cell = sheet.getRange('B2');
cell.setFontFamily('Helvetica');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
fontFamilyStringชุดแบบอักษรที่จะตั้งค่า ค่า null จะรีเซ็ตชุดแบบอักษร

รีเทิร์น

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

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

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

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

setFontLine(fontLine)

ตั้งค่ารูปแบบเส้นของแบบอักษรในช่วงที่ระบุ ('underline', 'line-through' หรือ 'none')

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

const cell = sheet.getRange('B2');
cell.setFontLine('line-through');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
fontLineStringรูปแบบเส้นแบบอักษร ซึ่งอาจเป็น 'underline', 'line-through' หรือ 'none' ค่า null จะรีเซ็ตรูปแบบเส้นแบบอักษร

รีเทิร์น

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

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

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

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

setFontLines(fontLines)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของรูปแบบเส้น (ต้องตรงกับขนาดของช่วงนี้)

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

// The size of the two-dimensional array must match the size of the range.
const fontLines = [['underline', 'line-through', 'none']];

const range = sheet.getRange('B2:D2');
range.setFontLines(fontLines);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
fontLinesObject[][]อาร์เรย์ 2 มิติของรูปแบบเส้นแบบอักษร ('underline', 'line-through' หรือ 'none'); ค่า null จะรีเซ็ตรูปแบบเส้นแบบอักษร

รีเทิร์น

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

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

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

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

setFontSize(size)

กำหนดขนาดแบบอักษร โดยขนาดคือขนาดจุดที่จะใช้

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

const cell = sheet.getRange('B2');
cell.setFontSize(20);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sizeIntegerขนาดแบบอักษรในหน่วยพอยต์

รีเทิร์น

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

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

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

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

setFontSizes(sizes)

กำหนดตารางกริดสี่เหลี่ยมของขนาดแบบอักษร (ต้องตรงกับมิติข้อมูลของช่วงนี้) ขนาดมีหน่วยเป็น พอยต์

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

// The size of the two-dimensional array must match the size of the range.
const fontSizes = [[16, 20, 24]];

const range = sheet.getRange('B2:D2');
range.setFontSizes(fontSizes);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
sizesObject[][]อาร์เรย์ 2 มิติของขนาด

รีเทิร์น

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

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

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

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

setFontStyle(fontStyle)

กำหนดรูปแบบแบบอักษรสำหรับช่วงที่ระบุ ('italic' หรือ 'normal')

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

const cell = sheet.getRange('B2');
cell.setFontStyle('italic');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
fontStyleStringรูปแบบแบบอักษร ไม่ว่าจะเป็น 'italic' หรือ 'normal' ค่า null จะรีเซ็ตรูปแบบแบบอักษร

รีเทิร์น

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

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

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

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

setFontStyles(fontStyles)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของรูปแบบแบบอักษร (ต้องตรงกับขนาดของช่วงนี้)

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

// The size of the two-dimensional array must match the size of the range.
const fontStyles = [['italic', 'normal']];

const range = sheet.getRange('B2:C2');
range.setFontStyles(fontStyles);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
fontStylesObject[][]อาร์เรย์สองมิติของรูปแบบแบบอักษร ซึ่งอาจเป็น 'italic' หรือ 'normal' ค่า null จะรีเซ็ตรูปแบบแบบอักษร

รีเทิร์น

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

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

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

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

setFontWeight(fontWeight)

กำหนดความหนาของแบบอักษรสำหรับช่วงที่ระบุ (ปกติ/หนา)

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

const cell = sheet.getRange('B2');
cell.setFontWeight('bold');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
fontWeightStringน้ำหนักแบบอักษร ซึ่งอาจเป็น 'bold' หรือ 'normal' ค่า null จะรีเซ็ตน้ำหนักแบบอักษร

รีเทิร์น

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

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

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

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

setFontWeights(fontWeights)

กำหนดตารางกริดสี่เหลี่ยมของความหนาแบบอักษร (ต้องตรงกับมิติข้อมูลของช่วงนี้) ตัวอย่าง ความหนาของแบบอักษรคือ "bold"

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

// The size of the two-dimensional array must match the size of the range.
const fontStyles = [['bold', 'bold', 'normal']];

const range = sheet.getRange('B2:D2');
range.setFontWeights(fontStyles);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
fontWeightsObject[][]อาร์เรย์สองมิติของน้ำหนักแบบอักษร ซึ่งอาจเป็น 'bold' หรือ 'normal' ค่า null จะรีเซ็ตน้ำหนักแบบอักษร

รีเทิร์น

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

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

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

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

setFormula(formula)

อัปเดตสูตรสำหรับช่วงนี้ สูตรที่ระบุต้องอยู่ในรูปแบบ A1

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

const cell = sheet.getRange('B5');
cell.setFormula('=SUM(B3:B4)');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
formulaStringสตริงที่แสดงสูตรที่จะตั้งค่าสำหรับเซลล์

รีเทิร์น

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

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

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

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

setFormulaR1C1(formula)

อัปเดตสูตรสำหรับช่วงนี้ สูตรที่ระบุต้องอยู่ในรูปแบบ R1C1

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

const cell = sheet.getRange('B5');
// This sets the formula to be the sum of the 3 rows above B5
cell.setFormulaR1C1('=SUM(R[-3]C[0]:R[-1]C[0])');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
formulaStringสูตรสตริง

รีเทิร์น

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

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

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

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

setFormulas(formulas)

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

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

// This sets the formulas to be a row of sums, followed by a row of averages
// right below. The size of the two-dimensional array must match the size of the
// range.
const formulas = [
  ['=SUM(B2:B4)', '=SUM(C2:C4)', '=SUM(D2:D4)'],
  ['=AVERAGE(B2:B4)', '=AVERAGE(C2:C4)', '=AVERAGE(D2:D4)'],
];

const cell = sheet.getRange('B5:D6');
cell.setFormulas(formulas);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
formulasString[][]อาร์เรย์สตริง 2 มิติของสูตร

รีเทิร์น

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

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

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

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

setFormulasR1C1(formulas)

ตั้งค่าตารางสูตรสี่เหลี่ยมผืนผ้า (ต้องตรงกับมิติข้อมูลของช่วงนี้) สูตรที่ระบุ ต้องอยู่ในรูปแบบ R1C1

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

// This creates formulas for a row of sums, followed by a row of averages.
const sumOfRowsAbove = '=SUM(R[-3]C[0]:R[-1]C[0])';
const averageOfRowsAbove = '=AVERAGE(R[-4]C[0]:R[-2]C[0])';

// The size of the two-dimensional array must match the size of the range.
const formulas = [
  [sumOfRowsAbove, sumOfRowsAbove, sumOfRowsAbove],
  [averageOfRowsAbove, averageOfRowsAbove, averageOfRowsAbove],
];

const cell = sheet.getRange('B5:D6');
// This sets the formula to be the sum of the 3 rows above B5.
cell.setFormulasR1C1(formulas);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
formulasString[][]อาร์เรย์ 2 มิติของสูตรในรูปแบบ R1C1

รีเทิร์น

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

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

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

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

setHorizontalAlignment(alignment)

ตั้งค่าการจัดแนวแนวนอน (จากซ้ายไปขวา) สำหรับช่วงที่ระบุ (ซ้าย/กึ่งกลาง/ขวา)

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

const cell = sheet.getRange('B2');
cell.setHorizontalAlignment('center');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
alignmentStringการจัดแนวเป็น 'left', 'center' หรือ 'normal' ค่า null จะรีเซ็ตการจัดแนว

รีเทิร์น

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

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

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

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

setHorizontalAlignments(alignments)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของการจัดแนวนอน ดู setHorizontalAlignment(alignment)

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

// The size of the two-dimensional array must match the size of the range.
const horizontalAlignments = [['left', 'right', 'center']];

const range = sheet.getRange('B2:D2');
range.setHorizontalAlignments(horizontalAlignments);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
alignmentsObject[][]อาร์เรย์ 2 มิติของการจัดแนว ไม่ว่าจะเป็น 'left', 'center' หรือ 'normal' ค่า null จะรีเซ็ตการจัดแนว

รีเทิร์น

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

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

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

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

ดูเพิ่มเติม


setNote(note)

ตั้งค่าโน้ตเป็นค่าที่ระบุ

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

const cell = sheet.getRange('B2');
cell.setNote('This is a note');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
noteStringค่าโน้ตที่จะตั้งค่าสำหรับช่วง โดยค่า null จะนำโน้ตออก

รีเทิร์น

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

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

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

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

setNotes(notes)

ตั้งค่าตารางโน้ตสี่เหลี่ยมผืนผ้า (ต้องตรงกับขนาดของช่วงนี้)

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

// The size of the two-dimensional array must match the size of the range.
const notes = [
  ['it goes', 'like this', 'the fourth, the fifth'],
  ['the minor fall', 'and the', 'major lift'],
];

const cell = sheet.getRange('B2:D3');
cell.setNotes(notes);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
notesObject[][]อาร์เรย์โน้ต 2 มิติ null ค่าจะนำโน้ตออก

รีเทิร์น

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

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

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

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

ดูเพิ่มเติม


setNumberFormat(numberFormat)

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

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

const cell = sheet.getRange('B2');
// Always show 3 decimal points
cell.setNumberFormat('0.000');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
numberFormatStringสตริงรูปแบบตัวเลข

รีเทิร์น

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

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

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

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

setNumberFormats(numberFormats)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของรูปแบบตัวเลขหรือวันที่ (ต้องตรงกับมิติข้อมูลของช่วงนี้) ค่าคือสตริงรูปแบบค่าตามที่อธิบายไว้ใน เอกสารประกอบเกี่ยวกับ Sheets API

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

// The size of the two-dimensional array must match the size of the range.
const formats = [['0.000', '0,000,000', '$0.00']];

const range = sheet.getRange('B2:D2');
range.setNumberFormats(formats);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
numberFormatsObject[][]อาร์เรย์สองมิติของรูปแบบตัวเลข

รีเทิร์น

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

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

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

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

setRichTextValue(value)

กำหนดค่าข้อความที่มีรูปแบบสำหรับเซลล์ในช่วง

// Sets all cells in range B2:D4 to have the text "Hello world", with "Hello"
// bolded.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const richText = SpreadsheetApp.newRichTextValue()
                     .setText('Hello world')
                     .setTextStyle(0, 5, bold)
                     .build();
range.setRichTextValue(richText);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
valueRichTextValueค่าข้อความที่มีรูปแบบที่ต้องการ

รีเทิร์น

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

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

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

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

setRichTextValues(values)

ตั้งค่าตารางสี่เหลี่ยมของค่าข้อความที่มีรูปแบบ

// Sets the cells in range A1:A2 to have Rich Text values.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('A1:A2');
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const italic = SpreadsheetApp.newTextStyle().setItalic(true).build();
const richTextA1 = SpreadsheetApp.newRichTextValue()
                       .setText('This cell is bold')
                       .setTextStyle(bold)
                       .build();
const richTextA2 = SpreadsheetApp.newRichTextValue()
                       .setText('bold words, italic words')
                       .setTextStyle(0, 11, bold)
                       .setTextStyle(12, 24, italic)
                       .build();
range.setRichTextValues([[richTextA1], [richTextA2]]);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
valuesRichTextValue[][]ค่า Rich Text ที่ต้องการ

รีเทิร์น

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

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

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

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

ตั้งค่าว่าจะให้ช่วงแสดงไฮเปอร์ลิงก์หรือไม่

// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');

// Gets cell A30 and sets its hyperlink value.
const range = sheet.getRange('A30');
range.setValue('https://www.example.com');

// Sets cell A30 to show hyperlinks.
range.setShowHyperlink(true);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
showHyperlinkBooleanจะแสดงไฮเปอร์ลิงก์หรือไม่

รีเทิร์น

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

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

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

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

setTextDirection(direction)

ตั้งค่าทิศทางข้อความสำหรับเซลล์ในช่วง หากทิศทางที่ระบุคือ null ระบบจะอนุมานทิศทางแล้วตั้งค่า

// Sets right-to-left text direction for the range.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
range.setTextDirection(SpreadsheetApp.TextDirection.RIGHT_TO_LEFT);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
directionTextDirectionทิศทางข้อความที่ต้องการ หากnullมีการอนุมานทิศทางก่อน การตั้งค่า

รีเทิร์น

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

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

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

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

setTextDirections(directions)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของทิศทางข้อความ หากทิศทางที่ระบุคือ null ระบบจะอนุมานทิศทางแล้วตั้งค่า

// Copies all of the text directions from range A1:B2 over to range C5:D6.
const sheet = SpreadsheetApp.getActiveSheet();
const range1 = sheet.getRange('A1:B2');
const range2 = sheet.getRange('C5:D6');

range2.setTextRotations(range1.getTextDirections());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
directionsTextDirection[][]ทิศทางข้อความที่ต้องการ หากทิศทางที่ระบุเป็น null ระบบจะอนุมานก่อนตั้งค่า

รีเทิร์น

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

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

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

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

setTextRotation(degrees)

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

สำหรับทิศทางข้อความจากซ้ายไปขวา มุมบวกจะอยู่ในทิศทางทวนเข็มนาฬิกา ในขณะที่สำหรับทิศทางข้อความจากขวาไปซ้าย มุมบวกจะอยู่ในทิศทางตามเข็มนาฬิกา

// Sets all cell's in range B2:D4 to have text rotated up 45 degrees.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');

range.setTextRotation(45);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
degreesIntegerมุมที่ต้องการระหว่างการวางแนวมาตรฐานกับการวางแนวที่ต้องการ สำหรับข้อความจากซ้ายไปขวา มุมที่เป็นบวกจะอยู่ในทิศทางทวนเข็มนาฬิกา

รีเทิร์น

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

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

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

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

setTextRotation(rotation)

ตั้งค่าการหมุนข้อความสำหรับเซลล์ในช่วง

// Sets all cell's in range B2:D4 to have the same text rotation settings as
// cell A1.
const sheet = SpreadsheetApp.getActiveSheet();

const rotation = sheet.getRange('A1').getTextRotation();

sheet.getRange('B2:D4').setTextRotation(rotation);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rotationTextRotationการตั้งค่าการหมุนข้อความที่ต้องการ

รีเทิร์น

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

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

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

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

setTextRotations(rotations)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของการหมุนข้อความ

// Copies all of the text rotations from range A1:B2 over to range C5:D6.
const sheet = SpreadsheetApp.getActiveSheet();
const range1 = sheet.getRange('A1:B2');
const range2 = sheet.getRange('C5:D6');

range2.setTextRotations(range1.getTextRotations());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
rotationsTextRotation[][]การตั้งค่าการหมุนข้อความที่ต้องการ

รีเทิร์น

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

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

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

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

setTextStyle(style)

ตั้งค่ารูปแบบข้อความสำหรับเซลล์ในช่วง

// Sets the cells in range C5:D6 to have underlined size 15 font.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('C5:D6');
const style =
    SpreadsheetApp.newTextStyle().setFontSize(15).setUnderline(true).build();
range.setTextStyle(style);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
styleTextStyleรูปแบบข้อความที่ต้องการ

รีเทิร์น

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

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

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

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

setTextStyles(styles)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของรูปแบบข้อความ

// Sets text styles for cells in range A1:B2
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('A1:B2');
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const otherStyle = SpreadsheetApp.newTextStyle()
                       .setBold(true)
                       .setUnderline(true)
                       .setItalic(true)
                       .setForegroundColor('#335522')
                       .setFontSize(44)
                       .build();
range.setTextStyles([
  [bold, otherStyle],
  [otherStyle, bold],
]);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
stylesTextStyle[][]รูปแบบข้อความที่ต้องการ

รีเทิร์น

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

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

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

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

setValue(value)

กำหนดค่าของช่วง ค่าอาจเป็นตัวเลข สตริง บูลีน หรือวันที่ หากขึ้นต้นด้วย '=' ระบบจะตีความว่าเป็นสูตร

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

const cell = sheet.getRange('B2');
cell.setValue(100);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
valueObjectค่าสำหรับช่วง

รีเทิร์น

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

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

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

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

setValues(values)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของค่า (ต้องตรงกับมิติข้อมูลของช่วงนี้) หากค่าขึ้นต้นด้วย = ระบบจะตีความค่าดังกล่าวเป็นสูตร

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

// The size of the two-dimensional array must match the size of the range.
const values = [['2.000', '1,000,000', '$2.99']];

const range = sheet.getRange('B2:D2');
range.setValues(values);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
valuesObject[][]อาร์เรย์ค่า 2 มิติ

รีเทิร์น

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

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

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

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

setVerticalAlignment(alignment)

ตั้งค่าการจัดแนวในแนวตั้ง (จากบนลงล่าง) สำหรับช่วงที่ระบุ (บน/กลาง/ล่าง)

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

const cell = sheet.getRange('B2');
cell.setVerticalAlignment('middle');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
alignmentStringการจัดแนวเป็น 'top', 'middle' หรือ 'bottom' ค่า null จะรีเซ็ตการจัดแนว

รีเทิร์น

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

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

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

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

setVerticalAlignments(alignments)

ตั้งค่าตารางสี่เหลี่ยมผืนผ้าของการจัดแนวตั้ง (ต้องตรงกับขนาดของช่วงนี้)

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

// The size of the two-dimensional array must match the size of the range.
const alignments = [['top', 'middle', 'bottom']];

const range = sheet.getRange('B2:D2');
range.setVerticalAlignments(alignments);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
alignmentsObject[][]อาร์เรย์ 2 มิติของการจัดแนว ไม่ว่าจะเป็น 'top', 'middle' หรือ 'bottom' ค่า null จะรีเซ็ตการจัดแนว

รีเทิร์น

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

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

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

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

ดูเพิ่มเติม


setVerticalText(isVertical)

กำหนดว่าจะซ้อนข้อความสำหรับเซลล์ในช่วงหรือไม่ หากข้อความซ้อนกัน ในแนวตั้ง ระบบจะไม่สนใจการตั้งค่าการหมุนข้อความตามองศา

// Sets all cell's in range B2:D4 to have vertically stacked text.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');

range.setVerticalText(true);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
isVerticalBooleanเลือกว่าจะซ้อนข้อความหรือไม่

รีเทิร์น

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

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

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

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

setWrap(isWrapEnabled)

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

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

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

const cell = sheet.getRange('B2');
cell.setWrap(true);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
isWrapEnabledBooleanว่าจะตัดข้อความหรือไม่

รีเทิร์น

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

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

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

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

setWrapStrategies(strategies)

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

// Copies all of the wrap strategies from range A1:B2 over to range C5:D6.
const sheet = SpreadsheetApp.getActiveSheet();
const range1 = sheet.getRange('A1:B2');
const range2 = sheet.getRange('C5:D6');

range2.setWrapStrategies(range1.getWrapStrategies());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
strategiesWrapStrategy[][]กลยุทธ์การตัดข้อความที่ต้องการ

รีเทิร์น

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

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

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

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

setWrapStrategy(strategy)

ตั้งค่ากลยุทธ์การตัดข้อความสำหรับเซลล์ในช่วง

// Sets all cells in range B2:D4 to use the clip wrap strategy.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');

range.setWrapStrategy(SpreadsheetApp.WrapStrategy.CLIP);

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

setWraps(isWrapEnabled)

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

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

// The size of the two-dimensional array must match the size of the range.
const wraps = [[true, true, false]];

const range = sheet.getRange('B2:D2');
range.setWraps(wraps);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
isWrapEnabledObject[][]อาร์เรย์ 2 มิติของตัวแปรการตัดข้อความที่กำหนดว่าจะตัด ข้อความในเซลล์หรือไม่

รีเทิร์น

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

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

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

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

ดูเพิ่มเติม


shiftColumnGroupDepth(delta)

เปลี่ยนความลึกของการจัดกลุ่มคอลัมน์ของช่วงตามจำนวนที่ระบุ

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

การดำเนินการนี้จะไม่มีผลเมื่อลดความลึกของกลุ่มต่ำกว่า 0 หรือสูงกว่า 8

หาก column group control position เป็น BEFORE ระบบจะแสดงข้อผิดพลาดเมื่อพยายามเปลี่ยน ความลึกของแถวแรก

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();

// The column grouping depth is increased by 1.
range.shiftColumnGroupDepth(1);

// The column grouping depth is decreased by 1.
range.shiftColumnGroupDepth(-1);

พารามิเตอร์

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

รีเทิร์น

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

การขว้าง

Error — เมื่อพยายามเปลี่ยนความลึกของคอลัมน์แรกเมื่อตำแหน่งควบคุมเป็น GroupControlTogglePosition.BEFORE

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

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

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

shiftRowGroupDepth(delta)

เปลี่ยนความลึกของการจัดกลุ่มแถวของช่วงตามจำนวนที่ระบุ

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

การดำเนินการนี้จะไม่มีผลเมื่อลดความลึกของกลุ่มต่ำกว่า 0 หรือสูงกว่า 8

หาก row group control position เป็น BEFORE ระบบจะแสดงข้อผิดพลาดเมื่อพยายามเปลี่ยน ความลึกของแถวแรก

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();

// The row grouping depth is increased by 1.
range.shiftRowGroupDepth(1);

// The row grouping depth is decreased by 1.
range.shiftRowGroupDepth(-1);

พารามิเตอร์

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

รีเทิร์น

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

การขว้าง

Error — เมื่อพยายามเปลี่ยนความลึกของแถวแรกเมื่อตำแหน่งการควบคุมเป็น GroupControlTogglePosition.BEFORE

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

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

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

sort(sortSpecObj)

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

const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:C7');

// Sorts by the values in the first column (A)
range.sort(1);

// Sorts by the values in the second column (B)
range.sort(2);

// Sorts descending by column B
range.sort({column: 2, ascending: false});

// Sorts descending by column B, then ascending by column A
// Note the use of an array
range.sort([
  {column: 2, ascending: false},
  {column: 1, ascending: true},
]);

// For rows that are sorted in ascending order, the "ascending" parameter is
// optional, and just an integer with the column can be used instead. Note that
// in general, keeping the sort specification consistent results in more
// readable code. You can express the earlier sort as:
range.sort([{column: 2, ascending: false}, 1]);

// Alternatively, if you want all columns to be in ascending order, you can use
// the following (this makes column 2 ascending)
range.sort([2, 1]);
// ... which is equivalent to
range.sort([
  {column: 2, ascending: true},
  {column: 1, ascending: true},
]);

พารามิเตอร์

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

รีเทิร์น

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

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

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

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

splitTextToColumns()

แยกคอลัมน์ข้อความออกเป็นหลายคอลัมน์ตามตัวคั่นที่ระบบตรวจหาโดยอัตโนมัติ

// A1:A3 has the following values:
//           A                  B                 C
// 1 |one,one,one      |                 |                 |
// 2 |two,two,two      |                 |                 |
// 3 |three,three,three|                 |                 |

const range = SpreadsheetApp.getActiveSheet().getRange('A1:A3');
range.splitTextToColumns();

// Result after splitting the text to columns:
//           A                  B                 C
// 1 |one              |one              |one              |
// 2 |two              |two              |two              |
// 3 |three            |three            |three            |

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

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

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

splitTextToColumns(delimiter)

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

// A1:A3 has the following values:
//           A                  B                 C
// 1 |one#one#one      |                 |                 |
// 2 |two#two#two      |                 |                 |
// 3 |three#three#three|                 |                 |

const range = SpreadsheetApp.getActiveSheet().getRange('A1:A3');
range.splitTextToColumns('#');

// Result after splitting the text to columns:
//           A                  B                 C
// 1 |one              |one              |one              |
// 2 |two              |two              |two              |
// 3 |three            |three            |three            |

พารามิเตอร์

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

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

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

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

splitTextToColumns(delimiter)

แยกคอลัมน์ข้อความออกเป็นหลายคอลัมน์ตามตัวคั่นที่ระบุ

// A1:A3 has the following values:
//           A                  B                 C
// 1 |one;one;one      |                 |                 |
// 2 |two;two;two      |                 |                 |
// 3 |three;three;three|                 |                 |

const range = SpreadsheetApp.getActiveSheet().getRange('A1:A3');
range.splitTextToColumns(SpreadsheetApp.TextToColumnsDelimiter.SEMICOLON);

// Result after splitting the text to columns:
//           A                  B                 C
// 1 |one              |one              |one              |
// 2 |two              |two              |two              |
// 3 |three            |three            |three            |

พารามิเตอร์

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

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

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

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

trimWhitespace()

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

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getRange('A1:A4');
range.activate();
range.setValues([
  ' preceding space',
  'following space ',
  'two  middle  spaces',
  '   =SUM(1,2)',
]);

range.trimWhitespace();

const values = range.getValues();
// Values are ['preceding space', 'following space', 'two middle spaces',
// '=SUM(1,2)']

รีเทิร์น

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

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

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

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

uncheck()

เปลี่ยนสถานะของช่องทำเครื่องหมายในช่วงเป็น "ไม่ได้เลือก" ระบบจะละเว้นเซลล์ในช่วง ซึ่งปัจจุบันไม่มีค่าที่เลือกหรือไม่ได้เลือกที่กำหนดค่าไว้

// Changes the state of cells which currently contain either the checked or
// unchecked value configured in the range A1:B10 to 'unchecked'.
const range = SpreadsheetApp.getActive().getRange('A1:B10');
range.uncheck();

รีเทิร์น

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

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

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

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

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