เข้าถึงและแก้ไขชีตในสเปรดชีต การดำเนินการทั่วไป ได้แก่ การเปลี่ยนชื่อชีตและการเข้าถึงออบเจ็กต์ช่วง จากชีต
เมธอด
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
---|---|---|
activate() | Sheet | เปิดใช้งานชีตนี้ |
add | Sheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ที่ระบุลงในชีต |
add | Sheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์และการเปิดเผยที่ระบุลงในชีต |
add | Sheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์และค่าที่ระบุลงในชีต |
add | Sheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ ค่า และระดับการเข้าถึงที่ระบุลงในชีต |
append | Sheet | เพิ่มแถวที่ด้านล่างของเขตข้อมูลปัจจุบันในชีต |
as | Data | แสดงผลชีตเป็น Data หากชีตเป็นประเภท Sheet หรือ null ในกรณีอื่นๆ |
auto | Sheet | ตั้งค่าความกว้างของคอลัมน์ที่ระบุให้พอดีกับเนื้อหา |
auto | Sheet | กำหนดความกว้างของคอลัมน์ทั้งหมดโดยเริ่มที่ตำแหน่งคอลัมน์ที่ระบุเพื่อให้พอดีกับเนื้อหา |
auto | Sheet | กำหนดความสูงของแถวทั้งหมดโดยเริ่มที่ตำแหน่งแถวที่ระบุเพื่อให้พอดีกับเนื้อหา |
clear() | Sheet | ล้างข้อมูลเนื้อหาและการจัดรูปแบบในชีต |
clear(options) | Sheet | ล้างเนื้อหาและ/หรือรูปแบบของชีตตามที่ระบุด้วยตัวเลือกขั้นสูงที่กำหนด |
clear | void | นํากฎรูปแบบตามเงื่อนไขทั้งหมดออกจากชีต |
clear | Sheet | ล้างเนื้อหาในชีต แต่จะเก็บข้อมูลการจัดรูปแบบไว้ |
clear | Sheet | ล้างการจัดรูปแบบชีตโดยคงเนื้อหาไว้ |
clear | Sheet | ล้างโน้ตทั้งหมดในชีต |
collapse | Sheet | ยุบกลุ่มคอลัมน์ทั้งหมดในชีต |
collapse | Sheet | ยุบกลุ่มแถวทั้งหมดในชีต |
copy | Sheet | คัดลอกชีตไปยังสเปรดชีตที่ระบุ ซึ่งอาจเป็นสเปรดชีตเดียวกันกับแหล่งที่มาก็ได้ |
create | Developer | แสดงผล Developer สำหรับค้นหาข้อมูลเมตาของนักพัฒนาแอปภายในขอบเขตของ
ชีตนี้ |
create | Text | สร้างเครื่องมือค้นหาข้อความสำหรับชีต ซึ่งสามารถค้นหาและแทนที่ข้อความภายในชีตได้ |
delete | Sheet | ลบคอลัมน์ในตำแหน่งคอลัมน์ที่ระบุ |
delete | void | ลบคอลัมน์จำนวนหนึ่งโดยเริ่มจากตำแหน่งคอลัมน์ที่ระบุ |
delete | Sheet | ลบแถวในตำแหน่งแถวที่ระบุ |
delete | void | ลบจำนวนแถวที่เริ่มต้นที่ตำแหน่งแถวที่ระบุ |
expand | Sheet | ขยายกลุ่มคอลัมน์ทั้งหมดในชีต |
expand | Sheet | ขยายกลุ่มแถวทั้งหมดในชีต |
expand | Sheet | ขยายกลุ่มคอลัมน์ทั้งหมดจนถึงระดับความลึกที่ระบุ และยุบกลุ่มอื่นๆ ทั้งหมด |
expand | Sheet | ขยายกลุ่มแถวทั้งหมดจนถึงระดับที่ระบุ และยุบกลุ่มอื่นๆ ทั้งหมด |
get | Range | แสดงผลเซลล์ที่ใช้งานอยู่ในชีตนี้ |
get | Range | แสดงช่วงที่เลือกในชีตที่ใช้งานอยู่ หรือ null หากไม่มีช่วงที่ใช้งานอยู่ |
get | Range | แสดงรายการช่วงที่ใช้งานอยู่ในชีตที่ใช้งานอยู่ หรือ null หากไม่มีช่วงที่ใช้งานอยู่
|
get | Banding[] | แสดงการแบนทั้งหมดในชีตนี้ |
get | Embedded | แสดงผลอาร์เรย์ของแผนภูมิในชีตนี้ |
get | Group | แสดงผลกลุ่มคอลัมน์ที่ดัชนีและความลึกของกลุ่มที่ระบุ |
get | Group | แสดงผล Group สำหรับกลุ่มคอลัมน์ทั้งหมดในชีต |
get | Integer | แสดงผลความลึกของกลุ่มของคอลัมน์ที่ดัชนีที่ระบุ |
get | Integer | รับความกว้างเป็นพิกเซลของคอลัมน์ที่ระบุ |
get | Conditional | รับกฎการจัดรูปแบบตามเงื่อนไขทั้งหมดในชีตนี้ |
get | Range | แสดงผลเซลล์ปัจจุบันในชีตที่ใช้งานอยู่หรือ null หากไม่มีเซลล์ปัจจุบัน |
get | Range | แสดงผล Range ที่สอดคล้องกับมิติข้อมูลที่มีข้อมูล |
get | Data | รับสูตรแหล่งข้อมูลทั้งหมด |
get | Data | รับตาราง Pivot ของแหล่งข้อมูลทั้งหมด |
get | Data | รับตารางแหล่งข้อมูลทั้งหมด |
get | Developer | รับข้อมูลเมตานักพัฒนาแอปทั้งหมดที่เชื่อมโยงกับชีตนี้ |
get | Drawing[] | แสดงผลอาร์เรย์ของภาพวาดในชีต |
get | Filter | แสดงตัวกรองในชีตนี้ หรือ null หากไม่มีตัวกรอง |
get | String | แสดง URL ของแบบฟอร์มที่ส่งคำตอบไปยังชีตนี้ หรือ null หากชีตนี้ไม่มีแบบฟอร์มที่เชื่อมโยง |
get | Integer | แสดงผลจำนวนคอลัมน์ที่ตรึง |
get | Integer | แสดงผลจำนวนแถวที่ตรึง |
get | Over | แสดงรูปภาพทั้งหมดที่อยู่นอกตารางกริดในชีต |
get | Integer | รับตำแหน่งของชีตในสเปรดชีตหลัก |
get | Integer | แสดงตำแหน่งของคอลัมน์สุดท้ายที่มีเนื้อหา |
get | Integer | แสดงตำแหน่งของแถวสุดท้ายที่มีเนื้อหา |
get | Integer | แสดงผลจำนวนคอลัมน์ปัจจุบันในชีตโดยไม่คำนึงถึงเนื้อหา |
get | Integer | แสดงผลจำนวนแถวปัจจุบันในชีตโดยไม่คำนึงถึงเนื้อหา |
get | String | แสดงผลชื่อชีต |
get | Named | รับช่วงที่ตั้งชื่อทั้งหมดในชีตนี้ |
get | Spreadsheet | แสดง Spreadsheet ที่มีชีตนี้ |
get | Pivot | แสดงตาราง Pivot ทั้งหมดในชีตนี้ |
get | Protection[] | รับอาร์เรย์ของออบเจ็กต์ที่แสดงช่วงที่ป้องกันทั้งหมดในชีต หรืออาร์เรย์ที่มีองค์ประกอบเดียวซึ่งแสดงการป้องกันในชีตเอง |
get | Range | แสดงผลช่วงที่มีเซลล์ซ้ายบนที่พิกัดที่ระบุ |
get | Range | แสดงผลช่วงที่มีเซลล์ด้านซ้ายบนที่พิกัดที่ระบุ และมีจำนวน แถวที่ระบุ |
get | Range | แสดงผลช่วงที่มีเซลล์ด้านซ้ายบนที่พิกัดที่กำหนดโดยมีจำนวนแถว และคอลัมน์ที่กำหนด |
get | Range | แสดงผลช่วงตามที่ระบุในรูปแบบ A1 หรือ R1C1 |
get | Range | แสดงผลคอลเล็กชัน Range ที่แสดงช่วงในชีตเดียวกันซึ่งระบุโดยรายการสัญกรณ์ A1 หรือสัญกรณ์ R1C1 ที่ไม่ว่าง |
get | Group | แสดงผลกลุ่มแถวที่ดัชนีและความลึกของกลุ่มที่ระบุ |
get | Group | แสดงผล Group สำหรับกลุ่มแถวทั้งหมดในชีต |
get | Integer | แสดงผลระดับกลุ่มของแถวที่ดัชนีที่ระบุ |
get | Integer | รับความสูงเป็นพิกเซลของแถวที่ระบุ |
get | Selection | แสดงผล Selection ปัจจุบันในสเปรดชีต |
get | Integer | แสดงผลรหัสของชีตที่ออบเจ็กต์นี้แสดง |
get | String | แสดงผลชื่อชีต |
get | Object[][] | แสดงผลตารางกริดสี่เหลี่ยมของค่าสำหรับช่วงนี้โดยเริ่มที่พิกัดที่ระบุ |
get | Slicer[] | แสดงผลอาร์เรย์ของ Slicer ในชีต |
get | Color | รับสีแท็บชีต หรือ null หากแท็บชีตไม่มีสี |
get | Sheet | แสดงผลประเภทของชีต |
has | Boolean | แสดงผล true หากซ่อนเส้นตารางของชีตไว้ หรือแสดงผล false ในกรณีอื่นๆ |
hide | void | ซ่อนคอลัมน์ในช่วงที่ระบุ |
hide | void | ซ่อนคอลัมน์เดียวที่ดัชนีที่ระบุ |
hide | void | ซ่อนคอลัมน์ที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์โดยเริ่มจากดัชนีที่ระบุ |
hide | void | ซ่อนแถวในช่วงที่ระบุ |
hide | void | ซ่อนแถวที่ดัชนีที่ระบุ |
hide | void | ซ่อนแถวที่ต่อเนื่องกันอย่างน้อย 1 แถวโดยเริ่มจากดัชนีที่ระบุ |
hide | Sheet | ซ่อนชีตนี้ |
insert | void | เพิ่มแผนภูมิใหม่ลงในชีตนี้ |
insert | Sheet | แทรกคอลัมน์หลังตำแหน่งคอลัมน์ที่ระบุ |
insert | Sheet | แทรกคอลัมน์ก่อนตำแหน่งคอลัมน์ที่ระบุ |
insert | void | แทรกคอลัมน์ว่างในชีตที่ตำแหน่งที่ระบุ |
insert | void | แทรกคอลัมน์ว่างที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์ในชีตโดยเริ่มจากตำแหน่งที่ระบุ |
insert | Sheet | แทรกคอลัมน์ตามจำนวนที่ระบุหลังจากตำแหน่งคอลัมน์ที่ระบุ |
insert | Sheet | แทรกคอลัมน์จำนวนหนึ่งก่อนตำแหน่งคอลัมน์ที่ระบุ |
insert | Over | แทรก Blob เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ |
insert | Over | แทรก Blob เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ โดยมีออฟเซ็ต
พิกเซล |
insert | Over | แทรกรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ |
insert | Over | แทรกรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ โดยมีค่าออฟเซ็ตเป็นพิกเซล |
insert | Sheet | แทรกแถวหลังตำแหน่งแถวที่ระบุ |
insert | Sheet | แทรกแถวก่อนตำแหน่งแถวที่ระบุ |
insert | void | แทรกแถวว่างในชีตที่ตำแหน่งที่ระบุ |
insert | void | แทรกแถวว่างที่ต่อเนื่องกันอย่างน้อย 1 แถวในชีตโดยเริ่มจากตำแหน่งที่ระบุ |
insert | Sheet | แทรกจำนวนแถวหลังจากตำแหน่งแถวที่ระบุ |
insert | Sheet | แทรกจำนวนแถวก่อนตำแหน่งแถวที่ระบุ |
insert | Slicer | เพิ่ม Slicer ใหม่ลงในชีตนี้ |
insert | Slicer | เพิ่ม Slicer ใหม่ลงในชีตนี้ |
is | Boolean | แสดงผลว่าผู้ใช้ซ่อนคอลัมน์ที่ระบุหรือไม่ |
is | Boolean | แสดงผล true หากเลย์เอาต์ชีตนี้เป็นจากขวาไปซ้าย |
is | Boolean | แสดงว่าแถวที่ระบุซ่อนอยู่ตามตัวกรอง (ไม่ใช่มุมมองตัวกรอง) หรือไม่ |
is | Boolean | แสดงผลว่าผู้ใช้ซ่อนแถวที่ระบุหรือไม่ |
is | Boolean | แสดง true หากชีตซ่อนอยู่ |
move | void | ย้ายคอลัมน์ที่เลือกตามช่วงที่ระบุไปยังตำแหน่งที่ระบุโดย destination |
move | void | ย้ายแถวที่เลือกตามช่วงที่ระบุไปยังตำแหน่งที่ระบุโดย destination |
new | Embedded | แสดงผล Builder เพื่อสร้างแผนภูมิใหม่สำหรับชีตนี้ |
protect() | Protection | สร้างออบเจ็กต์ที่ป้องกันไม่ให้มีการแก้ไขชีตได้ ยกเว้นผู้ใช้ที่มี สิทธิ์ |
remove | void | นำแผนภูมิออกจากชีตหลัก |
set | Range | กำหนดช่วงที่ระบุเป็นactive range ในชีตที่ใช้งานอยู่ โดยมีเซลล์ซ้ายบนสุดในช่วงเป็นcurrent cell |
set | Range | ตั้งค่ารายการช่วงที่ระบุเป็น active ranges ในชีตที่ใช้งานอยู่ |
set | Range | ตั้งค่าภูมิภาคที่เลือกที่ใช้งานอยู่สำหรับชีตนี้ |
set | Range | ตั้งค่าการเลือกที่ใช้งานอยู่ตามที่ระบุในรูปแบบ A1 หรือ R1C1 |
set | Sheet | กำหนดตำแหน่งของปุ่มเปิด/ปิดการควบคุมกลุ่มคอลัมน์ในชีต |
set | Sheet | กำหนดความกว้างของคอลัมน์ที่ระบุเป็นพิกเซล |
set | Sheet | กำหนดความกว้างของคอลัมน์ที่ระบุในหน่วยพิกเซล |
set | void | แทนที่กฎการจัดรูปแบบตามเงื่อนไขที่มีอยู่ในชีตทั้งหมดด้วยกฎที่ป้อน |
set | Range | ตั้งค่าเซลล์ที่ระบุเป็น current cell |
set | void | ตรึงจำนวนคอลัมน์ที่ระบุ |
set | void | ตรึงจำนวนแถวที่ระบุ |
set | Sheet | ซ่อนหรือแสดงเส้นตารางแผ่นงาน |
set | Sheet | ตั้งชื่อชีต |
set | Sheet | ตั้งค่าหรือยกเลิกการตั้งค่าเลย์เอาต์ชีตเป็นจากขวาไปซ้าย |
set | Sheet | ตั้งค่าตำแหน่งของปุ่มเปิด/ปิดการควบคุมกลุ่มแถวในชีต |
set | Sheet | กำหนดความสูงของแถวที่ระบุเป็นพิกเซล |
set | Sheet | กำหนดความสูงของแถวที่ระบุเป็นพิกเซล |
set | Sheet | กำหนดความสูงของแถวที่ระบุเป็นพิกเซล |
set | Sheet | ตั้งค่าสีแท็บแผ่นงาน |
set | Sheet | ตั้งค่าสีแท็บแผ่นงาน |
show | void | เลิกซ่อนคอลัมน์ที่ดัชนีที่ระบุ |
show | void | เลิกซ่อนคอลัมน์ที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์โดยเริ่มจากดัชนีที่ระบุ |
show | void | เลิกซ่อนแถวที่ดัชนีที่ระบุ |
show | void | เลิกซ่อนแถวที่ต่อเนื่องกันอย่างน้อย 1 แถวโดยเริ่มจากดัชนีที่ระบุ |
show | Sheet | ทำให้ชีตปรากฏ |
sort(columnPosition) | Sheet | จัดเรียงชีตตามคอลัมน์จากน้อยไปมาก |
sort(columnPosition, ascending) | Sheet | จัดเรียงชีตตามคอลัมน์ |
unhide | void | เลิกซ่อนคอลัมน์ในช่วงที่กำหนด |
unhide | void | เลิกซ่อนแถวในช่วงที่กำหนด |
update | void | อัปเดตแผนภูมิในชีตนี้ |
เอกสารโดยละเอียด
activate()
เปิดใช้งานชีตนี้ ไม่ได้แก้ไขชีตเอง แต่แก้ไขเฉพาะแนวคิดของชีตที่ใช้งานอยู่ของชีตหลัก
// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.activate();
รีเทิร์น
Sheet
— ชีตที่เพิ่งเปิดใช้งาน
add Developer Metadata(key)
เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ที่ระบุลงในชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Adds the key 'NAME' to the developer metadata for the sheet. sheet.addDeveloperMetadata('NAME'); // Gets the updated metadata info and logs it to the console. console.log(sheet.getDeveloperMetadata()[0].getKey());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
add Developer Metadata(key, visibility)
เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์และการเปิดเผยที่ระบุลงในชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Adds the key 'NAME' and sets the developer metadata visibility to PROJECT // for the sheet. sheet.addDeveloperMetadata( 'NAME', SpreadsheetApp.DeveloperMetadataVisibility.PROJECT, ); // Gets the updated metadata info and logs it to the console. const developerMetaData = sheet.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log(developerMetaData.getVisibility().toString());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
visibility | Developer | ระดับการเข้าถึงของข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
add Developer Metadata(key, value)
เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์และค่าที่ระบุลงในชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Adds the key 'COMPANY' with the value 'TECH' to the developer metadata for // the sheet. sheet.addDeveloperMetadata('COMPANY', 'TECH'); // Gets the updated metadata info and logs it to the console. const developerMetaData = sheet.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log(developerMetaData.getValue());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
value | String | ค่าสำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
add Developer Metadata(key, value, visibility)
เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ ค่า และระดับการเข้าถึงที่ระบุลงในชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Adds the key 'COMPANY' with the value 'TECH' to the developer metadata and // sets the visibility to DOCUMENT for the sheet. sheet.addDeveloperMetadata( 'COMPANY', 'TECH', SpreadsheetApp.DeveloperMetadataVisibility.DOCUMENT, ); // Gets the updated metadata info and logs it to the console. const developerMetaData = sheet.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log(developerMetaData.getValue()); console.log(developerMetaData.getVisibility().toString());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
value | String | ค่าสำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
visibility | Developer | ระดับการเข้าถึงของข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
append Row(rowContents)
เพิ่มแถวที่ด้านล่างของเขตข้อมูลปัจจุบันในชีต หากเนื้อหาของเซลล์เริ่มต้นด้วย =
ระบบจะตีความว่าเป็นสูตร
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Appends a new row with 3 columns to the bottom of the current // data region in the sheet containing the values in the array. sheet.appendRow(['a man', 'a plan', 'panama']);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Object[] | อาร์เรย์ของค่าที่จะแทรกหลังจากแถวสุดท้ายในชีต |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
as Data Source Sheet()
แสดงผลชีตเป็น Data
หากชีตเป็นประเภท Sheet
หรือ null
ในกรณีอื่นๆ
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can useSpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets the data source sheet value if the sheet is of type // SpreadsheetApp.SheetType.DATASOURCE, otherwise this returns a null value. const dataSourceSheet = sheet.asDataSourceSheet(); // Gets the data source sheet value and logs it to the console. console.log(dataSourceSheet); console.log(sheet.getType().toString());
รีเทิร์น
Data
- ชีตแหล่งข้อมูล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
auto Resize Column(columnPosition)
ตั้งค่าความกว้างของคอลัมน์ที่ระบุให้พอดีกับเนื้อหา
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; sheet.getRange('a1').setValue( 'Whenever it is a damp, drizzly November in my soul...'); // Sets the first column to a width which fits the text sheet.autoResizeColumn(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ตำแหน่งของคอลัมน์ที่ต้องการปรับขนาด |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
auto Resize Columns(startColumn, numColumns)
กำหนดความกว้างของคอลัมน์ทั้งหมดโดยเริ่มที่ตำแหน่งคอลัมน์ที่ระบุเพื่อให้พอดีกับเนื้อหา
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Sets the first 15 columns to a width that fits their text. sheet.autoResizeColumns(1, 15);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
start | Integer | คอลัมน์เริ่มต้นที่จะปรับขนาดอัตโนมัติ |
num | Integer | จำนวนคอลัมน์ที่จะปรับขนาดอัตโนมัติ |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
auto Resize Rows(startRow, numRows)
กำหนดความสูงของแถวทั้งหมดโดยเริ่มที่ตำแหน่งแถวที่ระบุเพื่อให้พอดีกับเนื้อหา
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Sets the first 15 rows to a height that fits their text. sheet.autoResizeRows(1, 15);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
start | Integer | แถวเริ่มต้นที่จะปรับขนาดอัตโนมัติ |
num | Integer | จำนวนแถวที่จะปรับขนาดอัตโนมัติ |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clear()
ล้างข้อมูลเนื้อหาและการจัดรูปแบบในชีต
// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.clear();
รีเทิร์น
Sheet
— แผ่นงานที่ล้างแล้ว
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clear(options)
ล้างเนื้อหาและ/หรือรูปแบบของชีตตามที่ระบุด้วยตัวเลือกขั้นสูงที่กำหนด
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; sheet.clear({formatOnly: true, contentsOnly: true});
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
options | Object | แผนที่ JavaScript ที่มีตัวเลือกขั้นสูงซึ่งแสดงอยู่ด้านล่าง |
พารามิเตอร์ขั้นสูง
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
contents | Boolean | จะล้างเนื้อหาหรือไม่ |
format | Boolean | เลือกว่าจะล้างรูปแบบไหม |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clear Conditional Format Rules()
นํากฎรูปแบบตามเงื่อนไขทั้งหมดออกจากชีต เทียบเท่ากับการเรียกใช้ set
โดยมีอาร์เรย์ว่างเป็นอินพุต
const sheet = SpreadsheetApp.getActiveSheet(); sheet.clearConditionalFormatRules();
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clear Contents()
ล้างเนื้อหาในชีต แต่จะเก็บข้อมูลการจัดรูปแบบไว้
// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.clearContents();
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clear Formats()
ล้างการจัดรูปแบบชีตโดยคงเนื้อหาไว้
การจัดรูปแบบหมายถึงวิธีจัดรูปแบบข้อมูลตามที่ตัวเลือกในเมนู "รูปแบบ" อนุญาต (เช่น ตัวหนา ตัวเอียง การจัดรูปแบบตามเงื่อนไข) ไม่ใช่ความกว้างหรือความสูงของเซลล์
// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.clearFormats();
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clear Notes()
ล้างโน้ตทั้งหมดในชีต
// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.clearNotes();
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
collapse All Column Groups()
ยุบกลุ่มคอลัมน์ทั้งหมดในชีต
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // All column groups on the sheet are collapsed. sheet.collapseAllColumnGroups();
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
collapse All Row Groups()
ยุบกลุ่มแถวทั้งหมดในชีต
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // All row groups on the sheet are collapsed. sheet.collapseAllRowGroups();
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
copy To(spreadsheet)
คัดลอกชีตไปยังสเปรดชีตที่ระบุ ซึ่งอาจเป็นสเปรดชีตเดียวกันกับแหล่งที่มาก็ได้ แผ่นงานที่คัดลอกจะมีชื่อว่า "สำเนาของ [ชื่อเดิม]"
const source = SpreadsheetApp.getActiveSpreadsheet(); const sheet = source.getSheets()[0]; const destination = SpreadsheetApp.openById('ID_GOES HERE'); sheet.copyTo(destination);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
spreadsheet | Spreadsheet | สเปรดชีตที่จะคัดลอกชีตนี้ไป ซึ่งอาจเป็นสเปรดชีตเดียวกันกับ แหล่งที่มาก็ได้ |
รีเทิร์น
Sheet
- ชีตใหม่สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
create Developer Metadata Finder()
แสดงผล Developer
สำหรับค้นหาข้อมูลเมตาของนักพัฒนาแอปภายในขอบเขตของ
ชีตนี้ ข้อมูลเมตาจะอยู่ในขอบเขตของชีตหนึ่งๆ หากเชื่อมโยงกับชีตนั้นเอง หรือเชื่อมโยงกับแถว คอลัมน์ หรือช่วงในชีตนั้น
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Adds developer metadata for testing. sheet.addDeveloperMetadata('CITY', 'PARIS'); // Creates the developer metadata finder. const metadatafinder = sheet.createDeveloperMetadataFinder(); // Finds the metadata with value 'PARIS' and displays its key in the console. console.log(metadatafinder.withValue('PARIS').find()[0].getKey());
รีเทิร์น
Developer
— เครื่องมือค้นหาข้อมูลเมตาของนักพัฒนาซอฟต์แวร์เพื่อค้นหาข้อมูลเมตาในขอบเขตของชีตนี้
create Text Finder(findText)
สร้างเครื่องมือค้นหาข้อความสำหรับชีต ซึ่งสามารถค้นหาและแทนที่ข้อความภายในชีตได้
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // Creates a text finder. const textFinder = sheet.createTextFinder('dog'); // Returns the first occurrence of 'dog' in the sheet. const firstOccurrence = textFinder.findNext(); // Replaces the last found occurrence of 'dog' with 'cat' and returns the number // of occurrences replaced. const numOccurrencesReplaced = firstOccurrence.replaceWith('cat');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
find | String | ข้อความที่จะค้นหา |
รีเทิร์น
Text
— Text
ของชีต
delete Column(columnPosition)
ลบคอลัมน์ในตำแหน่งคอลัมน์ที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Columns start at "1" - this deletes the first column sheet.deleteColumn(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ตำแหน่งของคอลัมน์ โดยเริ่มที่ 1 สำหรับคอลัมน์แรก |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
delete Columns(columnPosition, howMany)
ลบคอลัมน์จำนวนหนึ่งโดยเริ่มจากตำแหน่งคอลัมน์ที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Columns start at "1" - this deletes the first two columns sheet.deleteColumns(1, 2);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ตำแหน่งของคอลัมน์แรกที่จะลบ |
how | Integer | จำนวนคอลัมน์ที่จะลบ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
delete Row(rowPosition)
ลบแถวในตำแหน่งแถวที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Rows start at "1" - this deletes the first row sheet.deleteRow(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ตำแหน่งของแถว โดยเริ่มที่ 1 สำหรับแถวแรก |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
delete Rows(rowPosition, howMany)
ลบจำนวนแถวที่เริ่มต้นที่ตำแหน่งแถวที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Rows start at "1" - this deletes the first two rows sheet.deleteRows(1, 2);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ตำแหน่งของแถวแรกที่จะลบ |
how | Integer | จำนวนแถวที่จะลบ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
expand All Column Groups()
ขยายกลุ่มคอลัมน์ทั้งหมดในชีต วิธีนี้ต้องมีกลุ่มคอลัมน์อย่างน้อย 1 กลุ่ม
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // All column groups on the sheet are expanded. sheet.expandAllColumnGroups();
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
expand All Row Groups()
ขยายกลุ่มแถวทั้งหมดในชีต วิธีนี้ต้องมีกลุ่มแถวอย่างน้อย 1 กลุ่ม
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // All row groups on the sheet are expanded. sheet.expandAllRowGroups();
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
expand Column Groups Up To Depth(groupDepth)
ขยายกลุ่มคอลัมน์ทั้งหมดจนถึงระดับความลึกที่ระบุ และยุบกลุ่มอื่นๆ ทั้งหมด
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // All column groups of depth 2 and lower are expanded, and groups with depth // 3 and higher are collapsed. sheet.expandColumnGroupsUpToDepth(2);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
group | Integer | ความลึกของกลุ่มที่จะขยายกลุ่มคอลัมน์ |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
expand Row Groups Up To Depth(groupDepth)
ขยายกลุ่มแถวทั้งหมดจนถึงระดับที่ระบุ และยุบกลุ่มอื่นๆ ทั้งหมด
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // All row groups of depth 2 and lower are expanded, and groups with depth // 3 and higher are collapsed. sheet.expandRowGroupsUpToDepth(2);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
group | Integer | ความลึกของกลุ่มที่จะขยายกลุ่มแถว |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Active Cell()
แสดงผลเซลล์ที่ใช้งานอยู่ในชีตนี้
หมายเหตุ: ขอแนะนำให้ใช้ get
ซึ่งจะแสดงผลเซลล์ที่ไฮไลต์ในปัจจุบัน
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Returns the active cell const cell = sheet.getActiveCell();
รีเทิร์น
Range
— เซลล์ที่ใช้งานอยู่ในปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Active Range()
แสดงช่วงที่เลือกในชีตที่ใช้งานอยู่ หรือ null
หากไม่มีช่วงที่ใช้งานอยู่ หากเลือกหลายช่วง วิธีนี้จะแสดงเฉพาะช่วงที่เลือกสุดท้าย
คำว่า "ช่วงที่ใช้งานอยู่" หมายถึงช่วงที่ผู้ใช้เลือกในชีตที่ใช้งานอยู่ แต่ในฟังก์ชันที่กำหนดเองจะหมายถึงเซลล์ที่กำลังคำนวณใหม่
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const activeRange = sheet.getActiveRange();
รีเทิร์น
Range
- ช่วงที่ใช้งานอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
ดูเพิ่มเติม
get Active Range List()
แสดงรายการช่วงที่ใช้งานอยู่ในชีตที่ใช้งานอยู่ หรือ null
หากไม่มีช่วงที่ใช้งานอยู่
หากเลือกช่วงเดียว ฟังก์ชันนี้จะทำงานเป็นget
const sheet = SpreadsheetApp.getActiveSheet(); // Returns the list of active ranges. const activeRangeList = sheet.getActiveRangeList();
รีเทิร์น
Range
— รายการช่วงที่ใช้งานอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
ดูเพิ่มเติม
get Bandings()
แสดงการแบนทั้งหมดในชีตนี้
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets the banding info for the sheet. const bandings = sheet.getBandings(); // Gets info on the bandings' second row color and logs it to the console. for (const banding of bandings) { console.log(banding.getSecondRowColor()); }
รีเทิร์น
Banding[]
— แถบทั้งหมดในชีตนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Charts()
แสดงผลอาร์เรย์ของแผนภูมิในชีตนี้
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; const charts = sheet.getCharts(); for (const i in charts) { const chart = charts[i]; // Do something with the chart }
รีเทิร์น
Embedded
— อาร์เรย์ของแผนภูมิ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Column Group(columnIndex, groupDepth)
แสดงผลกลุ่มคอลัมน์ที่ดัชนีและความลึกของกลุ่มที่ระบุ
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // Returns the group whose control index is at column 2 and has a depth of 1, or // null if the group doesn’t exist. const columnGroup = sheet.getColumnGroup(2, 1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ดัชนีคอลัมน์ของปุ่มเปิด/ปิดการควบคุมกลุ่มหรือดัชนีภายในกลุ่ม |
group | Integer | ความลึกของกลุ่ม |
รีเทิร์น
Group
— กลุ่มคอลัมน์ที่ดัชนีและความลึกของตัวควบคุม หรือแสดงข้อยกเว้นหากกลุ่ม
ไม่มีอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Column Group Control Position()
แสดงผล Group
สำหรับกลุ่มคอลัมน์ทั้งหมดในชีต
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // GroupControlTogglePosition.AFTER if the column grouping control toggle is // shown after the group. const columnGroupControlPosition = sheet.getColumnGroupControlPosition();
รีเทิร์น
Group
— true
หากปุ่มเปิด/ปิดการควบคุมการจัดกลุ่มคอลัมน์แสดงขึ้นหลังจากกลุ่มในชีตนี้
และ false
ในกรณีอื่นๆ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Column Group Depth(columnIndex)
แสดงผลความลึกของกลุ่มของคอลัมน์ที่ดัชนีที่ระบุ
ความลึกของกลุ่มจะระบุจำนวนกลุ่มที่ทับซ้อนกับคอลัมน์ ซึ่งอาจมีค่าตั้งแต่ 0 ถึง 8
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // 1 if there is a group over columns 1 through 3 const groupDepth = sheet.getColumnGroupDepth(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ดัชนีของคอลัมน์ |
รีเทิร์น
Integer
— ความลึกของกลุ่มของคอลัมน์ที่ดัชนีที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Column Width(columnPosition)
รับความกว้างเป็นพิกเซลของคอลัมน์ที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Columns start at 1 Logger.log(sheet.getColumnWidth(1));
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ตำแหน่งของคอลัมน์ที่จะตรวจสอบ |
รีเทิร์น
Integer
— ความกว้างของคอลัมน์เป็นพิกเซล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Conditional Format Rules()
รับกฎการจัดรูปแบบตามเงื่อนไขทั้งหมดในชีตนี้
// Logs the conditional format rules in a sheet. const rules = SpreadsheetApp.getActiveSheet().getConditionalFormatRules(); for (let i = 0; i < rules.length; i++) { const rule = rules[i]; Logger.log(rule); }
รีเทิร์น
Conditional
— อาร์เรย์ของกฎทั้งหมดในชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Current Cell()
แสดงผลเซลล์ปัจจุบันในชีตที่ใช้งานอยู่หรือ null
หากไม่มีเซลล์ปัจจุบัน
เซลล์ปัจจุบันคือเซลล์ที่โฟกัสใน UI ของ Google ชีต และมีการไฮไลต์ด้วยเส้นขอบสีเข้ม
โดยจะมีเซลล์ปัจจุบันเพียงเซลล์เดียวเสมอ เมื่อผู้ใช้เลือกช่วงเซลล์อย่างน้อย 1 ช่วง
เซลล์ใดเซลล์หนึ่งในการเลือกจะเป็นเซลล์ปัจจุบัน
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // Returns the current highlighted cell in the one of the active ranges. const currentCell = sheet.getCurrentCell();
รีเทิร์น
Range
— เซลล์ปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Data Range()
แสดงผล Range
ที่สอดคล้องกับมิติข้อมูลที่มีข้อมูล
ซึ่งเทียบเท่ากับการสร้างช่วงที่กำหนดโดย A1 และ (Sheet.getLastColumn(), Sheet.getLastRow())
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This represents ALL the data const range = sheet.getDataRange(); const values = range.getValues(); // This logs the spreadsheet in CSV format with a trailing comma for (let i = 0; i < values.length; i++) { let row = ''; for (let j = 0; j < values[i].length; j++) { if (values[i][j]) { row = row + values[i][j]; } row = `${row},`; } Logger.log(row); }
รีเทิร์น
Range
— ช่วงที่ประกอบด้วยข้อมูลทั้งหมดในสเปรดชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Data Source Formulas()
รับสูตรแหล่งข้อมูลทั้งหมด
// Opens the spreadsheet by its ID. If you created your script from within a // Google Sheets file, use SpreadsheetApp.getActiveSpreadsheet(). // TODO(developer): Replace the ID with your own. const ss = SpreadsheetApp.openById('abc123456'); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets an array of the data source formulas on Sheet1. // To get an array of data source formulas for the entire spreadsheet, // replace 'sheet' with 'ss'. const dataSourceFormulas = sheet.getDataSourceFormulas(); // Logs the first data source formula in the array. console.log(dataSourceFormulas[0].getFormula());
รีเทิร์น
Data
— รายการสูตรแหล่งข้อมูล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Data Source Pivot Tables()
รับตาราง Pivot ของแหล่งข้อมูลทั้งหมด
// Opens the spreadsheet file by its ID. If you created your script from a // Google Sheets file, use SpreadsheetApp.getActiveSpreadsheet(). // TODO(developer): Replace the ID with your own. const ss = SpreadsheetApp.openById('abc123456'); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets an array of the data source pivot tables on Sheet1. // To get an array of data source pivot tables for the entire // spreadsheet, replace 'sheet' with 'ss'. const dataSourcePivotTables = sheet.getDataSourcePivotTables(); // Logs the last time that the first pivot table in the array was refreshed. console.log(dataSourcePivotTables[0].getStatus().getLastRefreshedTime());
รีเทิร์น
Data
- รายการตาราง Pivot ของแหล่งข้อมูล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Data Source Tables()
รับตารางแหล่งข้อมูลทั้งหมด
// Opens the spreadsheet file by its ID. If you created your script from a // Google Sheets file, use SpreadsheetApp.getActiveSpreadsheet(). // TODO(developer): Replace the ID with your own. const ss = SpreadsheetApp.openById('abc123456'); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets an array of data source tables on Sheet1. // To get an array of data source tables for the entire spreadsheet, // replace 'sheet' with 'ss'. const dataSourceTables = sheet.getDataSourceTables(); // Logs the last completed data execution time on the first data source table. console.log(dataSourceTables[0].getStatus().getLastExecutionTime());
รีเทิร์น
Data
- รายการตารางแหล่งข้อมูล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Developer Metadata()
รับข้อมูลเมตานักพัฒนาแอปทั้งหมดที่เชื่อมโยงกับชีตนี้
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Adds developer metadata for testing. sheet.addDeveloperMetadata('CITY', 'PARIS'); // Gets all the developer metadata for the sheet. const developerMetaDataList = sheet.getDeveloperMetadata(); // Logs the developer metadata to the console. for (const developerMetaData of developerMetaDataList) { console.log(developerMetaData.getKey()); }
รีเทิร์น
Developer
- ข้อมูลเมตาของนักพัฒนาแอปที่เชื่อมโยงกับชีตนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Drawings()
แสดงผลอาร์เรย์ของภาพวาดในชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets all the drawings from the sheet. const allDrawings = sheet.getDrawings(); // Logs the number of drawings present on the sheet. console.log(allDrawings.length);
รีเทิร์น
Drawing[]
— รายการภาพวาดในชีตนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Filter()
แสดงตัวกรองในชีตนี้ หรือ null
หากไม่มีตัวกรอง
// Gets the filter on the active sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter();
รีเทิร์น
Filter
— ตัวกรอง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Form Url()
แสดง URL ของแบบฟอร์มที่ส่งคำตอบไปยังชีตนี้ หรือ null
หากชีตนี้ไม่มีแบบฟอร์มที่เชื่อมโยง แสดงข้อยกเว้นหากผู้ใช้ไม่มีสิทธิ์แก้ไข
สเปรดชีต
const sheet = SpreadsheetApp.getActiveSheet(); const url = sheet.getFormUrl();
รีเทิร์น
String
— URL ของแบบฟอร์มที่จัดเก็บคำตอบไว้ในชีตนี้ หรือ null
หากชีตนี้ไม่มีแบบฟอร์มที่เชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Frozen Columns()
แสดงผลจำนวนคอลัมน์ที่ตรึง
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; Logger.log('Number of frozen columns: %s', sheet.getFrozenColumns());
รีเทิร์น
Integer
— จำนวนคอลัมน์ที่ตรึงไว้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Frozen Rows()
แสดงผลจำนวนแถวที่ตรึง
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; Logger.log('Number of frozen rows: %s', sheet.getFrozenRows());
รีเทิร์น
Integer
— จำนวนแถวที่ตรึงไว้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Images()
แสดงรูปภาพทั้งหมดที่อยู่นอกตารางกริดในชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets the over-the-grid images from Sheet1. // To get the over-the-grid images from the entire spreadsheet, use // ss.getImages() instead. const images = sheet.getImages(); // For each image, logs the anchor cell in A1 notation. for (const image of images) { console.log(image.getAnchorCell().getA1Notation()); }
รีเทิร์น
Over
— อาร์เรย์ของรูปภาพที่วางทับบนตาราง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Index()
รับตำแหน่งของชีตในสเปรดชีตหลัก เริ่มที่ 1
const ss = SpreadsheetApp.getActiveSpreadsheet(); // Note that the JavaScript index is 0, but this logs 1 const sheet = ss.getSheets()[0]; // ... because spreadsheets are 1-indexed Logger.log(sheet.getIndex());
รีเทิร์น
Integer
— ตำแหน่งของชีตในสเปรดชีตหลัก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Last Column()
แสดงตำแหน่งของคอลัมน์สุดท้ายที่มีเนื้อหา
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This logs the value in the very last cell of this sheet const lastRow = sheet.getLastRow(); const lastColumn = sheet.getLastColumn(); const lastCell = sheet.getRange(lastRow, lastColumn); Logger.log(lastCell.getValue());
รีเทิร์น
Integer
— คอลัมน์สุดท้ายของชีตที่มีเนื้อหา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Last Row()
แสดงตำแหน่งของแถวสุดท้ายที่มีเนื้อหา
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This logs the value in the very last cell of this sheet const lastRow = sheet.getLastRow(); const lastColumn = sheet.getLastColumn(); const lastCell = sheet.getRange(lastRow, lastColumn); Logger.log(lastCell.getValue());
รีเทิร์น
Integer
— แถวสุดท้ายของชีตที่มีเนื้อหา
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Max Columns()
แสดงผลจำนวนคอลัมน์ปัจจุบันในชีตโดยไม่คำนึงถึงเนื้อหา
// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); Logger.log(first.getMaxColumns());
รีเทิร์น
Integer
- ความกว้างสูงสุดของชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Max Rows()
แสดงผลจำนวนแถวปัจจุบันในชีตโดยไม่คำนึงถึงเนื้อหา
// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); Logger.log(first.getMaxRows());
รีเทิร์น
Integer
— ความสูงสูงสุดของชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Name()
แสดงผลชื่อชีต
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; Logger.log(sheet.getName());
รีเทิร์น
String
— ชื่อของชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Named Ranges()
รับช่วงที่ตั้งชื่อทั้งหมดในชีตนี้
// The code below logs the name of the first named range. const namedRanges = SpreadsheetApp.getActiveSheet().getNamedRanges(); if (namedRanges.length > 1) { Logger.log(namedRanges[0].getName()); }
รีเทิร์น
Named
— อาร์เรย์ของช่วงที่ตั้งชื่อทั้งหมดในชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Parent()
แสดง Spreadsheet
ที่มีชีตนี้
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // parent is identical to ss const parent = sheet.getParent();
รีเทิร์น
Spreadsheet
- สเปรดชีตหลัก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Pivot Tables()
แสดงตาราง Pivot ทั้งหมดในชีตนี้
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets all the pivot table info for the sheet. const pivotTables = sheet.getPivotTables(); // Logs the pivot tables to the console. for (const pivotTable of pivotTables) { console.log(pivotTable.getSourceDataRange().getValues()); }
รีเทิร์น
Pivot
— ตาราง Pivot ในชีตนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Protections(type)
รับอาร์เรย์ของออบเจ็กต์ที่แสดงช่วงที่ป้องกันทั้งหมดในชีต หรืออาร์เรย์ที่มีองค์ประกอบเดียวซึ่งแสดงการป้องกันในชีตเอง
// Remove all range protections in the spreadsheet that the user has permission // to edit. const sheet = SpreadsheetApp.getActiveSheet(); const protections = sheet.getProtections(SpreadsheetApp.ProtectionType.RANGE); for (let i = 0; i < protections.length; i++) { const protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
// Remove sheet protection from the active sheet, if the user has permission to // edit it. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.getProtections(SpreadsheetApp.ProtectionType.SHEET)[0]; if (protection?.canEdit()) { protection.remove(); }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
type | Protection | ประเภทของพื้นที่คุ้มครอง ไม่ว่าจะเป็น Spreadsheet หรือ
Spreadsheet |
รีเทิร์น
Protection[]
— อาร์เรย์ของออบเจ็กต์ที่แสดงช่วงที่ป้องกันทั้งหมดในชีต หรืออาร์เรย์ที่มีองค์ประกอบเดียว
ซึ่งแสดงการป้องกันในชีตเอง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Range(row, column)
แสดงผลช่วงที่มีเซลล์ซ้ายบนที่พิกัดที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Passing only two arguments returns a "range" with a single cell. const range = sheet.getRange(1, 1); const values = range.getValues(); Logger.log(values[0][0]);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ดัชนีแถวของเซลล์ที่จะแสดงผล โดยการจัดทำดัชนีแถวจะเริ่มต้นด้วย 1 |
column | Integer | ดัชนีคอลัมน์ของเซลล์ที่จะแสดงผล โดยการจัดทำดัชนีคอลัมน์จะเริ่มต้นด้วย 1 |
รีเทิร์น
Range
- ช่วงที่มีเฉพาะเซลล์นี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Range(row, column, numRows)
แสดงผลช่วงที่มีเซลล์ด้านซ้ายบนที่พิกัดที่ระบุ และมีจำนวน แถวที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // When the "numRows" argument is used, only a single column of data is // returned. const range = sheet.getRange(1, 1, 3); const values = range.getValues(); // Prints 3 values from the first column, starting from row 1. for (const row in values) { for (const col in values[row]) { Logger.log(values[row][col]); } }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ดัชนีแถวเริ่มต้นของช่วง โดยการจัดทำดัชนีแถวจะเริ่มต้นด้วย 1 |
column | Integer | ดัชนีคอลัมน์ของช่วง โดยการจัดทำดัชนีคอลัมน์จะเริ่มต้นด้วย 1 |
num | Integer | จำนวนแถวที่จะแสดงผล |
รีเทิร์น
Range
— ช่วงที่มีคอลัมน์ข้อมูลเดียวที่มีจำนวนแถวที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Range(row, column, numRows, numColumns)
แสดงผลช่วงที่มีเซลล์ด้านซ้ายบนที่พิกัดที่กำหนดโดยมีจำนวนแถว และคอลัมน์ที่กำหนด
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; const range = sheet.getRange(1, 1, 3, 3); const values = range.getValues(); // Print values from a 3x3 box. for (const row in values) { for (const col in values[row]) { Logger.log(values[row][col]); } }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ดัชนีแถวเริ่มต้นของช่วง โดยการจัดทำดัชนีแถวจะเริ่มต้นด้วย 1 |
column | Integer | ดัชนีคอลัมน์เริ่มต้นของช่วง โดยการจัดทำดัชนีคอลัมน์จะเริ่มต้นด้วย 1 |
num | Integer | จำนวนแถวที่จะแสดงผล |
num | Integer | จำนวนคอลัมน์ที่จะแสดงผล |
รีเทิร์น
Range
— ช่วงที่สอดคล้องกับพื้นที่ที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Range(a1Notation)
แสดงผลช่วงตามที่ระบุในรูปแบบ A1 หรือ R1C1
// Get a range A1:D4 on sheet titled "Invoices" const ss = SpreadsheetApp.getActiveSpreadsheet(); const range = ss.getRange('Invoices!A1:D4'); // Get cell A1 on the first sheet const sheet = ss.getSheets()[0]; const cell = sheet.getRange('A1');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
a1Notation | String | ช่วงที่จะแสดงผลตามที่ระบุในรูปแบบ A1 หรือ R1C1 |
รีเทิร์น
Range
— ช่วงที่ตำแหน่งที่กำหนด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Range List(a1Notations)
แสดงผลคอลเล็กชัน Range
ที่แสดงช่วงในชีตเดียวกันซึ่งระบุโดยรายการสัญกรณ์ A1 หรือสัญกรณ์ R1C1 ที่ไม่ว่าง
// Get a list of ranges A1:D4, F1:H4. const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const rangeList = sheet.getRangeList(['A1:D4', 'F1:H4']);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
a1Notations | String[] | รายการช่วงที่จะแสดงผลตามที่ระบุในรูปแบบ A1 หรือ R1C1 |
รีเทิร์น
Range
— รายการช่วงที่สถานที่ที่กำหนด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Row Group(rowIndex, groupDepth)
แสดงผลกลุ่มแถวที่ดัชนีและความลึกของกลุ่มที่ระบุ
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // Returns the group whose control index is at row 2 and has a depth of 1, or // null if the group doesn’t exist. const rowGroup = sheet.getRowGroup(2, 1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ดัชนีแถวของปุ่มเปิด/ปิดการควบคุมกลุ่มหรือดัชนีภายในกลุ่ม |
group | Integer | ความลึกของกลุ่ม |
รีเทิร์น
Group
— กลุ่มแถวที่ดัชนีและความลึกของตัวควบคุม หรือแสดงข้อยกเว้นหากกลุ่ม
ไม่มีอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Row Group Control Position()
แสดงผล Group
สำหรับกลุ่มแถวทั้งหมดในชีต
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // GroupControlTogglePosition.AFTER if the row grouping control toggle is shown // after the group. const rowGroupControlPosition = sheet.getRowGroupControlPosition();
รีเทิร์น
Group
— true
หากสลับการควบคุมการจัดกลุ่มแถวจะแสดงหลังกลุ่มในชีตนี้
และ false
ในกรณีอื่นๆ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Row Group Depth(rowIndex)
แสดงผลระดับกลุ่มของแถวที่ดัชนีที่ระบุ
ความลึกของกลุ่มจะระบุจำนวนกลุ่มที่ทับซ้อนกับแถว โดยมีค่าตั้งแต่ 0 ถึง 8
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; // 1 if there is a group over rows 1 through 3 const groupDepth = sheet.getRowGroupDepth(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ดัชนีของแถว |
รีเทิร์น
Integer
— ความลึกของกลุ่มแถวที่ดัชนีที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Row Height(rowPosition)
รับความสูงเป็นพิกเซลของแถวที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Rows start at 1 Logger.log(sheet.getRowHeight(1));
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ตำแหน่งของแถวที่จะตรวจสอบ |
รีเทิร์น
Integer
— ความสูงของแถวเป็นพิกเซล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Selection()
แสดงผล Selection
ปัจจุบันในสเปรดชีต
const selection = SpreadsheetApp.getActiveSpreadsheet().getSelection(); const currentCell = selection.getCurrentCell();
รีเทิร์น
Selection
— รายการที่เลือกในปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Sheet Id()
แสดงผลรหัสของชีตที่ออบเจ็กต์นี้แสดง
ซึ่งเป็นรหัสของชีตที่ไม่ซ้ำกันสำหรับสเปรดชีต รหัสคือจำนวนเต็มที่เพิ่มขึ้นอย่างต่อเนื่อง
ซึ่งกำหนดเมื่อสร้างชีตและไม่ขึ้นอยู่กับตำแหน่งชีต ซึ่งจะมีประโยชน์เมื่อใช้ร่วมกับเมธอดต่างๆ เช่น Range.copyFormatToRange(gridId, column, columnEnd, row, rowEnd)
ที่ใช้พารามิเตอร์ grid
แทนอินสแตนซ์ Sheet
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; Logger.log(sheet.getSheetId());
รีเทิร์น
Integer
— รหัสของชีตที่ไม่ซ้ำกันในสเปรดชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Sheet Name()
แสดงผลชื่อชีต
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; Logger.log(sheet.getSheetName());
รีเทิร์น
String
— ชื่อของชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Sheet Values(startRow, startColumn, numRows, numColumns)
แสดงผลตารางกริดสี่เหลี่ยมของค่าสำหรับช่วงนี้โดยเริ่มที่พิกัดที่ระบุ ค่า -1 ที่ระบุเป็นตำแหน่งแถวหรือคอลัมน์จะเทียบเท่ากับการรับแถวหรือคอลัมน์สุดท้าย ที่มีข้อมูลในชีต
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // The two samples below produce the same output let values = sheet.getSheetValues(1, 1, 3, 3); Logger.log(values); const range = sheet.getRange(1, 1, 3, 3); values = range.getValues(); Logger.log(values);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
start | Integer | ตำแหน่งของแถวเริ่มต้น |
start | Integer | ตำแหน่งของคอลัมน์เริ่มต้น |
num | Integer | จำนวนแถวที่จะแสดงค่า |
num | Integer | จำนวนคอลัมน์ที่จะแสดงค่า |
รีเทิร์น
Object[][]
— อาร์เรย์สองมิติของค่า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Slicers()
แสดงผลอาร์เรย์ของ Slicer ในชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets all slicers in the spreadsheet. const slicers = sheet.getSlicers(); // Logs the slicer titles to the console. for (const slicer of slicers) { console.log(slicer.getTitle()); }
รีเทิร์น
Slicer[]
— รายการ Slicer ในชีตนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Tab Color Object()
รับสีแท็บชีต หรือ null
หากแท็บชีตไม่มีสี
// This example assumes there is a sheet named "Sheet1" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('Sheet1'); const color = first.getTabColorObject();
รีเทิร์น
Color
— สีแท็บชีต หรือ null
หากแท็บชีตไม่มีสี
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Type()
แสดงผลประเภทของชีต
ประเภทชีตเริ่มต้นคือ Sheet
ชีตที่มีออบเจ็กต์ฝังเพียงรายการเดียว เช่น Embedded
จะเป็นชีต Sheet
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; Logger.log(sheet.getType());
รีเทิร์น
Sheet
— ประเภทของชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
has Hidden Gridlines()
แสดงผล true
หากซ่อนเส้นตารางของชีตไว้ หรือแสดงผล false
ในกรณีอื่นๆ
เส้นตารางจะมองเห็นได้โดยค่าเริ่มต้น
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Checks if the spreadsheet has hidden gridelines and logs the result to the // console. console.log(sheet.hasHiddenGridlines());
รีเทิร์น
Boolean
— true
หากซ่อนเส้นตารางไว้ หรือ false
ในกรณีอื่นๆ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
hide Column(column)
ซ่อนคอลัมน์ในช่วงที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This hides the first column let range = sheet.getRange('A1'); sheet.hideColumn(range); // This hides the first 3 columns range = sheet.getRange('A:C'); sheet.hideColumn(range);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Range | ช่วงคอลัมน์ที่จะซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
hide Columns(columnIndex)
ซ่อนคอลัมน์เดียวที่ดัชนีที่ระบุ ใช้อินเด็กซ์ 1 สำหรับเมธอดนี้
หากต้องการซ่อนคอลัมน์มากกว่า 1 คอลัมน์โดยใช้ดัชนี ให้ใช้ hide
หากต้องการซ่อนคอลัมน์มากกว่า 1 คอลัมน์โดยใช้ช่วง ให้ใช้ hide
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Hides the first column sheet.hideColumns(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ดัชนีของคอลัมน์ที่จะซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
hide Columns(columnIndex, numColumns)
ซ่อนคอลัมน์ที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์โดยเริ่มจากดัชนีที่ระบุ ใช้อินเด็กซ์ 1 สำหรับเมธอดนี้
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Hides the first three columns sheet.hideColumns(1, 3);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ดัชนีเริ่มต้นของคอลัมน์ที่จะซ่อน |
num | Integer | จำนวนคอลัมน์ที่จะซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
hide Row(row)
ซ่อนแถวในช่วงที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This hides the first row const range = sheet.getRange('A1'); sheet.hideRow(range);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Range | ช่วงแถวที่จะซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
hide Rows(rowIndex)
ซ่อนแถวที่ดัชนีที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Hides the first row sheet.hideRows(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ดัชนีของแถวที่จะซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
hide Rows(rowIndex, numRows)
ซ่อนแถวที่ต่อเนื่องกันอย่างน้อย 1 แถวโดยเริ่มจากดัชนีที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Hides the first three rows sheet.hideRows(1, 3);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ดัชนีเริ่มต้นของแถวที่จะซ่อน |
num | Integer | จำนวนแถวที่จะซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
hide Sheet()
ซ่อนชีตนี้ ไม่มีผลหากซ่อนชีตอยู่แล้ว หากเรียกใช้เมธอดนี้ใน ชีตที่มองเห็นได้เท่านั้น เมธอดจะส่งข้อยกเว้น
const sheet = SpreadsheetApp.getActiveSheet(); sheet.hideSheet();
รีเทิร์น
Sheet
— ชีตปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Chart(chart)
เพิ่มแผนภูมิใหม่ลงในชีตนี้
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This creates a simple bar chart from the first three rows // of the first two columns of the spreadsheet const chart = sheet.newChart() .setChartType(Charts.ChartType.BAR) .addRange(sheet.getRange('A1:B4')) .setPosition(5, 5, 0, 0) .setOption('title', 'Dynamic Chart') .build(); sheet.insertChart(chart);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
chart | Embedded | แผนภูมิที่จะแทรก |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Column After(afterPosition)
แทรกคอลัมน์หลังตำแหน่งคอลัมน์ที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This inserts a column after the first column position sheet.insertColumnAfter(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
after | Integer | คอลัมน์ที่ควรเพิ่มคอลัมน์ใหม่ต่อจากนั้น |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Column Before(beforePosition)
แทรกคอลัมน์ก่อนตำแหน่งคอลัมน์ที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This inserts a column in the first column position sheet.insertColumnBefore(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
before | Integer | คอลัมน์ก่อนหน้าคอลัมน์ใหม่ที่ควรเพิ่ม |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Columns(columnIndex)
แทรกคอลัมน์ว่างในชีตที่ตำแหน่งที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Shifts all columns by one sheet.insertColumns(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ดัชนีที่ระบุตำแหน่งที่จะแทรกคอลัมน์ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Columns(columnIndex, numColumns)
แทรกคอลัมน์ว่างที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์ในชีตโดยเริ่มจากตำแหน่งที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Shifts all columns by three sheet.insertColumns(1, 3);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ดัชนีที่ระบุตำแหน่งที่จะแทรกคอลัมน์ |
num | Integer | จำนวนคอลัมน์ที่จะแทรก |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Columns After(afterPosition, howMany)
แทรกคอลัมน์ตามจำนวนที่ระบุหลังจากตำแหน่งคอลัมน์ที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Inserts two columns after the first column on the first sheet of the // spreadsheet. sheet.insertColumnsAfter(1, 2);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
after | Integer | คอลัมน์ที่ควรเพิ่มคอลัมน์ใหม่ต่อจากนั้น |
how | Integer | จำนวนคอลัมน์ที่จะแทรก |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Columns Before(beforePosition, howMany)
แทรกคอลัมน์จำนวนหนึ่งก่อนตำแหน่งคอลัมน์ที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This inserts five columns before the first column sheet.insertColumnsBefore(1, 5);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
before | Integer | คอลัมน์ก่อนหน้าคอลัมน์ใหม่ที่ควรเพิ่ม |
how | Integer | จำนวนคอลัมน์ที่จะแทรก |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Image(blobSource, column, row)
แทรก Blob
เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ ระบบจะดึงข้อมูลขนาดรูปภาพ
จากเนื้อหา Blob ขนาดของ BLOB สูงสุดที่รองรับคือ 2 MB
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; const binaryData = []; // TODO(developer): Replace with your binary data. const blob = Utilities.newBlob(binaryData, 'image/png', 'MyImageName'); sheet.insertImage(blob, 1, 1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
blob | Blob | Blob ที่มีเนื้อหารูปภาพ, ประเภท MIME และ (ไม่บังคับ) ชื่อ |
column | Integer | ตำแหน่งคอลัมน์ |
row | Integer | ตำแหน่งแถว |
รีเทิร์น
Over
— รูปภาพที่แทรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Image(blobSource, column, row, offsetX, offsetY)
แทรก Blob
เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ โดยมีออฟเซ็ต
พิกเซล ระบบจะดึงขนาดรูปภาพจากเนื้อหา Blob ขนาดของ BLOB ต้องไม่เกิน 2 MB
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; const binaryData = []; // TODO(developer): Replace with your binary data. const blob = Utilities.newBlob(binaryData, 'image/png', 'MyImageName'); sheet.insertImage(blob, 1, 1, 10, 10);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
blob | Blob | Blob ที่มีเนื้อหารูปภาพ, ประเภท MIME และ (ไม่บังคับ) ชื่อ |
column | Integer | ตำแหน่งคอลัมน์ |
row | Integer | ตำแหน่งแถว |
offsetX | Integer | ออฟเซ็ตแนวนอนจากมุมเซลล์เป็นพิกเซล |
offsetY | Integer | ออฟเซ็ตแนวตั้งจากมุมของเซลล์ในหน่วยพิกเซล |
รีเทิร์น
Over
— รูปภาพที่แทรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Image(url, column, row)
แทรกรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ
URL ที่ระบุต้องเข้าถึงได้แบบสาธารณะ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; sheet.insertImage('https://www.google.com/images/srpr/logo3w.png', 1, 1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
url | String | URL ของรูปภาพ |
column | Integer | ตำแหน่งคอลัมน์กริด |
row | Integer | ตำแหน่งแถวของตารางกริด |
รีเทิร์น
Over
— รูปภาพที่แทรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Image(url, column, row, offsetX, offsetY)
แทรกรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ โดยมีค่าออฟเซ็ตเป็นพิกเซล
URL ที่ระบุต้องเข้าถึงได้แบบสาธารณะ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; sheet.insertImage( 'https://www.google.com/images/srpr/logo3w.png', 1, 1, 10, 10, );
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
url | String | URL ของรูปภาพ |
column | Integer | ตำแหน่งคอลัมน์ |
row | Integer | ตำแหน่งแถว |
offsetX | Integer | ออฟเซ็ตแนวนอนจากมุมเซลล์เป็นพิกเซล |
offsetY | Integer | ออฟเซ็ตแนวตั้งจากมุมของเซลล์ในหน่วยพิกเซล |
รีเทิร์น
Over
— รูปภาพที่แทรก
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Row After(afterPosition)
แทรกแถวหลังตำแหน่งแถวที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This inserts a row after the first row position sheet.insertRowAfter(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
after | Integer | แถวที่ควรเพิ่มแถวใหม่ต่อจาก |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Row Before(beforePosition)
แทรกแถวก่อนตำแหน่งแถวที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This inserts a row before the first row position sheet.insertRowBefore(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
before | Integer | แถวก่อนหน้าแถวใหม่ที่ควรเพิ่ม |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Rows(rowIndex)
แทรกแถวว่างในชีตที่ตำแหน่งที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Shifts all rows down by one sheet.insertRows(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ดัชนีที่ระบุตำแหน่งที่จะแทรกแถว |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Rows(rowIndex, numRows)
แทรกแถวว่างที่ต่อเนื่องกันอย่างน้อย 1 แถวในชีตโดยเริ่มจากตำแหน่งที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Shifts all rows down by three sheet.insertRows(1, 3);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ดัชนีที่ระบุตำแหน่งที่จะแทรกแถว |
num | Integer | จำนวนแถวที่จะแทรก |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Rows After(afterPosition, howMany)
แทรกจำนวนแถวหลังจากตำแหน่งแถวที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This inserts five rows after the first row sheet.insertRowsAfter(1, 5);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
after | Integer | แถวที่ควรเพิ่มแถวใหม่ต่อจากนั้น |
how | Integer | จำนวนแถวที่จะแทรก |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Rows Before(beforePosition, howMany)
แทรกจำนวนแถวก่อนตำแหน่งแถวที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This inserts five rows before the first row sheet.insertRowsBefore(1, 5);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
before | Integer | แถวก่อนหน้าแถวใหม่ที่ควรเพิ่ม |
how | Integer | จำนวนแถวที่จะแทรก |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Slicer(range, anchorRowPos, anchorColPos)
เพิ่ม Slicer ใหม่ลงในชีตนี้
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets the range of the sheet. const range = sheet.getRange('A1:D10'); // Inserts the slicer with a random range into the sheet. const insertSlicers = sheet.insertSlicer(range.randomize(), 1, 10); // Logs the insert slicer result to the console. console.log(insertSlicers);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
range | Range | ช่วงที่สร้างตัวควบคุมตัวกรองทางด้านขวา |
anchor | Integer | ด้านบนของตัวแบ่งส่วนข้อมูลจะยึดไว้ในแถวนี้ |
anchor | Integer | ด้านบนของตัวแบ่งส่วนข้อมูลจะยึดไว้ในคอลัมน์นี้ |
รีเทิร์น
Slicer
- ตัวควบคุมตัวกรองที่แทรกใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Slicer(range, anchorRowPos, anchorColPos, offsetX, offsetY)
เพิ่ม Slicer ใหม่ลงในชีตนี้
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets the range. const range = sheet.getRange('A1:D10'); // Inserts a slicer using the random range function. const insertSlicers = sheet.insertSlicer(range.randomize(), 1, 10, 0, 0); // Logs the insert slicer result to the console. console.log(insertSlicers);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
range | Range | ช่วงที่สร้างตัวควบคุมตัวกรองทางด้านขวา |
anchor | Integer | ด้านบนของตัวแบ่งส่วนข้อมูลจะยึดไว้ในแถวนี้ |
anchor | Integer | ด้านบนของตัวแบ่งส่วนข้อมูลจะยึดไว้ในคอลัมน์นี้ |
offsetX | Integer | ออฟเซ็ตแนวนอนจากมุมเซลล์เป็นพิกเซล |
offsetY | Integer | ออฟเซ็ตแนวตั้งจากมุมของเซลล์ในหน่วยพิกเซล |
รีเทิร์น
Slicer
- ตัวควบคุมตัวกรองที่แทรกใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
is Column Hidden By User(columnPosition)
แสดงผลว่าผู้ใช้ซ่อนคอลัมน์ที่ระบุหรือไม่
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Columns start at 1 Logger.log(sheet.isColumnHiddenByUser(1));
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ตำแหน่งของคอลัมน์ที่จะตรวจสอบ |
รีเทิร์น
Boolean
— true
หากคอลัมน์ซ่อนอยู่ false
ในกรณีอื่นๆ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
is Right To Left()
แสดงผล true
หากเลย์เอาต์ชีตนี้เป็นจากขวาไปซ้าย แสดง false
หากชีต
ใช้เลย์เอาต์จากซ้ายไปขวาเริ่มต้น
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Checks if a spreadsheet is ordered from right to left and logs the result to // the console. console.log(sheet.isRightToLeft());
รีเทิร์น
Boolean
— true
หากเป็นภาษาที่อ่านจากขวาไปซ้าย หรือ false
ในกรณีอื่นๆ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
is Row Hidden By Filter(rowPosition)
แสดงว่าแถวที่ระบุซ่อนอยู่ตามตัวกรอง (ไม่ใช่มุมมองตัวกรอง) หรือไม่
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Rows start at 1 Logger.log(sheet.isRowHiddenByFilter(1));
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ตำแหน่งของแถวที่จะตรวจสอบ |
รีเทิร์น
Boolean
— true
หากซ่อนแถวไว้ false
หากไม่ซ่อน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
is Row Hidden By User(rowPosition)
แสดงผลว่าผู้ใช้ซ่อนแถวที่ระบุหรือไม่
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Rows start at 1 Logger.log(sheet.isRowHiddenByUser(1));
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ตำแหน่งของแถวที่จะตรวจสอบ |
รีเทิร์น
Boolean
— true
หากซ่อนแถวไว้ false
หากไม่ซ่อน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
is Sheet Hidden()
แสดง true
หากชีตซ่อนอยู่
const sheet = SpreadsheetApp.getActiveSheet(); if (sheet.isSheetHidden()) { // do something... }
รีเทิร์น
Boolean
— true
หากชีตซ่อนอยู่ หรือ false
หากชีตไม่ได้ซ่อนอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
move Columns(columnSpec, destinationIndex)
ย้ายคอลัมน์ที่เลือกตามช่วงที่ระบุไปยังตำแหน่งที่ระบุโดย destination
column
ไม่จำเป็นต้องแสดงทั้งคอลัมน์หรือกลุ่มคอลัมน์ทั้งหมดอย่างถูกต้องเพื่อที่จะย้าย แต่จะเลือกคอลัมน์ทั้งหมดที่ช่วงครอบคลุม
// The code below moves rows A-B to destination index 5. // This results in those columns becoming columns C-D. const sheet = SpreadsheetApp.getActiveSheet(); // Selects column A and column B to be moved. const columnSpec = sheet.getRange('A1:B1'); sheet.moveColumns(columnSpec, 5);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Range | ช่วงที่ครอบคลุมคอลัมน์ที่ควรย้าย |
destination | Integer | ดัชนีที่ควรย้ายคอลัมน์ไป โปรดทราบว่าดัชนีนี้อิงตามพิกัดก่อนที่จะย้ายคอลัมน์ ระบบจะเลื่อนข้อมูลที่มีอยู่ไปทางขวาเพื่อ เว้นที่ว่างสำหรับคอลัมน์ที่ย้าย ในขณะที่นำคอลัมน์แหล่งที่มาจากตารางกริด ดังนั้น ข้อมูลอาจไปอยู่ในดัชนีอื่นที่ไม่ใช่ดัชนีที่ระบุไว้เดิม |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
move Rows(rowSpec, destinationIndex)
ย้ายแถวที่เลือกตามช่วงที่ระบุไปยังตำแหน่งที่ระบุโดย destination
row
เองไม่จำเป็นต้องแสดงทั้งแถว
หรือกลุ่มของแถวที่จะย้ายอย่างถูกต้อง แต่จะเลือกแถวทั้งหมดที่ช่วงครอบคลุม
// The code below moves rows 1-2 to destination index 5. // This results in those rows becoming rows 3-4. const sheet = SpreadsheetApp.getActiveSheet(); // Selects row 1 and row 2 to be moved. const rowSpec = sheet.getRange('A1:A2'); sheet.moveRows(rowSpec, 5);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Range | ช่วงที่ครอบคลุมแถวที่ควรย้าย |
destination | Integer | ดัชนีที่ควรย้ายแถวไป โปรดทราบว่าดัชนีนี้อิงตามพิกัดก่อนที่จะย้ายแถว ระบบจะเลื่อนข้อมูลที่มีอยู่ลงมาเพื่อ เว้นที่ว่างสำหรับแถวที่ย้าย ในขณะที่นำแถวต้นฉบับออกจากตารางกริด ดังนั้น ข้อมูลอาจไปอยู่ในดัชนีอื่นที่ไม่ใช่ดัชนีที่ระบุไว้แต่แรก |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
new Chart()
แสดงผล Builder เพื่อสร้างแผนภูมิใหม่สำหรับชีตนี้
ตัวอย่างนี้แสดงวิธีสร้างแผนภูมิใหม่
const sheet = SpreadsheetApp.getActiveSheet(); const range = sheet.getRange('A1:B8'); const chartBuilder = sheet.newChart(); chartBuilder.addRange(range) .setChartType(Charts.ChartType.LINE) .setPosition(2, 2, 0, 0) .setOption('title', 'My Line Chart!'); sheet.insertChart(chartBuilder.build());
รีเทิร์น
Embedded
- เครื่องมือสร้างเพื่อสร้างแผนภูมิใหม่
protect()
สร้างออบเจ็กต์ที่ป้องกันไม่ให้มีการแก้ไขชีตได้ ยกเว้นผู้ใช้ที่มี
สิทธิ์ จนกว่าสคริปต์จะเปลี่ยนรายชื่อผู้แก้ไขชีตจริงๆ (โดยการเรียกใช้
Protection.removeEditor(emailAddress)
, Protection.removeEditor(user)
, Protection.removeEditors(emailAddresses)
, Protection.addEditor(emailAddress)
, Protection.addEditor(user)
, Protection.addEditors(emailAddresses)
หรือการตั้งค่า
ค่าใหม่สำหรับ Protection.setDomainEdit(editable)
) สิทธิ์จะเหมือนกับสิทธิ์ของ
สเปรดชีตเอง ซึ่งหมายความว่าชีตจะยังคงไม่ได้รับการปกป้อง หากชีตได้รับการป้องกันอยู่แล้ว วิธีนี้จะแสดงออบเจ็กต์ที่แสดงการตั้งค่าการป้องกันที่มีอยู่
ชีตที่ป้องกันอาจมีภูมิภาคที่ไม่ได้ป้องกัน
// Protect the active sheet, then remove all other users from the list of // editors. const sheet = SpreadsheetApp.getActiveSheet(); const protection = sheet.protect().setDescription('Sample protected sheet'); // Ensure the current user is an editor before removing others. Otherwise, if // the user's edit permission comes from a group, the script throws an exception // upon removing the group. const me = Session.getEffectiveUser(); protection.addEditor(me); protection.removeEditors(protection.getEditors()); if (protection.canDomainEdit()) { protection.setDomainEdit(false); }
รีเทิร์น
Protection
- ออบเจ็กต์ที่แสดงการตั้งค่าการป้องกัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove Chart(chart)
นำแผนภูมิออกจากชีตหลัก
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This removes all the embedded charts from the spreadsheet const charts = sheet.getCharts(); for (const i in charts) { sheet.removeChart(charts[i]); }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
chart | Embedded | แผนภูมิที่จะนำออก |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Active Range(range)
กำหนดช่วงที่ระบุเป็นactive range
ในชีตที่ใช้งานอยู่ โดยมีเซลล์ซ้ายบนสุดในช่วงเป็นcurrent cell
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const range = sheet.getRange('A1:D4'); sheet.setActiveRange(range); const selection = sheet.getSelection(); // Current cell: A1 const currentCell = selection.getCurrentCell(); // Active Range: A1:D4 const activeRange = selection.getActiveRange();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
range | Range | ช่วงที่จะตั้งเป็นช่วงที่ใช้งานอยู่ |
รีเทิร์น
Range
- ช่วงที่เพิ่งเปิดใช้งาน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Active Range List(rangeList)
ตั้งค่ารายการช่วงที่ระบุเป็น active ranges
ในชีตที่ใช้งานอยู่ ช่วงสุดท้ายในรายการจะได้รับการตั้งค่าเป็น active range
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['D4', 'B2:C4']); sheet.setActiveRangeList(rangeList); const selection = sheet.getSelection(); // Current cell: B2 const currentCell = selection.getCurrentCell(); // Active range: B2:C4 const activeRange = selection.getActiveRange(); // Active range list: [D4, B2:C4] const activeRangeList = selection.getActiveRangeList();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
range | Range | รายการช่วงที่จะเลือก |
รีเทิร์น
Range
— รายการช่วงที่เลือกใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Active Selection(range)
ตั้งค่าภูมิภาคที่เลือกที่ใช้งานอยู่สำหรับชีตนี้
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; const range = sheet.getRange('A1:D4'); sheet.setActiveSelection(range);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
range | Range | ช่วงที่จะตั้งค่าเป็นการเลือกที่ใช้งานอยู่ |
รีเทิร์น
Range
- ช่วงที่เพิ่งเปิดใช้งาน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Active Selection(a1Notation)
ตั้งค่าการเลือกที่ใช้งานอยู่ตามที่ระบุในรูปแบบ A1 หรือ R1C1
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; sheet.setActiveSelection('A1:D4');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
a1Notation | String | ช่วงที่จะตั้งค่าเป็นใช้งานอยู่ตามที่ระบุในรูปแบบ A1 หรือ R1C1 |
รีเทิร์น
Range
- ช่วงที่เพิ่งเปิดใช้งาน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Column Group Control Position(position)
กำหนดตำแหน่งของปุ่มเปิด/ปิดการควบคุมกลุ่มคอลัมน์ในชีต
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; sheet.setColumnGroupControlPosition( SpreadsheetApp.GroupControlTogglePosition.AFTER, );
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
position | Group | ตำแหน่งของปุ่มสลับการควบคุมกลุ่มคอลัมน์ |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Column Width(columnPosition, width)
กำหนดความกว้างของคอลัมน์ที่ระบุเป็นพิกเซล
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Sets the first column to a width of 200 pixels sheet.setColumnWidth(1, 200);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ตำแหน่งของคอลัมน์ที่ต้องการตั้งค่า |
width | Integer | ความกว้างเป็นพิกเซลที่จะตั้งค่า |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Column Widths(startColumn, numColumns, width)
กำหนดความกว้างของคอลัมน์ที่ระบุในหน่วยพิกเซล
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Sets the first three columns to a width of 200 pixels sheet.setColumnWidths(1, 3, 200);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
start | Integer | ตำแหน่งคอลัมน์เริ่มต้นที่จะเปลี่ยน |
num | Integer | จำนวนคอลัมน์ที่จะเปลี่ยน |
width | Integer | ความกว้างเป็นพิกเซลที่จะตั้งค่า |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Conditional Format Rules(rules)
แทนที่กฎการจัดรูปแบบตามเงื่อนไขที่มีอยู่ในชีตทั้งหมดด้วยกฎที่ป้อน ระบบจะประเมินกฎตามลำดับอินพุต
// Remove one of the existing conditional format rules. const sheet = SpreadsheetApp.getActiveSheet(); const rules = sheet.getConditionalFormatRules(); rules.splice(1, 1); // Deletes the 2nd format rule. sheet.setConditionalFormatRules(rules);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
rules | Conditional | กฎการจัดรูปแบบตามเงื่อนไขใหม่ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Current Cell(cell)
ตั้งค่าเซลล์ที่ระบุเป็น current cell
หากเซลล์ที่ระบุอยู่ในช่วงที่เลือกไว้แล้ว ช่วงนั้นจะกลายเป็น ช่วงที่ใช้งานอยู่โดยมีเซลล์ดังกล่าวเป็นเซลล์ปัจจุบัน
หากเซลล์ที่ระบุไม่อยู่ในช่วงที่เลือก ระบบจะนำการเลือกที่มีอยู่ออก และเซลล์นั้นจะกลายเป็นเซลล์ปัจจุบันและช่วงที่ใช้งานอยู่
หมายเหตุ: Range
ที่ระบุต้องประกอบด้วยเซลล์เดียว ไม่เช่นนั้นระบบจะแสดงข้อยกเว้น
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const cell = sheet.getRange('B5'); sheet.setCurrentCell(cell); const selection = sheet.getSelection(); // Current cell: B5 const currentCell = selection.getCurrentCell();
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
cell | Range | เซลล์ที่จะตั้งเป็นเซลล์ปัจจุบัน |
รีเทิร์น
Range
— เซลล์ปัจจุบันที่ตั้งค่าใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Frozen Columns(columns)
ตรึงจำนวนคอลัมน์ที่ระบุ หากเป็น 0 ระบบจะไม่ตรึงคอลัมน์ใดๆ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Freezes the first column sheet.setFrozenColumns(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
columns | Integer | จำนวนคอลัมน์ที่จะตรึง |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Frozen Rows(rows)
ตรึงจำนวนแถวที่ระบุ หากเป็น 0 ระบบจะไม่ตรึงแถวใดเลย
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Freezes the first row sheet.setFrozenRows(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
rows | Integer | จำนวนแถวที่จะตรึง |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Hidden Gridlines(hideGridlines)
ซ่อนหรือแสดงเส้นตารางแผ่นงาน
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can us eSpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Hides the gridlines in the sheet. sheet.setHiddenGridlines(true);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
hide | Boolean | หาก true ให้ซ่อนเส้นตารางในชีตนี้ มิฉะนั้นให้แสดง
เส้นตาราง |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Name(name)
ตั้งชื่อชีต
// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.setName('not first anymore');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อใหม่ของชีต |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Right To Left(rightToLeft)
ตั้งค่าหรือยกเลิกการตั้งค่าเลย์เอาต์ชีตเป็นจากขวาไปซ้าย
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets a sheet by its name. const sheet = ss.getSheetByName('Sheet1'); // Sets the sheet layout, so that the sheet is ordered from right to left. sheet.setRightToLeft(true);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
right | Boolean | หากเป็น true ระบบจะตั้งค่าเลย์เอาต์ชีตเป็นจากขวาไปซ้าย โดยมีเซลล์ A1 อยู่ที่
มุมขวาบน หากเป็น false ระบบจะตั้งค่าเลย์เอาต์ชีตเป็นค่าเริ่มต้น
จากซ้ายไปขวา โดยมีเซลล์ A1 อยู่ที่ด้านซ้ายบน |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Row Group Control Position(position)
ตั้งค่าตำแหน่งของปุ่มเปิด/ปิดการควบคุมกลุ่มแถวในชีต
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; sheet.setRowGroupControlPosition( SpreadsheetApp.GroupControlTogglePosition.AFTER, );
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
position | Group | ตำแหน่งของปุ่มเปิด/ปิดการควบคุมกลุ่มแถว |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Row Height(rowPosition, height)
กำหนดความสูงของแถวที่ระบุเป็นพิกเซล โดยค่าเริ่มต้น แถวจะขยายให้พอดีกับเนื้อหาของเซลล์ หากต้องการบังคับให้แถวมีความสูงที่ระบุ ให้ใช้ set
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Sets the first row to a height of 200 pixels sheet.setRowHeight(1, 200);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ตำแหน่งแถวที่จะเปลี่ยน |
height | Integer | ความสูงเป็นพิกเซลที่จะตั้งค่า |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Row Heights(startRow, numRows, height)
กำหนดความสูงของแถวที่ระบุเป็นพิกเซล โดยค่าเริ่มต้น แถวจะขยายให้พอดีกับเนื้อหาของเซลล์ หากต้องการบังคับให้แถวมีความสูงที่ระบุ ให้ใช้ set
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Sets the first three rows to a height of 20 pixels sheet.setRowHeights(1, 3, 20);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
start | Integer | ตำแหน่งแถวเริ่มต้นที่จะเปลี่ยน |
num | Integer | จำนวนแถวที่จะเปลี่ยน |
height | Integer | ความสูงเป็นพิกเซลที่จะตั้งค่า |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Row Heights Forced(startRow, numRows, height)
กำหนดความสูงของแถวที่ระบุเป็นพิกเซล โดยค่าเริ่มต้น แถวจะขยายให้พอดีกับเนื้อหาของเซลล์ เมื่อ
คุณใช้ set
ระบบจะบังคับให้แถวมีความสูงตามที่ระบุ แม้ว่าเนื้อหาในเซลล์จะสูงกว่าความสูงของแถว
ก็ตาม
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Sets the first three rows to a height of 5 pixels. sheet.setRowHeightsForced(1, 3, 5);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
start | Integer | ตำแหน่งแถวเริ่มต้นที่จะเปลี่ยน |
num | Integer | จำนวนแถวที่จะเปลี่ยน |
height | Integer | ความสูงเป็นพิกเซลที่จะตั้งค่า |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Tab Color(color)
ตั้งค่าสีแท็บแผ่นงาน
// This example assumes there is a sheet named "first" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('first'); first.setTabColor('ff0000'); // Set the color to red. first.setTabColor(null); // Unset the color.
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | String | รหัสสีในรูปแบบ CSS (เช่น '#ffffff' หรือ 'white' ) หรือ
null เพื่อรีเซ็ตสีแท็บ |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Tab Color Object(color)
ตั้งค่าสีแท็บแผ่นงาน
// This example assumes there is a sheet named "Sheet1" const ss = SpreadsheetApp.getActiveSpreadsheet(); const first = ss.getSheetByName('Sheet1'); const color = SpreadsheetApp.newColor() .setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1) .build(); first.setTabColorObject(color); // Set the color to theme accent 1. first.setTabColorObject(null); // Unset the color.
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
color | Color | สีแท็บแผ่นงานที่จะตั้งค่า |
รีเทิร์น
Sheet
— แผ่นงานนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
show Columns(columnIndex)
เลิกซ่อนคอลัมน์ที่ดัชนีที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Unhides the first column sheet.showColumns(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ดัชนีของคอลัมน์ที่จะเลิกซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
show Columns(columnIndex, numColumns)
เลิกซ่อนคอลัมน์ที่ต่อเนื่องกันอย่างน้อย 1 คอลัมน์โดยเริ่มจากดัชนีที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Unhides the first three columns sheet.showColumns(1, 3);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | ดัชนีเริ่มต้นของคอลัมน์ที่จะเลิกซ่อน |
num | Integer | จำนวนคอลัมน์ที่จะเลิกซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
show Rows(rowIndex)
เลิกซ่อนแถวที่ดัชนีที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Unhides the first row sheet.showRows(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ดัชนีของแถวที่จะเลิกซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
show Rows(rowIndex, numRows)
เลิกซ่อนแถวที่ต่อเนื่องกันอย่างน้อย 1 แถวโดยเริ่มจากดัชนีที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Unhides the first three rows sheet.showRows(1, 3);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ดัชนีเริ่มต้นของแถวที่จะเลิกซ่อน |
num | Integer | จำนวนแถวที่จะเลิกซ่อน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
show Sheet()
ทำให้ชีตปรากฏ ไม่มีผลหากชีตมองเห็นได้อยู่แล้ว
const sheet = SpreadsheetApp.getActiveSheet(); sheet.showSheet();
รีเทิร์น
Sheet
— ชีตปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
sort(columnPosition)
จัดเรียงชีตตามคอลัมน์จากน้อยไปมาก
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Sorts the sheet by the first column, ascending sheet.sort(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | คอลัมน์ที่จะใช้จัดเรียง |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
sort(columnPosition, ascending)
จัดเรียงชีตตามคอลัมน์ ใช้พารามิเตอร์เพื่อระบุการเรียงจากน้อยไปมากหรือมากไปน้อย
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Sorts the sheet by the first column, descending sheet.sort(1, false);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Integer | คอลัมน์ที่จะใช้จัดเรียง |
ascending | Boolean | true สำหรับการจัดเรียงจากน้อยไปหามาก false สำหรับการจัดเรียงจากมากไปหาน้อย |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
unhide Column(column)
เลิกซ่อนคอลัมน์ในช่วงที่กำหนด
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This unhides the first column if it was previously hidden const range = sheet.getRange('A1'); sheet.unhideColumn(range);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
column | Range | ช่วงที่จะเลิกซ่อน หากซ่อนอยู่ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
unhide Row(row)
เลิกซ่อนแถวในช่วงที่กำหนด
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This unhides the first row if it was previously hidden const range = sheet.getRange('A1'); sheet.unhideRow(range);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Range | ช่วงที่จะเลิกซ่อน หากซ่อนอยู่ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
update Chart(chart)
อัปเดตแผนภูมิในชีตนี้
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // This code is going to loop through all the charts and change them to // column charts const charts = sheet.getCharts(); for (const i in charts) { const chart = charts[i]; const newChart = chart.modify().setChartType(Charts.ChartType.COLUMN).build(); sheet.updateChart(newChart); }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
chart | Embedded | แผนภูมิที่จะอัปเดต |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets