เข้าถึงและแก้ไขไฟล์ Google ชีต การดำเนินการที่พบบ่อย ได้แก่ การเพิ่มชีตใหม่และการเพิ่ม ผู้ทำงานร่วมกัน
เมธอด
วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
---|---|---|
add | Spreadsheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ที่ระบุไปยังสเปรดชีตระดับบนสุด |
add | Spreadsheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์และการเปิดเผยที่ระบุลงในสเปรดชีต |
add | Spreadsheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์และค่าที่ระบุลงในสเปรดชีต |
add | Spreadsheet | เพิ่มข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่มีคีย์ ค่า และระดับการเข้าถึงที่ระบุลงในสเปรดชีต |
add | Spreadsheet | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อเอดิเตอร์สำหรับ Spreadsheet |
add | Spreadsheet | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อเอดิเตอร์สำหรับ Spreadsheet |
add | Spreadsheet | เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขสำหรับ Spreadsheet |
add | void | สร้างเมนูใหม่ใน UI ของสเปรดชีต |
add | Spreadsheet | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ชมของ Spreadsheet |
add | Spreadsheet | เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ชมของ Spreadsheet |
add | Spreadsheet | เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้ชมสำหรับ Spreadsheet |
append | Sheet | เพิ่มแถวที่ด้านล่างของเขตข้อมูลปัจจุบันในชีต |
auto | Sheet | ตั้งค่าความกว้างของคอลัมน์ที่ระบุให้พอดีกับเนื้อหา |
copy(name) | Spreadsheet | คัดลอกสเปรดชีตและส่งคืนสเปรดชีตใหม่ |
create | Developer | แสดงผล Developer สำหรับค้นหาข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ภายในขอบเขตของ
สเปรดชีตนี้ |
create | Text | สร้างเครื่องมือค้นหาข้อความสำหรับสเปรดชีต ซึ่งใช้เพื่อค้นหาและแทนที่ข้อความภายใน สเปรดชีตได้ |
delete | Sheet | ลบชีตที่ใช้งานอยู่ในปัจจุบัน |
delete | Sheet | ลบคอลัมน์ในตำแหน่งคอลัมน์ที่ระบุ |
delete | void | ลบคอลัมน์จำนวนหนึ่งโดยเริ่มจากตำแหน่งคอลัมน์ที่ระบุ |
delete | Sheet | ลบแถวในตำแหน่งแถวที่ระบุ |
delete | void | ลบจำนวนแถวที่เริ่มต้นที่ตำแหน่งแถวที่ระบุ |
delete | void | ลบชีตที่ระบุ |
duplicate | Sheet | ทำซ้ำชีตที่ใช้งานอยู่และทำให้เป็นชีตที่ใช้งานอยู่ |
get | Range | แสดงผลเซลล์ที่ใช้งานอยู่ในชีตนี้ |
get | Range | แสดงช่วงที่เลือกในชีตที่ใช้งานอยู่ หรือ null หากไม่มีช่วงที่ใช้งานอยู่ |
get | Range | แสดงรายการช่วงที่ใช้งานอยู่ในชีตที่ใช้งานอยู่ หรือ null หากไม่มีช่วงที่ใช้งานอยู่
|
get | Sheet | รับชีตที่ใช้งานอยู่ในสเปรดชีต |
get | Blob | แสดงผลข้อมูลภายในออบเจ็กต์นี้เป็น Blob ที่แปลงเป็นประเภทเนื้อหาที่ระบุ |
get | Banding[] | แสดงการแบนทั้งหมดในสเปรดชีตนี้ |
get | Blob | ส่งคืนข้อมูลภายในออบเจ็กต์นี้เป็น Blob |
get | Integer | รับความกว้างเป็นพิกเซลของคอลัมน์ที่ระบุ |
get | Range | แสดงผลเซลล์ปัจจุบันในชีตที่ใช้งานอยู่หรือ null หากไม่มีเซลล์ปัจจุบัน |
get | Range | แสดงผล Range ที่สอดคล้องกับมิติข้อมูลที่มีข้อมูล |
get | Data | รับสูตรแหล่งข้อมูลทั้งหมด |
get | Data | รับตาราง Pivot ของแหล่งข้อมูลทั้งหมด |
get | Data | รับกำหนดเวลาการรีเฟรชของสเปรดชีตนี้ |
get | Data | แสดงผลชีตแหล่งข้อมูลทั้งหมดในสเปรดชีต |
get | Data | รับตารางแหล่งข้อมูลทั้งหมด |
get | Data | แสดงผลแหล่งข้อมูลทั้งหมดในสเปรดชีต |
get | Developer | รับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่เชื่อมโยงกับสเปรดชีตระดับบนสุด |
get | User[] | รับรายชื่อเอดิเตอร์สำหรับ Spreadsheet นี้ |
get | String | แสดง URL ของแบบฟอร์มที่ส่งคำตอบไปยังสเปรดชีตนี้ หรือ null หากสเปรดชีตนี้ไม่มีแบบฟอร์มที่เชื่อมโยง |
get | Integer | แสดงผลจำนวนคอลัมน์ที่ตรึง |
get | Integer | แสดงผลจำนวนแถวที่ตรึง |
get | String | รับตัวระบุที่ไม่ซ้ำกันสำหรับสเปรดชีตนี้ |
get | Over | แสดงรูปภาพทั้งหมดที่อยู่นอกตารางกริดในชีต |
get | Number | แสดงผลค่าเกณฑ์ที่ใช้ระหว่างการคำนวณแบบวนซ้ำ |
get | Integer | แสดงตำแหน่งของคอลัมน์สุดท้ายที่มีเนื้อหา |
get | Integer | แสดงตำแหน่งของแถวสุดท้ายที่มีเนื้อหา |
get | Integer | แสดงผลจำนวนการทำซ้ำสูงสุดที่จะใช้ในระหว่างการคำนวณซ้ำ |
get | String | รับชื่อของเอกสาร |
get | Named | รับช่วงที่ตั้งชื่อทั้งหมดในสเปรดชีตนี้ |
get | Integer | แสดงผลจำนวนชีตในสเปรดชีตนี้ |
get | User | แสดงเจ้าของเอกสาร หรือ null สำหรับเอกสารในไดรฟ์ที่แชร์ |
get | Spreadsheet | แสดงผลรายการธีมที่กำหนดไว้ล่วงหน้า |
get | Protection[] | รับอาร์เรย์ของออบเจ็กต์ที่แสดงช่วงหรือชีตที่ป้องกันทั้งหมดในสเปรดชีต |
get | Range | แสดงผลช่วงตามที่ระบุในรูปแบบ A1 หรือ R1C1 |
get | Range | แสดงผลช่วงที่มีชื่อ หรือ null หากไม่พบช่วงที่มีชื่อที่ระบุ |
get | Range | แสดงผลคอลเล็กชัน Range ที่แสดงช่วงในชีตเดียวกันซึ่งระบุโดยรายการสัญกรณ์ A1 หรือสัญกรณ์ R1C1 ที่ไม่ว่าง |
get | Recalculation | แสดงช่วงเวลาการคำนวณสำหรับสเปรดชีตนี้ |
get | Integer | รับความสูงเป็นพิกเซลของแถวที่ระบุ |
get | Selection | แสดงผล Selection ปัจจุบันในสเปรดชีต |
get | Sheet | รับชีตที่มีรหัสที่ระบุ |
get | Sheet | แสดงผลชีตที่มีชื่อที่ระบุ |
get | Integer | แสดงผลรหัสของชีตที่ออบเจ็กต์นี้แสดง |
get | String | แสดงผลชื่อชีต |
get | Object[][] | แสดงผลตารางกริดสี่เหลี่ยมของค่าสำหรับช่วงนี้โดยเริ่มที่พิกัดที่ระบุ |
get | Sheet[] | รับชีตทั้งหมดในสเปรดชีตนี้ |
get | String | รับภาษาของสเปรดชีต |
get | Spreadsheet | แสดงผลธีมปัจจุบันของสเปรดชีต หรือ null หากไม่มีการใช้ธีม |
get | String | รับเขตเวลาของสเปรดชีต |
get | String | แสดงผล URL สำหรับสเปรดชีตที่ระบุ |
get | User[] | รับรายการผู้มีสิทธิ์อ่านและผู้แสดงความคิดเห็นสำหรับ Spreadsheet นี้ |
hide | void | ซ่อนคอลัมน์ในช่วงที่ระบุ |
hide | void | ซ่อนแถวในช่วงที่ระบุ |
insert | Sheet | แทรกคอลัมน์หลังตำแหน่งคอลัมน์ที่ระบุ |
insert | Sheet | แทรกคอลัมน์ก่อนตำแหน่งคอลัมน์ที่ระบุ |
insert | Sheet | แทรกคอลัมน์ตามจำนวนที่ระบุหลังจากตำแหน่งคอลัมน์ที่ระบุ |
insert | Sheet | แทรกคอลัมน์จำนวนหนึ่งก่อนตำแหน่งคอลัมน์ที่ระบุ |
insert | Data | แทรก Data ใหม่ในสเปรดชีตและเริ่มการดำเนินการข้อมูล |
insert | Over | แทรก Spreadsheet เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ |
insert | Over | แทรก Spreadsheet เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ โดยมีออฟเซ็ต
พิกเซล |
insert | Over | แทรกรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ |
insert | Over | แทรกรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ โดยมีค่าออฟเซ็ตเป็นพิกเซล |
insert | Sheet | แทรกแถวหลังตำแหน่งแถวที่ระบุ |
insert | Sheet | แทรกแถวก่อนตำแหน่งแถวที่ระบุ |
insert | Sheet | แทรกจำนวนแถวหลังจากตำแหน่งแถวที่ระบุ |
insert | Sheet | แทรกจำนวนแถวก่อนตำแหน่งแถวที่ระบุ |
insert | Sheet | แทรกแผ่นงานใหม่ลงในสเปรดชีตโดยใช้ชื่อแผ่นงานเริ่มต้น |
insert | Sheet | แทรกชีตใหม่ลงในสเปรดชีตที่ดัชนีที่ระบุ |
insert | Sheet | แทรกชีตใหม่ลงในสเปรดชีตที่ดัชนีที่ระบุและใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ |
insert | Sheet | แทรกแผ่นงานใหม่ลงในสเปรดชีตโดยใช้ชื่อแผ่นงานเริ่มต้นและอาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ |
insert | Sheet | แทรกชีตใหม่ลงในสเปรดชีตโดยใช้ชื่อที่ระบุ |
insert | Sheet | แทรกชีตใหม่ลงในสเปรดชีตโดยใช้ชื่อที่ระบุในดัชนีที่ระบุ |
insert | Sheet | แทรกชีตใหม่ลงในสเปรดชีตโดยใช้ชื่อที่ระบุในดัชนีที่ระบุ และใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ |
insert | Sheet | แทรกชีตใหม่ลงในสเปรดชีตโดยใช้ชื่อที่ระบุและใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ |
insert | Sheet | แทรกชีตใหม่ในสเปรดชีต สร้าง Data ครอบคลุม
ทั้งชีตด้วยข้อกำหนดแหล่งข้อมูลที่ระบุ และเริ่มการดำเนินการข้อมูล |
is | Boolean | แสดงผลว่าผู้ใช้ซ่อนคอลัมน์ที่ระบุหรือไม่ |
is | Boolean | แสดงผลว่าเปิดใช้งานการคำนวณซ้ำในสเปรดชีตนี้หรือไม่ |
is | Boolean | แสดงว่าแถวที่ระบุซ่อนอยู่ตามตัวกรอง (ไม่ใช่มุมมองตัวกรอง) หรือไม่ |
is | Boolean | แสดงผลว่าผู้ใช้ซ่อนแถวที่ระบุหรือไม่ |
move | void | ย้ายชีตที่ใช้งานอยู่ไปยังตำแหน่งที่ระบุในรายการชีต |
move | Sheet | สร้างชีต Sheet ใหม่และย้ายแผนภูมิที่ระบุไปยังชีตนั้น |
refresh | void | รีเฟรชแหล่งข้อมูลที่รองรับทั้งหมดและออบเจ็กต์แหล่งข้อมูลที่ลิงก์ โดยข้ามออบเจ็กต์แหล่งข้อมูลที่ไม่ถูกต้อง |
remove | Spreadsheet | นำผู้ใช้ที่ระบุออกจากรายชื่อเอดิเตอร์สำหรับ Spreadsheet |
remove | Spreadsheet | นำผู้ใช้ที่ระบุออกจากรายชื่อเอดิเตอร์สำหรับ Spreadsheet |
remove | void | นำเมนูที่ add เพิ่มออก |
remove | void | ลบช่วงที่มีชื่อซึ่งมีชื่อที่ระบุ |
remove | Spreadsheet | นำผู้ใช้ที่ระบุออกจากรายชื่อผู้มีสิทธิ์อ่านและผู้แสดงความคิดเห็นสำหรับ Spreadsheet |
remove | Spreadsheet | นำผู้ใช้ที่ระบุออกจากรายชื่อผู้มีสิทธิ์อ่านและผู้แสดงความคิดเห็นสำหรับ Spreadsheet |
rename(newName) | void | เปลี่ยนชื่อเอกสาร |
rename | void | เปลี่ยนชื่อชีตที่ใช้งานอยู่ปัจจุบันเป็นชื่อใหม่ที่ระบุ |
reset | Spreadsheet | นำธีมที่ใช้แล้วออกและตั้งค่าธีมเริ่มต้นในสเปรดชีต |
set | Range | กำหนดช่วงที่ระบุเป็นactive range ในชีตที่ใช้งานอยู่ โดยมีเซลล์ซ้ายบนสุดในช่วงเป็นcurrent cell |
set | Range | ตั้งค่ารายการช่วงที่ระบุเป็น active ranges ในชีตที่ใช้งานอยู่ |
set | Range | ตั้งค่าภูมิภาคที่เลือกที่ใช้งานอยู่สำหรับชีตนี้ |
set | Range | ตั้งค่าการเลือกที่ใช้งานอยู่ตามที่ระบุในรูปแบบ A1 หรือ R1C1 |
set | Sheet | ตั้งค่าชีตที่ระบุให้เป็นชีตที่ใช้งานอยู่ในสเปรดชีต |
set | Sheet | ตั้งค่าชีตที่ระบุให้เป็นชีตที่ใช้งานอยู่ในสเปรดชีต โดยมีตัวเลือกในการคืนค่า การเลือกที่ล่าสุดภายในชีตนั้น |
set | Sheet | กำหนดความกว้างของคอลัมน์ที่ระบุเป็นพิกเซล |
set | Range | ตั้งค่าเซลล์ที่ระบุเป็น current cell |
set | void | ตรึงจำนวนคอลัมน์ที่ระบุ |
set | void | ตรึงจำนวนแถวที่ระบุ |
set | Spreadsheet | กำหนดค่าเกณฑ์ขั้นต่ำสำหรับการคำนวณแบบวนซ้ำ |
set | Spreadsheet | ตั้งค่าว่าจะเปิดใช้งานการคำนวณซ้ำในสเปรดชีตนี้หรือไม่ |
set | Spreadsheet | กำหนดจำนวนการคำนวณซ้ำสูงสุดที่ควรดำเนินการระหว่างการคำนวณซ้ำ |
set | void | ตั้งชื่อช่วง |
set | Spreadsheet | กำหนดความถี่ที่สเปรดชีตนี้ควรรีคำนวณ |
set | Sheet | กำหนดความสูงของแถวที่ระบุเป็นพิกเซล |
set | void | ตั้งค่าภาษาของสเปรดชีต |
set | Spreadsheet | กำหนดธีมในสเปรดชีต |
set | void | ตั้งค่าเขตเวลาสำหรับสเปรดชีต |
show(userInterface) | void | แสดงคอมโพเนนต์อินเทอร์เฟซผู้ใช้ที่กำหนดเองในกล่องโต้ตอบที่อยู่ตรงกลางวิวพอร์ตของเบราว์เซอร์ของผู้ใช้ |
sort(columnPosition) | Sheet | จัดเรียงชีตตามคอลัมน์จากน้อยไปมาก |
sort(columnPosition, ascending) | Sheet | จัดเรียงชีตตามคอลัมน์ |
toast(msg) | void | แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีตพร้อมข้อความที่ระบุ |
toast(msg, title) | void | แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีตพร้อมข้อความและ ชื่อที่ระบุ |
toast(msg, title, timeoutSeconds) | void | แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีตพร้อมชื่อและข้อความที่ระบุ ซึ่งจะแสดงเป็นระยะเวลาหนึ่ง |
unhide | void | เลิกซ่อนคอลัมน์ในช่วงที่กำหนด |
unhide | void | เลิกซ่อนแถวในช่วงที่กำหนด |
update | void | อัปเดตเมนูที่เพิ่มโดย add |
wait | void | รอจนกว่าการดำเนินการปัจจุบันทั้งหมดในสเปรดชีตจะเสร็จสมบูรณ์ โดยจะหมดเวลาหลังจากผ่านไปตามจำนวนวินาทีที่ระบุ |
เอกสารโดยละเอียด
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', ); // Adds the key 'NAME' in the developer metadata for the spreadsheet. ss.addDeveloperMetadata('NAME'); // Gets the first developer metadata object and logs its key. const developerMetaData = ss.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
รีเทิร์น
Spreadsheet
— สเปรดชีตนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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', ); // Adds the key 'NAME' in the developer metadata for the spreadsheet and sets // the visibility to the developer project that created the metadata. ss.addDeveloperMetadata( 'NAME', SpreadsheetApp.DeveloperMetadataVisibility.PROJECT, ); // Gets the first developer metadata object and logs its key and visibility // setting. const developerMetaData = ss.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log(`Key: ${developerMetaData.getKey()}, . Visibility: ${developerMetaData.getVisibility()}`);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
visibility | Developer | ระดับการเข้าถึงของข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
รีเทิร์น
Spreadsheet
— สเปรดชีตนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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', ); // Adds the key 'NAME' and sets the value to 'GOOGLE' in the developer metadata // for the spreadsheet. ss.addDeveloperMetadata('NAME', 'GOOGLE'); // Gets the first developer metadata object and logs its key and value. const developerMetaData = ss.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log( `Key: ${developerMetaData.getKey()}, Value: ${ developerMetaData.getValue()}`, );
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
value | String | ค่าสำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
รีเทิร์น
Spreadsheet
— สเปรดชีตนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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', ); // Adds the key 'NAME', sets the value to 'GOOGLE', and sets the visibility // to any developer project with document access. ss.addDeveloperMetadata( 'NAME', 'GOOGLE', SpreadsheetApp.DeveloperMetadataVisibility.DOCUMENT, ); // Gets the first developer metadata object and logs its key, value, and // visibility setting. const developerMetaData = ss.getDeveloperMetadata()[0]; console.log(`Key: ${developerMetaData.getKey()}, Value: ${developerMetaData.getValue()}, Visibility: ${developerMetaData.getVisibility()}`);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
key | String | คีย์สำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
value | String | ค่าสำหรับข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
visibility | Developer | ระดับการเข้าถึงของข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ใหม่ |
รีเทิร์น
Spreadsheet
— สเปรดชีตนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
add Editor(emailAddress)
เพิ่มผู้ใช้ที่ระบุลงในรายชื่อเอดิเตอร์สำหรับ Spreadsheet
หากผู้ใช้
อยู่ในรายชื่อผู้ชมอยู่แล้ว วิธีนี้จะเลื่อนผู้ใช้รายดังกล่าวออกจากรายชื่อผู้ชม
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
email | String | อีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
Spreadsheet
— This Spreadsheet
, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
add Editor(user)
เพิ่มผู้ใช้ที่ระบุลงในรายชื่อเอดิเตอร์สำหรับ Spreadsheet
หากผู้ใช้
อยู่ในรายชื่อผู้ชมอยู่แล้ว วิธีนี้จะเลื่อนผู้ใช้รายดังกล่าวออกจากรายชื่อผู้ชม
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
Spreadsheet
— This Spreadsheet
, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
add Editors(emailAddresses)
เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้แก้ไขสำหรับ Spreadsheet
หากผู้ใช้รายใดอยู่ในรายชื่อผู้ชมอยู่แล้ว วิธีนี้จะเลื่อนผู้ใช้รายดังกล่าวออกจากรายชื่อผู้ชม
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
email | String[] | อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
Spreadsheet
— This Spreadsheet
, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
add Menu(name, subMenus)
สร้างเมนูใหม่ใน UI ของสเปรดชีต
รายการเมนูแต่ละรายการจะเรียกใช้ฟังก์ชันที่ผู้ใช้กำหนด โดยปกติแล้ว คุณจะเรียกใช้จากฟังก์ชัน on
เพื่อให้ระบบสร้างเมนูโดยอัตโนมัติเมื่อโหลดสเปรดชีต
// The onOpen function is executed automatically every time a Spreadsheet is // loaded function onOpen() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const menuEntries = []; // When the user clicks on "addMenuExample" then "Menu Entry 1", the function // function1 is executed. menuEntries.push({name: 'Menu Entry 1', functionName: 'function1'}); menuEntries.push(null); // line separator menuEntries.push({name: 'Menu Entry 2', functionName: 'function2'}); ss.addMenu('addMenuExample', menuEntries); }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อของเมนูที่จะสร้าง |
sub | Object[] | อาร์เรย์ของแผนที่ JavaScript ที่มีพารามิเตอร์ name และ function คุณสามารถใช้ฟังก์ชันจากไลบรารีที่รวมไว้ เช่น
Library.libFunction1 |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
add Viewer(emailAddress)
เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ชมของ Spreadsheet
หากผู้ใช้เป็นผู้แก้ไขอยู่แล้ว วิธีนี้จะไม่มีผล
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
email | String | อีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
Spreadsheet
— This Spreadsheet
, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
add Viewer(user)
เพิ่มผู้ใช้ที่ระบุลงในรายชื่อผู้ชมของ Spreadsheet
หากผู้ใช้เป็นผู้แก้ไขอยู่แล้ว วิธีนี้จะไม่มีผล
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
Spreadsheet
— This Spreadsheet
, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
add Viewers(emailAddresses)
เพิ่มอาร์เรย์ของผู้ใช้ที่ระบุลงในรายชื่อผู้ชมสำหรับ Spreadsheet
หากผู้ใช้รายใดอยู่ในรายชื่อผู้แก้ไขอยู่แล้ว วิธีนี้จะไม่มีผลกับผู้ใช้รายนั้น
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
email | String[] | อาร์เรย์ของอีเมลของผู้ใช้ที่จะเพิ่ม |
รีเทิร์น
Spreadsheet
— This Spreadsheet
, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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
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
copy(name)
คัดลอกสเปรดชีตและส่งคืนสเปรดชีตใหม่
// This code makes a copy of the current spreadsheet and names it appropriately const ss = SpreadsheetApp.getActiveSpreadsheet(); ss.copy(`Copy of ${ss.getName()}`);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อของสำเนา |
รีเทิร์น
Spreadsheet
— สเปรดชีตนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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', ); // Adds developer metadata to the spreadsheet. ss.addDeveloperMetadata('NAME', 'CHARLIE'); ss.addDeveloperMetadata('COMPANY', 'EXAMPLE ORGANIZATION'); ss.addDeveloperMetadata('TECHNOLOGY', 'JAVASCRIPT'); // Creates a developer metadata finder. const developerMetadataFinder = ss.createDeveloperMetadataFinder(); // Finds the developer metadata objects with 'COMPANY' as the key. const googleMetadataFromSpreadsheet = developerMetadataFinder.withKey('COMPANY').find(); // Gets the first result of developer metadata that has the key 'COMPANY' and // logs its value. console.log(googleMetadataFromSpreadsheet[0].getValue());
รีเทิร์น
Developer
- เครื่องมือค้นหาข้อมูลเมตาของนักพัฒนาซอฟต์แวร์เพื่อค้นหาข้อมูลเมตาในขอบเขตของสเปรดชีตนี้
create Text Finder(findText)
สร้างเครื่องมือค้นหาข้อความสำหรับสเปรดชีต ซึ่งใช้เพื่อค้นหาและแทนที่ข้อความภายใน สเปรดชีตได้ การค้นหาจะเริ่มจากชีตแรกของสเปรดชีต
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // Creates a text finder. const textFinder = spreadsheet.createTextFinder('dog'); // Returns the first occurrence of 'dog' in the spreadsheet. const firstOccurrence = textFinder.findNext(); // Replaces the last found occurrence of 'dog' with 'cat' and returns the number // of occurrences replaced. const numOccurrencesReplaced = textFinder.replaceWith('cat');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
find | String | ข้อความที่จะค้นหา |
รีเทิร์น
Text
— Text
สำหรับสเปรดชีต
delete Active Sheet()
ลบชีตที่ใช้งานอยู่ในปัจจุบัน
// The code below deletes the currently active sheet and stores the new active // sheet in a variable const newSheet = SpreadsheetApp.getActiveSpreadsheet().deleteActiveSheet();
รีเทิร์น
Sheet
— ชีตใหม่ที่ใช้งานอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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
delete Sheet(sheet)
ลบชีตที่ระบุ
// The code below deletes the specified sheet. const ss = SpreadsheetApp.getActive(); const sheet = ss.getSheetByName('My Sheet'); ss.deleteSheet(sheet);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | Sheet | แผ่นงานที่จะลบ |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
duplicate Active Sheet()
ทำซ้ำชีตที่ใช้งานอยู่และทำให้เป็นชีตที่ใช้งานอยู่
// The code below makes a duplicate of the active sheet SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();
รีเทิร์น
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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 Active Sheet()
รับชีตที่ใช้งานอยู่ในสเปรดชีต
ชีตที่ใช้งานในสเปรดชีตคือชีตที่แสดงใน UI ของสเปรดชีต
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
รีเทิร์น
Sheet
— ชีตที่ใช้งานอยู่ในสเปรดชีต
get As(contentType)
แสดงผลข้อมูลภายในออบเจ็กต์นี้เป็น Blob ที่แปลงเป็นประเภทเนื้อหาที่ระบุ วิธีนี้จะเพิ่มนามสกุลที่เหมาะสมให้กับชื่อไฟล์ เช่น "myfile.pdf" อย่างไรก็ตาม ระบบจะ ถือว่าส่วนของชื่อไฟล์ที่อยู่หลังจุดสุดท้าย (หากมี) เป็นนามสกุลที่มีอยู่ ซึ่งควรแทนที่ ดังนั้น "ShoppingList.12.25.2014" จะกลายเป็น "ShoppingList.12.25.pdf"
หากต้องการดูโควต้า Conversion รายวัน โปรดดูโควต้าสำหรับบริการของ Google โดเมน Google Workspace ที่สร้างขึ้นใหม่จะอยู่ภายใต้โควต้าที่เข้มงวดมากขึ้นชั่วคราว
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
content | String | ประเภท MIME ที่จะแปลง สำหรับ Blob ส่วนใหญ่ 'application/pdf' เป็น
ตัวเลือกเดียวที่ใช้ได้ สำหรับรูปภาพในรูปแบบ BMP, GIF, JPEG หรือ PNG คุณยังใช้ 'image/bmp' , 'image/gif' , 'image/jpeg' หรือ 'image/png' ได้ด้วย
เช่นกัน สำหรับเอกสาร Google เอกสาร 'text/markdown' ก็ใช้ได้เช่นกัน |
รีเทิร์น
Blob
— ข้อมูลเป็น Blob
get Bandings()
แสดงการแบนทั้งหมดในสเปรดชีตนี้
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets an array of the bandings in the spreadsheet. const bandings = ss.getBandings(); // Logs the range of the first banding in the spreadsheet to the console. console.log(bandings[0].getRange().getA1Notation());
รีเทิร์น
Banding[]
- แถบสีในสเปรดชีตนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Blob()
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 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 Refresh Schedules()
รับกำหนดเวลาการรีเฟรชของสเปรดชีตนี้
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Activates BigQuery operations for the connected spreadsheet. SpreadsheetApp.enableBigQueryExecution(); // Gets the frequency type of the first referesh schedule in the array. const frequencyType = ss.getDataSourceRefreshSchedules()[0] .getFrequency() .getFrequencyType() .toString(); // Logs the frequency type to the console. console.log(frequencyType);
รีเทิร์น
Data
- กำหนดเวลารีเฟรชของสเปรดชีตนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Data Source Sheets()
แสดงผลชีตแหล่งข้อมูลทั้งหมดในสเปรดชีต
// Turns data execution on for BigQuery data sources. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets the first data source sheet in the spreadsheet. const dataSource = ss.getDataSourceSheets()[0]; // Gets the name of the data source sheet. console.log(dataSource.asSheet().getName());
รีเทิร์น
Data
— อาร์เรย์ของชีตแหล่งข้อมูลทั้งหมด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 Data Sources()
แสดงผลแหล่งข้อมูลทั้งหมดในสเปรดชีต
// Turns data execution on for BigQuery data sources. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets the data sources on the spreadsheet. const dataSources = ss.getDataSources(); // Logs the name of the first column on the first data source. console.log(dataSources[0].getColumns()[0].getName());
รีเทิร์น
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 spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Adds 'Google' as a key to the spreadsheet metadata. ss.addDeveloperMetadata('Google'); // Gets the spreadsheet's metadata. const ssMetadata = ss.getDeveloperMetadata(); // Gets the first set of the spreadsheet's metadata and logs the key to the // console. console.log(ssMetadata[0].getKey());
รีเทิร์น
Developer
- ข้อมูลเมตาของนักพัฒนาซอฟต์แวร์ที่เชื่อมโยงกับช่วงนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Editors()
รับรายชื่อเอดิเตอร์สำหรับ Spreadsheet
นี้
รีเทิร์น
User[]
— อาร์เรย์ของผู้ใช้ที่มีสิทธิ์แก้ไข
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Form Url()
แสดง URL ของแบบฟอร์มที่ส่งคำตอบไปยังสเปรดชีตนี้ หรือ null
หากสเปรดชีตนี้ไม่มีแบบฟอร์มที่เชื่อมโยง หากแบบฟอร์มหลายรายการส่งคำตอบไปยังสเปรดชีตนี้
URL ของแบบฟอร์มที่แสดงจะระบุไม่ได้ คุณสามารถเรียกข้อมูลการเชื่อมโยง URL ของแบบฟอร์มต่อชีตได้ผ่านเมธอด Sheet.getFormUrl()
แสดงข้อยกเว้นหากผู้ใช้
ไม่มีสิทธิ์แก้ไขสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets the form URL from the spreadsheet. const formUrl = ss.getFormUrl(); // Logs the form URL to the console. console.log(formUrl);
รีเทิร์น
String
— URL ของแบบฟอร์มที่บันทึกคำตอบไว้ในสเปรดชีตนี้ หรือ null
หาก
สเปรดชีตนี้ไม่มีแบบฟอร์มที่เชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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 Id()
รับตัวระบุที่ไม่ซ้ำกันสำหรับสเปรดชีตนี้ คุณสามารถดึงรหัสของสเปรดชีตจาก URL ของสเปรดชีตนั้น เช่น รหัสสเปรดชีตใน URL https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 คือ "abc1234567"
// The code below logs the ID for the active spreadsheet. Logger.log(SpreadsheetApp.getActiveSpreadsheet().getId());
รีเทิร์น
String
— รหัสที่ไม่ซ้ำกัน (หรือคีย์) สำหรับสเปรดชีต
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 Iterative Calculation Convergence Threshold()
แสดงผลค่าเกณฑ์ที่ใช้ระหว่างการคำนวณแบบวนซ้ำ เมื่อผลลัพธ์ของการคำนวณ ที่ต่อเนื่องแตกต่างกันน้อยกว่าค่านี้ การคำนวณแบบวนซ้ำจะหยุดลง
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Sets the iterative calculation convergence threshold for the spreadsheet. ss.setIterativeCalculationConvergenceThreshold(2); // Logs the threshold to the console. console.log(ss.getIterativeCalculationConvergenceThreshold());
รีเทิร์น
Number
— เกณฑ์การบรรจบ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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 Iterative Calculation Cycles()
แสดงผลจำนวนการทำซ้ำสูงสุดที่จะใช้ในระหว่างการคำนวณซ้ำ
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Sets the max iterative calculation cycles for the spreadsheet. ss.setMaxIterativeCalculationCycles(10); // Logs the max iterative calculation cycles to the console. console.log(ss.getMaxIterativeCalculationCycles());
รีเทิร์น
Integer
— จำนวนการวนซ้ำการคำนวณสูงสุด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Name()
รับชื่อของเอกสาร
const ss = SpreadsheetApp.getActiveSpreadsheet(); Logger.log(ss.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.getActiveSpreadsheet().getNamedRanges(); for (let i = 0; i < namedRanges.length; i++) { Logger.log(namedRanges[i].getName()); }
รีเทิร์น
Named
— อาร์เรย์ของช่วงที่ตั้งชื่อทั้งหมดในสเปรดชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Num Sheets()
แสดงผลจำนวนชีตในสเปรดชีตนี้
// The code below logs the number of sheets in the active spreadsheet. Logger.log(SpreadsheetApp.getActiveSpreadsheet().getNumSheets());
รีเทิร์น
Integer
— จำนวนชีตในสเปรดชีต
get Owner()
แสดงเจ้าของเอกสาร หรือ null
สำหรับเอกสารในไดรฟ์ที่แชร์
const ss = SpreadsheetApp.getActiveSpreadsheet(); const owner = ss.getOwner(); Logger.log(owner.getEmail());
รีเทิร์น
User
— เจ้าของเอกสาร หรือ null
หากเอกสารอยู่ในไดรฟ์ที่แชร์
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Predefined Spreadsheet Themes()
แสดงผลรายการธีมที่กำหนดไว้ล่วงหน้า
// The code below returns the list of predefined themes. const predefinedThemesList = SpreadsheetApp.getActiveSpreadsheet().getPredefinedSpreadsheetThemes();
รีเทิร์น
Spreadsheet
— รายการธีมที่กำหนดไว้ล่วงหน้า
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 ss = SpreadsheetApp.getActive(); const protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE); for (let i = 0; i < protections.length; i++) { const protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
// Remove all sheet protections in the spreadsheet that the user has permission // to edit. const ss = SpreadsheetApp.getActive(); const protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET); for (let i = 0; i < protections.length; i++) { const protection = protections[i]; 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(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 By Name(name)
แสดงผลช่วงที่มีชื่อ หรือ null
หากไม่พบช่วงที่มีชื่อที่ระบุ หากสเปรดชีตมีหลายชีตที่ใช้ชื่อช่วงเดียวกัน ให้ระบุชื่อชีตโดยไม่ต้องใส่เครื่องหมายคำพูดเพิ่มเติม เช่น get
หรือ get
แต่ไม่ใช่ get
// Log the number of columns for the range named 'TaxRates' in the active // spreadsheet. const range = SpreadsheetApp.getActiveSpreadsheet().getRangeByName('TaxRates'); if (range != null) { Logger.log(range.getNumColumns()); }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อของช่วงที่จะได้รับ |
รีเทิร์น
Range
— ช่วงของเซลล์ที่มีชื่อที่ระบุ
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 Recalculation Interval()
แสดงช่วงเวลาการคำนวณสำหรับสเปรดชีตนี้
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Logs the calculation interval for the spreadsheet to the console. console.log(ss.getRecalculationInterval().toString());
รีเทิร์น
Recalculation
- ช่วงเวลาการคำนวณสำหรับสเปรดชีตนี้
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 By Id(id)
รับชีตที่มีรหัสที่ระบุ ใช้ Sheet.getSheetId()
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetById(12345);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
id | Integer | รหัสของชีตที่จะรับ |
รีเทิร์น
Sheet
— ชีตที่มีรหัสที่ระบุหรือ null
หากไม่พบชีต
get Sheet By Name(name)
แสดงผลชีตที่มีชื่อที่ระบุ
หากชีตหลายรายการมีชื่อเดียวกัน ระบบจะแสดงชีตที่อยู่ซ้ายสุด แสดงผล null
หาก
ไม่มีชีตที่มีชื่อที่ระบุ
// The code below logs the index of a sheet named "Expenses" const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Expenses'); if (sheet != null) { Logger.log(sheet.getIndex()); }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อชีตที่จะได้รับ |
รีเทิร์น
Sheet
— ชีตที่มีชื่อที่ระบุ
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 Sheets()
รับชีตทั้งหมดในสเปรดชีตนี้
// The code below logs the name of the second sheet const sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets(); // Iterates through the sheets and logs the name and ID of each sheet. for (const sheet of sheets) { Logger.log(`name: ${sheet.getName()}, ID: ${sheet.getSheetId()}`); }
รีเทิร์น
Sheet[]
— อาร์เรย์ของชีตทั้งหมดในสเปรดชีต
get Spreadsheet Locale()
รับภาษาของสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets the spreadsheet locale. const ssLocale = ss.getSpreadsheetLocale(); // Logs the locale to the console. console.log(ssLocale);
รีเทิร์น
String
— ภาษาของสเปรดชีต
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Spreadsheet Theme()
แสดงผลธีมปัจจุบันของสเปรดชีต หรือ null
หากไม่มีการใช้ธีม
// The code below returns the current theme of the spreadsheet. const currentTheme = SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTheme();
รีเทิร์น
Spreadsheet
— ธีมที่ใช้อยู่ในปัจจุบัน
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Spreadsheet Time Zone()
รับเขตเวลาของสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Sets the time zone of the spreadsheet. ss.setSpreadsheetTimeZone('America/New_York'); // Gets the time zone of the spreadsheet. const ssTimeZone = ss.getSpreadsheetTimeZone(); // Logs the time zone to the console. console.log(ssTimeZone);
รีเทิร์น
String
— เขตเวลาที่ระบุในรูปแบบ "ยาว" (เช่น "America/New_York" ตามที่ระบุโดย Joda.org)
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Url()
แสดงผล URL สำหรับสเปรดชีตที่ระบุ
const ss = SpreadsheetApp.getActiveSpreadsheet(); Logger.log(ss.getUrl());
รีเทิร์น
String
— URL ของสเปรดชีตที่ระบุ
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Viewers()
รับรายการผู้มีสิทธิ์อ่านและผู้แสดงความคิดเห็นสำหรับ Spreadsheet
นี้
รีเทิร์น
User[]
— อาร์เรย์ของผู้ใช้ที่มีสิทธิ์ดูหรือแสดงความคิดเห็น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 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
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 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 Data Source Sheet(spec)
แทรก Data
ใหม่ในสเปรดชีตและเริ่มการดำเนินการข้อมูล ผลพลอยได้จากขั้นตอนนี้คือการทำให้ชีตใหม่เป็นชีตที่ใช้งานอยู่
แสดงข้อยกเว้นหากไม่ได้เปิดใช้ประเภทแหล่งข้อมูล ใช้วิธีการ Spreadsheet
เพื่อเปิดใช้การเรียกใช้ข้อมูลสำหรับแหล่งข้อมูลประเภทใดประเภทหนึ่ง
// Activates BigQuery operations. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Builds a data source specification. // TODO (developer): Update the project ID to your own Google Cloud project ID. const dataSourceSpec = SpreadsheetApp.newDataSourceSpec() .asBigQuery() .setProjectId('project-id-1') .setTableProjectId('bigquery-public-data') .setDatasetId('ncaa_basketball') .setTableId('mbb_historical_teams_games') .build(); // Adds the data source and its data to the spreadsheet. ss.insertDataSourceSheet(dataSourceSpec);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
spec | Data | ข้อกำหนดของแหล่งข้อมูลที่จะแทรก |
รีเทิร์น
Data
— ชีตแหล่งข้อมูลใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Image(blobSource, column, row)
แทรก Spreadsheet
เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ ระบบจะดึงข้อมูลขนาดรูปภาพ
จากเนื้อหา 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)
แทรก Spreadsheet
เป็นรูปภาพในเอกสารที่แถวและคอลัมน์ที่ระบุ โดยมีออฟเซ็ต
พิกเซล ระบบจะดึงขนาดรูปภาพจากเนื้อหา 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 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 Sheet()
แทรกแผ่นงานใหม่ลงในสเปรดชีตโดยใช้ชื่อแผ่นงานเริ่มต้น ชีตใหม่จะกลายเป็น ชีตที่ใช้งานอยู่
const ss = SpreadsheetApp.getActiveSpreadsheet(); ss.insertSheet();
รีเทิร์น
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Sheet(sheetIndex)
แทรกชีตใหม่ลงในสเปรดชีตที่ดัชนีที่ระบุ ชีตใหม่จะกลายเป็นชีตที่ใช้งานอยู่
const ss = SpreadsheetApp.getActiveSpreadsheet(); ss.insertSheet(1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | Integer | ดัชนีของชีตที่สร้างขึ้นใหม่ หากต้องการแทรกชีตเป็นชีตแรกใน สเปรดชีต ให้ตั้งค่าเป็น 0 |
รีเทิร์น
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Sheet(sheetIndex, options)
แทรกชีตใหม่ลงในสเปรดชีตที่ดัชนีที่ระบุและใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ แผ่นงานใหม่จะกลายเป็นแผ่นงานที่ใช้งานอยู่
const ss = SpreadsheetApp.getActiveSpreadsheet(); const templateSheet = ss.getSheetByName('Sales'); ss.insertSheet(1, {template: templateSheet});
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | Integer | ดัชนีของชีตที่สร้างขึ้นใหม่ หากต้องการแทรกชีตเป็นชีตแรกใน สเปรดชีต ให้ตั้งค่าเป็น 0 |
options | Object | อาร์กิวเมนต์ขั้นสูงของ JavaScript ที่ไม่บังคับ |
พารามิเตอร์ขั้นสูง
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
template | Sheet | ระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตชีตต้องเป็นชีตใดชีตหนึ่งของออบเจ็กต์สเปรดชีต |
รีเทิร์น
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Sheet(options)
แทรกแผ่นงานใหม่ลงในสเปรดชีตโดยใช้ชื่อแผ่นงานเริ่มต้นและอาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ แผ่นงานใหม่จะกลายเป็นแผ่นงานที่ใช้งานอยู่
const ss = SpreadsheetApp.getActiveSpreadsheet(); const templateSheet = ss.getSheetByName('Sales'); ss.insertSheet({template: templateSheet});
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
options | Object | อาร์กิวเมนต์ขั้นสูงของ JavaScript ที่ไม่บังคับ ซึ่งแสดงอยู่ด้านล่าง |
พารามิเตอร์ขั้นสูง
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
template | Sheet | ระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตชีตต้องเป็นชีตใดชีตหนึ่งของออบเจ็กต์สเปรดชีตนี้ |
รีเทิร์น
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Sheet(sheetName)
แทรกชีตใหม่ลงในสเปรดชีตโดยใช้ชื่อที่ระบุ ชีตใหม่จะกลายเป็นชีตที่ใช้งานอยู่
const ss = SpreadsheetApp.getActiveSpreadsheet(); ss.insertSheet('My New Sheet');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | String | ชื่อของชีตใหม่ |
รีเทิร์น
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Sheet(sheetName, sheetIndex)
แทรกชีตใหม่ลงในสเปรดชีตโดยใช้ชื่อที่ระบุในดัชนีที่ระบุ แผ่นงานใหม่ จะกลายเป็นแผ่นงานที่ใช้งานอยู่
const ss = SpreadsheetApp.getActiveSpreadsheet(); ss.insertSheet('My New Sheet', 1);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | String | ชื่อของชีตใหม่ |
sheet | Integer | ดัชนีของชีตที่สร้างขึ้นใหม่ หากต้องการแทรกชีตเป็นชีตแรกใน สเปรดชีต ให้ตั้งค่าเป็น 0 |
รีเทิร์น
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Sheet(sheetName, sheetIndex, options)
แทรกชีตใหม่ลงในสเปรดชีตโดยใช้ชื่อที่ระบุในดัชนีที่ระบุ และใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ แผ่นงานใหม่จะกลายเป็นแผ่นงานที่ใช้งานอยู่
const ss = SpreadsheetApp.getActiveSpreadsheet(); const templateSheet = ss.getSheetByName('Sales'); ss.insertSheet('My New Sheet', 1, {template: templateSheet});
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | String | ชื่อของชีตใหม่ |
sheet | Integer | ดัชนีของชีตที่แทรกใหม่ หากต้องการแทรกชีตเป็นชีตแรกใน สเปรดชีต ให้ตั้งค่าเป็น 0 |
options | Object | อาร์กิวเมนต์ขั้นสูงของ JavaScript ที่ไม่บังคับ |
พารามิเตอร์ขั้นสูง
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
template | Sheet | ระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตชีตต้องเป็นชีตใดชีตหนึ่งของออบเจ็กต์สเปรดชีต |
รีเทิร์น
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Sheet(sheetName, options)
แทรกชีตใหม่ลงในสเปรดชีตโดยใช้ชื่อที่ระบุและใช้อาร์กิวเมนต์ขั้นสูงที่ไม่บังคับ แผ่นงานใหม่จะกลายเป็นแผ่นงานที่ใช้งานอยู่
const ss = SpreadsheetApp.getActiveSpreadsheet(); const templateSheet = ss.getSheetByName('Sales'); ss.insertSheet('My New Sheet', {template: templateSheet});
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | String | ชื่อของชีตใหม่ |
options | Object | อาร์กิวเมนต์ขั้นสูงของ JavaScript ที่ไม่บังคับ |
พารามิเตอร์ขั้นสูง
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
template | Sheet | ระบบจะคัดลอกข้อมูลทั้งหมดจากออบเจ็กต์ชีตเทมเพลตไปยังชีตใหม่ เทมเพลตชีตต้องเป็นชีตใดชีตหนึ่งของออบเจ็กต์สเปรดชีต |
รีเทิร์น
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insert Sheet With Data Source Table(spec)
แทรกชีตใหม่ในสเปรดชีต สร้าง Data
ครอบคลุม
ทั้งชีตด้วยข้อกำหนดแหล่งข้อมูลที่ระบุ และเริ่มการดำเนินการข้อมูล และจะทำให้ชีตใหม่เป็นชีตที่ใช้งานอยู่ด้วย
แสดงข้อยกเว้นหากไม่ได้เปิดใช้ประเภทแหล่งข้อมูล ใช้วิธีการ Spreadsheet
เพื่อเปิดใช้การเรียกใช้ข้อมูลสำหรับแหล่งข้อมูลประเภทใดประเภทหนึ่ง
// Activates BigQuery operations. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Adds a sheet and sets cell A1 as the parameter cell. const parameterCell = ss.insertSheet('parameterSheet').getRange('A1'); // Sets the value of the parameter cell to 'Duke'. parameterCell.setValue('Duke'); const query = 'select * from `bigquery-public-data`.`ncaa_basketball`.' + '`mbb_historical_tournament_games` WHERE win_school_ncaa = @SCHOOL'; // Adds a data source with a query parameter. // TODO(developer): Update the project ID to your own Google Cloud project ID. const dataSourceSpec = SpreadsheetApp.newDataSourceSpec() .asBigQuery() .setProjectId('project-id-1') .setRawQuery(query) .setParameterFromCell('SCHOOL', 'parameterSheet!A1') .build(); // Adds sheets for the data source and data source table to the spreadsheet. ss.insertSheetWithDataSourceTable(dataSourceSpec);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
spec | Data | ข้อกำหนดของแหล่งข้อมูลที่จะแทรก |
รีเทิร์น
Sheet
— ชีตใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 Iterative Calculation Enabled()
แสดงผลว่าเปิดใช้งานการคำนวณซ้ำในสเปรดชีตนี้หรือไม่
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Activates iterative calculation on the spreadsheet. ss.setIterativeCalculationEnabled(true); // Logs whether iterative calculation is activated for the spreadsheet. console.log(ss.isIterativeCalculationEnabled());
รีเทิร์น
Boolean
— true
หากเปิดใช้งานการคำนวณซ้ำ false
มิฉะนั้น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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
move Active Sheet(pos)
ย้ายชีตที่ใช้งานอยู่ไปยังตำแหน่งที่ระบุในรายการชีต ส่งข้อยกเว้นหากตำแหน่งเป็นค่าลบหรือมากกว่าจำนวนชีต
// This example assumes that there are 2 sheets in the current // active spreadsheet: one named "first" in position 1 and another named // "second" in position 2. const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // Gets the "first" sheet and activates it. const sheet = spreadsheet.getSheetByName('first').activate(); // Logs 'Current index of sheet: 1' console.log('Current index of sheet: %s', sheet.getIndex()); spreadsheet.moveActiveSheet(2); // Logs 'New index of sheet: 2' console.log('New index of sheet: %s', sheet.getIndex());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
pos | Integer | ตำแหน่งดัชนี 1 ที่จะย้ายชีตที่ใช้งานอยู่ไปยังรายการชีต |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
move Chart To Object Sheet(chart)
สร้างชีต Sheet
ใหม่และย้ายแผนภูมิที่ระบุไปยังชีตนั้น หากแผนภูมิ
อยู่ในชีตของตัวเองอยู่แล้ว ระบบจะแสดงชีตนั้นโดยไม่ต้องสร้างชีตใหม่
const sheet = SpreadsheetApp.getActiveSheet(); const chart = sheet.newChart().setPosition(1, 1, 0, 0).build(); sheet.insertChart(chart); const objectSheet = SpreadsheetApp.getActive().moveChartToObjectSheet(chart);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
chart | Embedded | แผนภูมิที่จะย้าย |
รีเทิร์น
Sheet
— ชีตที่มีแผนภูมิอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
refresh All Data Sources()
รีเฟรชแหล่งข้อมูลที่รองรับทั้งหมดและออบเจ็กต์แหล่งข้อมูลที่ลิงก์ โดยข้ามออบเจ็กต์แหล่งข้อมูลที่ไม่ถูกต้อง
ใช้วิธีการ Spreadsheet
เพื่อเปิดใช้การเรียกใช้ข้อมูลสำหรับ
แหล่งข้อมูลประเภทใดประเภทหนึ่ง
// Activates BigQuery operations. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Gets the first data source sheet on the spreadsheet. const dataSheet = ss.getDataSourceSheets()[0]; // Refreshes all data sources on the spreadsheet. ss.refreshAllDataSources(); // Logs the last refreshed time of the first data source sheet. console.log( `Last refresh time: ${dataSheet.getStatus().getLastRefreshedTime()}`, );
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove Editor(emailAddress)
นำผู้ใช้ที่ระบุออกจากรายชื่อเอดิเตอร์สำหรับ Spreadsheet
วิธีนี้จะไม่
บล็อกผู้ใช้ไม่ให้เข้าถึง Spreadsheet
หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มี
สิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Spreadsheet
กับทั้งโดเมนของผู้ใช้
หรือหาก Spreadsheet
อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้
สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ดังกล่าวออกจากรายชื่อผู้ดูด้วย
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
email | String | อีเมลของผู้ใช้ที่จะนำออก |
รีเทิร์น
Spreadsheet
— This Spreadsheet
, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove Editor(user)
นำผู้ใช้ที่ระบุออกจากรายชื่อเอดิเตอร์สำหรับ Spreadsheet
วิธีนี้จะไม่
บล็อกผู้ใช้ไม่ให้เข้าถึง Spreadsheet
หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มี
สิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Spreadsheet
กับทั้งโดเมนของผู้ใช้
หรือหาก Spreadsheet
อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้
สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ดังกล่าวออกจากรายชื่อผู้ดูด้วย
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะนำออก |
รีเทิร์น
Spreadsheet
— This Spreadsheet
, for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove Menu(name)
นำเมนูที่ add
เพิ่มออก อาร์กิวเมนต์ name
ควรมีค่าเดียวกับการเรียก add
ที่เกี่ยวข้อง
// The onOpen function is executed automatically every time a Spreadsheet is // loaded function onOpen() { const ss = SpreadsheetApp.getActiveSpreadsheet(); ss.addMenu('badMenu', [ {name: 'remove bad menu', functionName: 'removeBadMenu'}, {name: 'foo', functionName: 'foo'}, ]); } function removeBadMenu() { const ss = SpreadsheetApp.getActiveSpreadsheet(); ss.removeMenu( 'badMenu'); // name must match the name used when added the menu } function foo() { // Do nothing }
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อเมนูที่จะนำออก |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove Named Range(name)
ลบช่วงที่มีชื่อซึ่งมีชื่อที่ระบุ แสดงข้อยกเว้นหากไม่พบช่วงที่มีชื่อที่ระบุ ในสเปรดชีต
// The code below creates a new named range "foo", and then remove it. const ss = SpreadsheetApp.getActiveSpreadsheet(); ss.setNamedRange('foo', ss.getActiveRange()); ss.removeNamedRange('foo');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อช่วง |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove Viewer(emailAddress)
นำผู้ใช้ที่ระบุออกจากรายชื่อผู้มีสิทธิ์อ่านและผู้แสดงความคิดเห็นสำหรับ Spreadsheet
วิธีนี้จะไม่มีผลหากผู้ใช้เป็นผู้แก้ไข ไม่ใช่ผู้ดูหรือผู้แสดงความคิดเห็น นอกจากนี้ วิธีนี้ยัง
ไม่ได้บล็อกไม่ให้ผู้ใช้เข้าถึง Spreadsheet
หากผู้ใช้เป็นสมาชิกของกลุ่มผู้ใช้ที่มี
สิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Spreadsheet
กับโดเมนทั้งหมดของผู้ใช้ หรือหาก Spreadsheet
อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้
สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ดังกล่าวออกจากรายชื่อผู้แก้ไขด้วย
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
email | String | อีเมลของผู้ใช้ที่จะนำออก |
รีเทิร์น
Spreadsheet
— This Spreadsheet
for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
remove Viewer(user)
นำผู้ใช้ที่ระบุออกจากรายชื่อผู้มีสิทธิ์อ่านและผู้แสดงความคิดเห็นสำหรับ Spreadsheet
วิธีนี้จะไม่มีผลหากผู้ใช้เป็นผู้แก้ไข ไม่ใช่ผู้ดู นอกจากนี้ วิธีนี้ยังไม่บล็อกไม่ให้ผู้ใช้เข้าถึง Spreadsheet
หากผู้ใช้เป็นสมาชิกในกลุ่มผู้ใช้ที่มีสิทธิ์เข้าถึงทั่วไป เช่น หากมีการแชร์ Spreadsheet
กับทั้งโดเมนของผู้ใช้ หรือหาก Spreadsheet
อยู่ในไดรฟ์ที่แชร์ซึ่งผู้ใช้เข้าถึงได้
สำหรับไฟล์ในไดรฟ์ การดำเนินการนี้จะนำผู้ใช้ดังกล่าวออกจากรายชื่อผู้แก้ไขด้วย
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
user | User | การแสดงผู้ใช้ที่จะนำออก |
รีเทิร์น
Spreadsheet
— This Spreadsheet
for chaining.
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
rename(newName)
เปลี่ยนชื่อเอกสาร
const ss = SpreadsheetApp.getActiveSpreadsheet(); ss.rename('This is the new name');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
new | String | ชื่อใหม่ของเอกสาร |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
rename Active Sheet(newName)
เปลี่ยนชื่อชีตที่ใช้งานอยู่ปัจจุบันเป็นชื่อใหม่ที่ระบุ
// The code below renames the active sheet to "Hello world" SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet('Hello world');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
new | String | ชื่อใหม่ของชีตที่ใช้งานอยู่ในปัจจุบัน |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
reset Spreadsheet Theme()
นำธีมที่ใช้แล้วออกและตั้งค่าธีมเริ่มต้นในสเปรดชีต
// The code below applies default theme on the spreadsheet. SpreadsheetApp.getActiveSpreadsheet().resetSpreadsheetTheme();
รีเทิร์น
Spreadsheet
- ธีมเริ่มต้น
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 Active Sheet(sheet)
ตั้งค่าชีตที่ระบุให้เป็นชีตที่ใช้งานอยู่ในสเปรดชีต UI ของ Google ชีตจะแสดง ชีตที่เลือก เว้นแต่ชีตนั้นจะอยู่ในสเปรดชีตอื่น
// The code below makes the first sheet active in the active spreadsheet. const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); spreadsheet.setActiveSheet(spreadsheet.getSheets()[0]);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | Sheet | ชีตที่จะตั้งเป็นชีตที่ใช้งานอยู่ |
รีเทิร์น
Sheet
- ชีตที่ใช้งานอยู่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Active Sheet(sheet, restoreSelection)
ตั้งค่าชีตที่ระบุให้เป็นชีตที่ใช้งานอยู่ในสเปรดชีต โดยมีตัวเลือกในการคืนค่า การเลือกที่ล่าสุดภายในชีตนั้น UI ของ Google ชีตจะแสดงชีตที่เลือก เว้นแต่ ชีตนั้นจะอยู่ในสเปรดชีตอื่น
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); const firstSheet = spreadsheet.getSheets()[0]; const secondSheet = spreadsheet.getSheets()[1]; // Set the first sheet as the active sheet and select the range D4:F4. spreadsheet.setActiveSheet(firstSheet).getRange('D4:F4').activate(); // Switch to the second sheet to do some work. spreadsheet.setActiveSheet(secondSheet); // Switch back to first sheet, and restore its selection. spreadsheet.setActiveSheet(firstSheet, true); // The selection of first sheet is restored, and it logs D4:F4 const range = spreadsheet.getActiveSheet().getSelection().getActiveRange(); Logger.log(range.getA1Notation());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
sheet | Sheet | ชีตใหม่ที่ใช้งานอยู่ |
restore | Boolean | หากเป็น true ระบบจะเลือกแผ่นงานที่ใช้งานอยู่ใหม่ล่าสุดอีกครั้งเมื่อแผ่นงานใหม่ใช้งานได้ หากเป็น false แผ่นงานใหม่จะใช้งานได้โดยไม่เปลี่ยนการเลือกปัจจุบัน |
รีเทิร์น
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 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 Iterative Calculation Convergence Threshold(minThreshold)
กำหนดค่าเกณฑ์ขั้นต่ำสำหรับการคำนวณแบบวนซ้ำ เมื่อผลลัพธ์ของการคำนวณ ที่ต่อเนื่องแตกต่างกันน้อยกว่าค่านี้ การคำนวณแบบวนซ้ำจะหยุดลง ค่านี้ต้องไม่เป็นลบ และค่าเริ่มต้นคือ 0.05
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Sets the iterative calculation convergence threshold for the spreadsheet. ss.setIterativeCalculationConvergenceThreshold(2); // Logs the threshold to the console. console.log(ss.getIterativeCalculationConvergenceThreshold());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
min | Number | เกณฑ์การบรรจบกันขั้นต่ำ (ต้องไม่เป็นค่าลบ) |
รีเทิร์น
Spreadsheet
— สเปรดชีตนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Iterative Calculation Enabled(isEnabled)
ตั้งค่าว่าจะเปิดใช้งานการคำนวณซ้ำในสเปรดชีตนี้หรือไม่ หากไม่ได้ตั้งค่าจำนวนรอบการคำนวณและเกณฑ์การบรรจบสูงสุดไว้ก่อนหน้านี้เมื่อเปิดใช้งานการคำนวณ ค่าเริ่มต้นจะเป็น 50 และ 0.05 ตามลำดับ หากมีการตั้งค่าไว้ก่อนหน้านี้ ค่าดังกล่าวจะยังคงเป็นค่าเดิม
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Activates iterative calculation on the spreadsheet. ss.setIterativeCalculationEnabled(true); // Logs whether iterative calculation is activated for the spreadsheet. console.log(ss.isIterativeCalculationEnabled());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
is | Boolean | true หากควรเปิดใช้การคำนวณซ้ำ false
ไม่เช่นนั้น |
รีเทิร์น
Spreadsheet
— สเปรดชีตนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Max Iterative Calculation Cycles(maxIterations)
กำหนดจำนวนการคำนวณซ้ำสูงสุดที่ควรดำเนินการระหว่างการคำนวณซ้ำ ค่านี้ต้องอยู่ระหว่าง 1 ถึง 10,000 (รวม) และค่าเริ่มต้นคือ 50
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Sets the max iterative calculation cycles for the spreadsheet. ss.setMaxIterativeCalculationCycles(10); // Logs the max iterative calculation cycles to the console. console.log(ss.getMaxIterativeCalculationCycles());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
max | Integer | จำนวนการวนซ้ำการคำนวณสูงสุด (ระหว่าง 1 ถึง 10,000) |
รีเทิร์น
Spreadsheet
— สเปรดชีตนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Named Range(name, range)
ตั้งชื่อช่วง
// The code below creates a new named range "TaxRates" in the active spreadsheet const ss = SpreadsheetApp.getActiveSpreadsheet(); ss.setNamedRange('TaxRates', SpreadsheetApp.getActiveRange());
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อที่จะตั้งให้กับช่วง |
range | Range | ข้อมูลจำเพาะของช่วง |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Recalculation Interval(recalculationInterval)
กำหนดความถี่ที่สเปรดชีตนี้ควรรีคำนวณ
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() // instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Sets the calculation interval for the spreadsheet to 'ON_CHANGE'. const interval = ss.setRecalculationInterval( SpreadsheetApp.RecalculationInterval.ON_CHANGE, ); // Logs the calculation interval to the console. console.log(interval);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
recalculation | Recalculation | ช่วงเวลาการคำนวณใหม่ |
รีเทิร์น
Spreadsheet
— สเปรดชีตนี้สำหรับการเชื่อมโยง
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Row Height(rowPosition, height)
กำหนดความสูงของแถวที่ระบุเป็นพิกเซล โดยค่าเริ่มต้น แถวจะขยายให้พอดีกับเนื้อหาของเซลล์ หากต้องการบังคับให้แถวมีความสูงที่ระบุ ให้ใช้ Sheet.setRowHeightsForced(startRow, numRows, height)
const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheets()[0]; // Sets the first row to a height of 200 pixels sheet.setRowHeight(1, 200);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
row | Integer | ตำแหน่งแถวที่จะเปลี่ยน |
height | Integer | ความสูงเป็นพิกเซลที่จะตั้งค่า |
รีเทิร์น
Sheet
- ชีตที่มีประโยชน์สำหรับการเชื่อมโยงเมธอด
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Spreadsheet Locale(locale)
ตั้งค่าภาษาของสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Sets the spreadsheet locale. ss.setSpreadsheetLocale('fr'); // Gets the spreadsheet locale. const ssLocale = ss.getSpreadsheetLocale(); // Logs the locale to the console. console.log(ssLocale);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
locale | String | รหัสภาษาที่จะใช้ (เช่น "en", "fr" หรือ "en_US") |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Spreadsheet Theme(theme)
กำหนดธีมในสเปรดชีต
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // The code below sets the second predefined theme as the current theme of the // spreadsheet. const predefinedThemesList = spreadsheet.getPredefinedSpreadsheetThemes(); spreadsheet.setSpreadsheetTheme(predefinedThemesList[1]);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
theme | Spreadsheet | ธีมที่จะใช้ |
รีเทิร์น
Spreadsheet
- ธีมปัจจุบันใหม่
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
set Spreadsheet Time Zone(timezone)
ตั้งค่าเขตเวลาสำหรับสเปรดชีต
// Opens the spreadsheet file by its URL. If you created your script from within // a Google Sheets spreadsheet, you can use // SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl( 'https://docs.google.com/spreadsheets/d/abc123456/edit', ); // Sets the time zone of the spreadsheet. ss.setSpreadsheetTimeZone('America/New_York'); // Gets the time zone of the spreadsheet. const ssTimeZone = ss.getSpreadsheetTimeZone(); // Logs the time zone to the console. console.log(ssTimeZone);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
timezone | String | เขตเวลาที่ระบุในรูปแบบ "ยาว" (เช่น "America/New_York" ตามที่ระบุโดย Joda.org) |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
show(userInterface)
แสดงคอมโพเนนต์อินเทอร์เฟซผู้ใช้ที่กำหนดเองในกล่องโต้ตอบที่อยู่ตรงกลางวิวพอร์ตของเบราว์เซอร์ของผู้ใช้ ระบบไม่ระงับการเรียกใช้สคริปต์ฝั่งเซิร์ฟเวอร์ หากต้องการสื่อสารกับฝั่งเซิร์ฟเวอร์ คอมโพเนนต์อินเทอร์เฟซผู้ใช้ต้องเรียกใช้ฟังก์ชันเรียกกลับแบบไม่พร้อมกันไปยังสคริปต์ฝั่งเซิร์ฟเวอร์
หากสคริปต์ฝั่งเซิร์ฟเวอร์แสดงกล่องโต้ตอบที่ยังไม่ได้ปิดไปก่อนหน้านี้ ระบบจะแทนที่กล่องโต้ตอบที่มีอยู่ด้วยอินเทอร์เฟซผู้ใช้ของกล่องโต้ตอบที่ขอใหม่
ข้อมูลโค้ดต่อไปนี้จะแสดงHtml
แอปพลิเคชันแบบง่ายในกล่องโต้ตอบที่มีชื่อ ความสูง และความกว้างที่ระบุ
const htmlApp = HtmlService .createHtmlOutput( '<p>A change of speed, a change of style...</p>', ) .setTitle('My HtmlService Application') .setWidth(250) .setHeight(300); SpreadsheetApp.getActiveSpreadsheet().show(htmlApp); // The script resumes execution immediately after showing the dialog.
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
user | Object | Html |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/script.container.ui
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
toast(msg)
แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีตพร้อมข้อความที่ระบุ
// Show a popup with the message "Task started". SpreadsheetApp.getActiveSpreadsheet().toast('Task started');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
msg | String | ข้อความที่จะแสดงในข้อความป๊อปอัป |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
toast(msg, title)
แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีตพร้อมข้อความและ ชื่อที่ระบุ
// Show a popup with the title "Status" and the message "Task started". SpreadsheetApp.getActiveSpreadsheet().toast('Task started', 'Status');
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
msg | String | ข้อความที่จะแสดงในข้อความป๊อปอัป |
title | String | ชื่อที่ไม่บังคับของข้อความป๊อปอัป |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
toast(msg, title, timeoutSeconds)
แสดงหน้าต่างป๊อปอัปที่มุมขวาล่างของสเปรดชีตพร้อมชื่อและข้อความที่ระบุ ซึ่งจะแสดงเป็นระยะเวลาหนึ่ง
// Show a 3-second popup with the title "Status" and the message "Task started". SpreadsheetApp.getActiveSpreadsheet().toast('Task started', 'Status', 3);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
msg | String | ข้อความที่จะแสดงในข้อความป๊อปอัป |
title | String | ชื่อที่ไม่บังคับของข้อความป๊อปอัป |
timeout | Number | การหมดเวลาเป็นวินาที หากเป็น null การแจ้งเตือนจะใช้ค่าเริ่มต้นเป็น 5 วินาที
หากเป็นค่าลบ การแจ้งเตือนจะยังคงอยู่จนกว่าจะปิด |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 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 Menu(name, subMenus)
อัปเดตเมนูที่เพิ่มโดย add
ทำงานเหมือนกับ add
const ss = SpreadsheetApp.getActiveSpreadsheet(); const menuEntries = []; menuEntries.push({name: 'Lone Menu Entry', functionName: 'function1'}); ss.updateMenu('addMenuExample', menuEntries);
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
name | String | ชื่อของเมนูที่จะอัปเดต |
sub | Object[] | อาร์เรย์ของแผนที่ JavaScript ที่มีพารามิเตอร์ name และ function คุณสามารถใช้ฟังก์ชันจากไลบรารีที่รวมไว้ เช่น
Library.libFunction1 |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
wait For All Data Executions Completion(timeoutInSeconds)
รอจนกว่าการดำเนินการปัจจุบันทั้งหมดในสเปรดชีตจะเสร็จสมบูรณ์ โดยจะหมดเวลาหลังจากผ่านไปตามจำนวนวินาทีที่ระบุ โยนข้อยกเว้นหากการดำเนินการไม่เสร็จสมบูรณ์เมื่อหมดเวลา แต่จะไม่ยกเลิกการดำเนินการข้อมูล
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
---|---|---|
timeout | Integer | เวลารอการดำเนินการข้อมูลเป็นวินาที สูงสุดคือ 300 วินาที |
การให้สิทธิ์
สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets