Class Group

กลุ่ม

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

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

เมธอด

วิธีการประเภทการแสดงผลรายละเอียดแบบย่อ
collapse()Groupยุบกลุ่มนี้
expand()Groupขยายกลุ่มนี้
getControlIndex()Integerแสดงผลดัชนีสวิตช์ควบคุมของกลุ่มนี้
getDepth()Integerแสดงผลความลึกของกลุ่มนี้
getRange()Rangeแสดงช่วงที่กลุ่มนี้มีอยู่
isCollapsed()Booleanแสดง true หากยุบกลุ่มนี้
remove()voidนำกลุ่มนี้ออกจากชีต ซึ่งจะลดระดับกลุ่มของ range ลง 1 ระดับ

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

collapse()

ยุบกลุ่มนี้

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; const range = sheet.getRange('2:3'); range.shiftRowGroupDepth(1); const group = sheet.getRowGroup(2, 1);  // Collapses this group. group.collapse();

รีเทิร์น

Group - กลุ่มนี้สำหรับเชื่อมโยง

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

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

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

expand()

ขยายกลุ่มนี้

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; const range = sheet.getRange('2:3'); range.shiftRowGroupDepth(1); const group = sheet.getRowGroup(2, 1);  // Expands this group. group.expand();

รีเทิร์น

Group - กลุ่มนี้สำหรับเชื่อมโยง

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

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

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

getControlIndex()

แสดงผลดัชนีสวิตช์ควบคุมของกลุ่มนี้ นี่คือดัชนีที่อยู่ก่อนช่วงเมื่อ สวิตช์ควบคุมแสดงก่อนกลุ่ม หรือดัชนีที่อยู่หลังช่วงในกรณีอื่นๆ

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; sheet.setRowGroupControlAfter(true); const range = sheet.getRange('2:3'); range.shiftRowGroupDepth(1); const group = sheet.getRowGroup(2, 1);  // Returns 4 const controlIndex = group.getControlIndex();

รีเทิร์น

Integer — ดัชนีสลับการควบคุมของกลุ่มนี้

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

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

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

getDepth()

แสดงผลความลึกของกลุ่มนี้

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; const range = sheet.getRange('2:3'); range.shiftRowGroupDepth(1); const group = sheet.getRowGroup(2, 1);  // Returns 1 if the group is at depth 1. const depth = group.getDepth();

รีเทิร์น

Integer - ความลึกของกลุ่มนี้

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

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

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

getRange()

แสดงช่วงที่กลุ่มนี้มีอยู่

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; let range = sheet.getRange('2:3'); range.shiftRowGroupDepth(1); const group = sheet.getRowGroup(1, 1);  // Returns the range 2:3 if the group is over rows 2:3 range = group.getRange();

รีเทิร์น

Range — ช่วงที่กลุ่มมีอยู่

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

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

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

isCollapsed()

แสดง true หากยุบกลุ่มนี้

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; const range = sheet.getRange('2:3'); range.shiftRowGroupDepth(1); const group = sheet.getRowGroup(2, 1);  // Returns true if the group is collapsed. const isCollapsed = group.isCollapsed();

รีเทิร์น

Booleantrue หากกลุ่มนี้ยุบอยู่ จะแสดงผล false ในกรณีอื่นๆ

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

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

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

remove()

นำกลุ่มนี้ออกจากชีต ซึ่งจะลดระดับกลุ่มของ range ลง 1 ระดับ ซึ่งอาจแก้ไขกลุ่มอื่นๆ หลังจากเรียกใช้แล้ว ออบเจ็กต์กลุ่มจะใช้ไม่ได้

const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; let range = sheet.getRange('2:3'); range.shiftRowGroupDepth(1); const group = sheet.getRowGroup(2, 1);  // Removes this group range = group.remove();

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

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

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

ดูเพิ่มเติม