同一份工作表中一或多個 Range
例項的集合。您可以使用此類別對非鄰近範圍或儲存格集合套用運算。
方法
內容詳盡的說明文件
activate()
選取 Range
執行個體的清單。清單中的最後一個範圍設為 active range
。
注意:可讓您一次選取多個範圍。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['D4', 'B2:C4']); rangeList.activate(); var selection = sheet.getSelection(); // Current cell: B2 var currentCell = selection.getCurrentCell(); // Active range: B2:C4 var activeRange = selection.getActiveRange(); // Active range list: [D4, B2:C4] var activeRangeList = selection.getActiveRangeList();
回攻員
RangeList
— 有效範圍的清單,可用於鏈結。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
breakApart()
再次將範圍清單中包含的所有水平或垂直合併的儲存格分割為個別儲存格。
在範圍清單上呼叫這個函式,等同於選取一組範圍,然後依序選取「Format」>「Merge」>「Unmerge」工作表選單項目。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.breakApart();
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
check()
將範圍中的核取方塊狀態變更為「已勾選」。忽略目前範圍中不包含已勾選或未勾選值的儲存格。
// Changes the state of cells which currently contain either the checked or unchecked value // configured in the ranges D4 and E6 to 'checked'. var rangeList = SpreadsheetApp.getActive().getRangeList(['D4', 'E6']); rangeList.check();
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clear()
清除範圍清單中每個 Range
的內容、格式和資料驗證規則範圍。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clear();
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clear(options)
按照指定的選項指定,清除內容範圍、格式、資料驗證規則和註解。根據預設,系統會清除所有資料。
// The code below clears the contents of the following ranges A:A and C:C in the active sheet, // but preserves the format, data validation rules, and comments. var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clear({contentsOnly: true});
參數
名稱 | 類型 | 說明 |
---|---|---|
options | Object | 指定進階參數的 JavaScript 物件,如下所示。 |
進階參數
名稱 | 類型 | 說明 |
---|---|---|
commentsOnly | Boolean | 是否只清除留言。 |
contentsOnly | Boolean | 是否只要清除內容。 |
formatOnly | Boolean | 是否要僅清除格式;請注意,清除格式會一併清除資料驗證規則。 |
validationsOnly | Boolean | 是否僅清除資料驗證規則。 |
skipFilteredRows | Boolean | 是否要清除已篩選的資料列。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clearContent()
清除範圍清單中每個 Range
的內容,完整保留格式。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clearContent();
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clearDataValidations()
清除範圍清單中每個 Range
的資料驗證規則。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clearDataValidations();
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clearFormat()
清除範圍清單中每個 Range
的文字格式。
這會清除每個範圍的文字格式,但不會重設任何數字格式設定規則。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clearFormat();
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clearNote()
getRanges()
insertCheckboxes()
將核取方塊插入範圍中的每個儲存格,並將 true
設為已勾選,而 false
代表未勾選。將範圍內所有儲存格的值設為 false
。
var rangeList = SpreadsheetApp.getActive().getRangeList(['D4', 'E6']); // Inserts checkboxes into each cell in the ranges D4 and E6 configured with 'true' for checked // and 'false' for unchecked. Also, sets the value of each cell in the ranges D4 and E6 to // 'false'. rangeList.insertCheckboxes();
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertCheckboxes(checkedValue)
將核取方塊插入範圍中的每個儲存格,已設定勾選的自訂值,以及未勾選的空字串。將範圍內每個儲存格的值設為空字串。
var rangeList = SpreadsheetApp.getActive().getRangeList(['D4', 'E6']); // Inserts checkboxes into each cell in the ranges D4 and E6 configured with 'yes' for checked // and the empty string for unchecked. Also, sets the value of each cell in the ranges D4 and // E6 to the empty string. rangeList.insertCheckboxes('yes');
參數
名稱 | 類型 | 說明 |
---|---|---|
checkedValue | Object | 核取方塊資料驗證勾選的值。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertCheckboxes(checkedValue, uncheckedValue)
在範圍中的每個儲存格中插入核取方塊,並使用已勾選和未勾選狀態的自訂值進行設定。將範圍內每個儲存格的值設為自訂的未檢查值。
var rangeList = SpreadsheetApp.getActive().getRangeList(['D4', 'E6']); // Inserts checkboxes into each cell in the ranges D4 and E6 configured with 'yes' for checked // and 'no' for unchecked. Also, sets the value of each cell in the ranges D4 and E6 to 'no'. rangeList.insertCheckboxes('yes', 'no');
參數
名稱 | 類型 | 說明 |
---|---|---|
checkedValue | Object | 核取方塊資料驗證勾選的值。 |
uncheckedValue | Object | 核取方塊資料驗證的未勾選值。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeCheckboxes()
移除範圍內的所有核取方塊。清除每個儲存格的資料驗證,如果儲存格含有勾選或未勾選的值,也會清除該儲存格的值。
var range = SpreadsheetApp.getActive().getRange('A1:B10'); // Inserts checkboxes and sets each cell value to 'no' in the range A1:B10. range.insertCheckboxes('yes', 'no'); var rangeList1 = SpreadsheetApp.getActive().getRangeList(['A1', 'A3']); rangeList1.setValue('yes'); // Removes the checkbox data validation in cells A1 and A3 and clears their value. rangeList1.removeCheckboxes(); var rangeList2 = SpreadsheetApp.getActive().getRangeList(['A5', 'A7']); rangeList2.setValue('random'); // Removes the checkbox data validation in cells A5 and A7 but does not clear their value. rangeList2.removeCheckboxes();
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setBackground(color)
設定範圍清單中每個 Range
的背景顏色。顏色會以 CSS 標記法表示,例如 '#ffffff'
或 'white'
。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setBackground('red');
參數
名稱 | 類型 | 說明 |
---|---|---|
color | String | CSS 標記法 (例如 '#ffffff' 或 'white' ) 的背景顏色代碼,null 值會重設顏色。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setBackgroundRGB(red, green, blue)
將背景設為指定的 RGB 顏色。這是 setBackground(color)
呼叫的便利包裝函式。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); // Sets the background to red for each range in the range list. rangeList.setBackgroundRGB(255, 0, 0);
參數
名稱 | 類型 | 說明 |
---|---|---|
red | Integer | RGB 標記法中的紅色值。 |
green | Integer | RGB 標記法中的綠色值。 |
blue | Integer | RGB 標記法中的藍色值。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setBorder(top, left, bottom, right, vertical, horizontal)
設定範圍清單中每個 Range
的框線屬性。有效值為 true
(開啟)、false
(關閉) 和 null
(保持不變)。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A2:B4', 'C1:D4']); // Sets borders on the top and bottom of the ranges A2:B4 and C1:D4, but leaves the left and // right unchanged. rangeList.setBorder(true, null, true, null, false, false);
參數
名稱 | 類型 | 說明 |
---|---|---|
top | Boolean | true 代表無框線,false 代表無,null 代表不變更。 |
left | Boolean | true 代表無框線,false 代表無,null 代表不變更。 |
bottom | Boolean | true 代表無框線,false 代表無,null 代表不變更。 |
right | Boolean | true 代表無框線,false 代表無,null 代表不變更。 |
vertical | Boolean | true 代表內部垂直框線,false 代表無,null 代表不變更。 |
horizontal | Boolean | true 代表內部水平框線,false 表示無,null 代表不變更。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setBorder(top, left, bottom, right, vertical, horizontal, color, style)
為範圍清單中的每個 Range
設定顏色和/或樣式的邊框屬性。有效值為 true
(開啟)、false
(關閉) 和 null
(保持不變)。顏色會以 CSS 標記法表示,例如 '#ffffff'
或 'white'
。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A2:B4', 'C1:D4']); // Sets borders on the top and bottom, but leaves the left and right unchanged of the ranges // A2:B4 and C1:D4. Also sets the color to 'red', and the border to 'DASHED'. rangeList.setBorder( true, null, true, null, false, false, 'red', SpreadsheetApp.BorderStyle.DASHED);
參數
名稱 | 類型 | 說明 |
---|---|---|
top | Boolean | true 代表無框線,false 代表無,null 代表不變更。 |
left | Boolean | true 代表無框線,false 代表無,null 代表不變更。 |
bottom | Boolean | true 代表無框線,false 代表無,null 代表不變更。 |
right | Boolean | true 代表無框線,false 代表無,null 代表不變更。 |
vertical | Boolean | true 代表內部垂直框線,false 代表無,null 代表不變更。 |
horizontal | Boolean | true 代表內部水平框線,false 表示無,null 代表不變更。 |
color | String | CSS 標記法 (例如 '#ffffff' 或 'white' ) 的邊框顏色,null 代表預設顏色 (黑色)。 |
style | BorderStyle | 邊框樣式,null 代表預設樣式 (固定樣式)。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontColor(color)
設定範圍清單中每個 Range
的字型顏色。顏色會以 CSS 標記法表示,例如 '#ffffff'
或 'white'
。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontColor('red');
參數
名稱 | 類型 | 說明 |
---|---|---|
color | String | CSS 標記法 (例如 '#ffffff' 或 'white' ) 的字型顏色;null 值會重設顏色。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontFamily(fontFamily)
設定範圍清單中每個 Range
的字型系列。字型系列會透過 Arial
或 Roboto
等字串 ID 來描述。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontFamily('Roboto');
參數
名稱 | 類型 | 說明 |
---|---|---|
fontFamily | String | 要設定的字型系列;null 值會重設字型系列。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontLine(fontLine)
設定範圍清單中每個 Range
的字型行樣式。線條樣式選項為 'underline'
、'line-through'
或 'none'
。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontLine('line-through');
參數
名稱 | 類型 | 說明 |
---|---|---|
fontLine | String | 字型行樣式為 'underline' 、'line-through' 或 'none' ;null 值會重設字型行樣式。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontSize(size)
設定範圍清單中每個 Range
的字型大小 (以點為單位)。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontSize(20);
參數
名稱 | 類型 | 說明 |
---|---|---|
size | Integer | 字型大小。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontStyle(fontStyle)
為範圍清單中的每個 Range
設定字型樣式。字型樣式選項為 'italic'
或 'normal'
。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontStyle("italic");
參數
名稱 | 類型 | 說明 |
---|---|---|
fontStyle | String | 字型樣式 'italic' 或 'normal' ;null 值會重設字型樣式。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontWeight(fontWeight)
設定範圍清單中每個 Range
的字型粗細。字型粗細選項為 'normal'
或 'bold'
。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontWeight('bold');
參數
名稱 | 類型 | 說明 |
---|---|---|
fontWeight | String | 字型粗細 ('bold' 或 'normal' );null 值會重設字型粗細。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFormula(formula)
更新範圍清單中每個 Range
的公式。指定的公式必須採用 A1 標記法。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A11', 'C11']); rangeList.setFormula('=SUM(B1:B10)');
參數
名稱 | 類型 | 說明 |
---|---|---|
formula | String | 字串,代表要設定的公式。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFormulaR1C1(formula)
更新範圍清單中每個 Range
的公式。提供的公式必須是 R1C1 標記法。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A11', 'C11']); // This sets the formula to be the sum of the 3 rows above B5 rangeList.setFormulaR1C1('=SUM(R[-3]C[0]:R[-1]C[0])');
參數
名稱 | 類型 | 說明 |
---|---|---|
formula | String | 字串公式。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setHorizontalAlignment(alignment)
為範圍清單中的每個 Range
設定水平對齊。對齊選項為 'left'
、'center'
或 'right'
。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setHorizontalAlignment("center");
參數
名稱 | 類型 | 說明 |
---|---|---|
alignment | String | 'left' 、'center' 或 'normal' 對齊方式;null 值會重設對齊方式。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setNote(note)
設定範圍清單中每個 Range
的附註文字。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setNote('This is a note');
參數
名稱 | 類型 | 說明 |
---|---|---|
note | String | 要設定的附註文字,null 值會移除附註。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setNumberFormat(numberFormat)
設定範圍清單中每個 Range
的數字或日期格式。
如要瞭解系統支援的格式設定模式,請參閱 Sheets API 日期和數字格式指南。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A1:A10', 'C1:C10']); // Always show 3 decimal points for the specified ranges. rangeList.setNumberFormat('0.000');
參數
名稱 | 類型 | 說明 |
---|---|---|
numberFormat | String | 數字格式字串。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setShowHyperlink(showHyperlink)
設定範圍清單中的每個 Range
是否應顯示超連結。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A1:A10', 'C1:C10']); // Show hyperlinks for all the ranges. rangeList.setShowHyperlink(true);
參數
名稱 | 類型 | 說明 |
---|---|---|
showHyperlink | Boolean | 是否顯示超連結。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setTextDirection(direction)
設定範圍清單中每個 Range
的儲存格文字方向。如果指定方向為 null
,系統會推論方向然後設定。
// Sets right-to-left text direction each range in the range list. var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A1:A10', 'C1:C10']); rangeList.setTextDirection(SpreadsheetApp.TextDirection.RIGHT_TO_LEFT);
參數
名稱 | 類型 | 說明 |
---|---|---|
direction | TextDirection | 指定的文字方向;如果 null ,系統會在設定前推斷方向。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setTextRotation(degrees)
為範圍清單中每個 Range
的儲存格設定文字旋轉設定。輸入內容對應標準文字方向與所需方向之間的角度。如果輸入 0,表示文字已設為標準方向。
如果是從左到右的文字方向,正角則是逆時針方向,由右到左則為順時針方向。
// Sets the cells in the ranges A1:A10 and C1:C10 to have text rotated up 45 degrees. var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A1:A10', 'C1:C10']); rangeList.setTextRotation(45);
參數
名稱 | 類型 | 說明 |
---|---|---|
degrees | Integer | 標準螢幕方向與所需方向之間的所需角度。從左到右的文字中,正角是以逆時針方向呈現。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setValue(value)
設定範圍清單中每個 Range
的值。這個值可以是數字、字串、布林值或日期。如果開頭為「=」,系統會將此解析為公式。
var sheet = SpreadsheetApp.getActiveSheet(); // Set value of 100 to each range in the range list. var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setValue(100);
參數
名稱 | 類型 | 說明 |
---|---|---|
value | Object | 範圍的值。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setVerticalAlignment(alignment)
為範圍清單中的每個 Range
設定垂直對齊。對齊選項為 'top'
、'middle'
或 'bottom'
。
// Sets the vertical alignment to middle for the list of ranges. var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['D4', 'B2:C4']); rangeList.setVerticalAlignment("middle");
參數
名稱 | 類型 | 說明 |
---|---|---|
alignment | String | 'top' 、'middle' 或 'bottom' 對齊方式;null 值會重設對齊方式。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setVerticalText(isVertical)
設定是否要堆疊範圍清單中每個 Range
的儲存格文字。如果文字垂直堆疊,系統會忽略文字旋轉角度設定。
// Sets all cell's in ranges D4 and B2:D4 to have vertically stacked text. var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['D4', 'B2:C4']); rangeList.setVerticalText(true);
參數
名稱 | 類型 | 說明 |
---|---|---|
isVertical | Boolean | 是否堆疊文字。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setWrap(isWrapEnabled)
為範圍清單中的每個 Range
設定文字換行。啟用自動換行功能的儲存格可以調整大小,以便顯示完整內容。已停用換行功能的儲存格可在儲存格中盡可能顯示,且不調整大小或執行多行。
// Enable text wrap for the list of ranges. var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['D4', 'B2:C4']); rangeList.setWrap(true);
參數
名稱 | 類型 | 說明 |
---|---|---|
isWrapEnabled | Boolean | 是否自動換行。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setWrapStrategy(strategy)
為範圍清單中的每個 Range
設定文字包裝策略。
// Sets the list of ranges to use the clip wrap strategy. var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['D4', 'B2:C4']); rangeList.setWrapStrategy(SpreadsheetApp.WrapStrategy.CLIP);
參數
名稱 | 類型 | 說明 |
---|---|---|
strategy | WrapStrategy | 所需的包裝策略。 |
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
trimWhitespace()
在這個範圍清單的所有儲存格中,修剪空白字元 (例如空格、定位點或換行符號)。 移除每個儲存格文字開頭和結尾的所有空白字元,並將剩餘的空白字元序列減少為單一空格。
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; var range = sheet.getRange('A1:A4'); range.activate(); range.setValues( [' preceding space', 'following space ', 'two middle spaces', ' =SUM(1,2)']); var rangeList = sheet.getRangeList(['A1', 'A2', 'A3', 'A4']); rangeList.trimWhitespace(); var values = range.getValues(); // Values are ['preceding space', 'following space', 'two middle spaces', '=SUM(1,2)']
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
另請參閱
uncheck()
將範圍中核取方塊的狀態變更為「未勾選」。忽略目前範圍中不包含勾選或未勾選值的範圍。
// Changes the state of cells which currently contain either the checked or unchecked value // configured in the ranges D4 and E6 to 'unchecked'. var rangeList = SpreadsheetApp.getActive().getRangeList(['D4', 'E6']); rangeList.uncheck();
回攻員
RangeList
— 用於鏈結的範圍清單。
授權
使用這個方法的指令碼必須取得以下一或多個範圍的授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets