同一工作表中的一或多個 Range 執行個體集合。您可以使用這個類別,對非相鄰範圍或儲存格的集合套用作業。
方法
內容詳盡的說明文件
activate()
選取Range執行個體清單。清單中的最後一個範圍會設為 active range。
注意:這樣就能選取多個範圍。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['D4', 'B2:C4']); rangeList.activate(); 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:有效範圍的清單,用於鏈結。
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
break Apart()
將範圍清單中所有水平或垂直合併的儲存格再次分割為個別儲存格。
在範圍清單中呼叫這個函式,相當於選取一組範圍,然後選取「格式」>「合併」>「取消合併」試算表選單項目。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.breakApart();
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
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'. const rangeList = SpreadsheetApp.getActive().getRangeList(['D4', 'E6']); rangeList.check();
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
clear()
清除範圍清單中每個 Range 的內容、格式和資料驗證規則。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clear();
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
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. const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clear({contentsOnly: true});
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
options | Object | 指定進階參數的 JavaScript 物件,如下所示。 |
進階參數
| 名稱 | 類型 | 說明 |
|---|---|---|
comments | Boolean | 是否只清除留言。 |
contents | Boolean | 是否只清除內容。 |
format | Boolean | 是否只清除格式;請注意,清除格式也會清除資料驗證規則。 |
validations | Boolean | 是否只清除資料驗證規則。 |
skip | Boolean | 是否要避免清除已篩選的資料列。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
clear Content()
清除範圍清單中每個 Range 的內容,但保留格式。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clearContent();
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
clear Data Validations()
清除範圍清單中每個 Range 的資料驗證規則。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clearDataValidations();
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
clear Format()
清除範圍清單中每個 Range 的文字格式。
這會清除每個範圍的文字格式,但不會重設任何數字格式規則。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clearFormat();
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
clear Note()
清除範圍清單中每個 Range 的附註。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clearNote();
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
get Ranges()
insert Checkboxes()
在範圍內的每個儲存格中插入核取方塊,並將勾選狀態設為 true,未勾選狀態設為 false。將範圍內所有儲存格的值設為 false。
const 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();
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
insert Checkboxes(checkedValue)
在範圍內的每個儲存格中插入核取方塊,並為勾選和未勾選狀態設定自訂值 (未勾選狀態的值為空字串)。將範圍中每個儲存格的值設為空字串。
const 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');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
checked | Object | 核取方塊資料驗證的勾選值。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
insert Checkboxes(checkedValue, uncheckedValue)
在範圍內的每個儲存格中插入核取方塊,並為勾選和未勾選狀態設定自訂值。將範圍中每個儲存格的值設為自訂未勾選值。
const 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');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
checked | Object | 核取方塊資料驗證的勾選值。 |
unchecked | Object | 核取方塊資料驗證的未勾選值。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
remove Checkboxes()
移除範圍內的所有核取方塊。清除每個儲存格的資料驗證,並在儲存格包含勾選或未勾選的值時,一併清除值。
const range = SpreadsheetApp.getActive().getRange('A1:B10'); // Inserts checkboxes and sets each cell value to 'no' in the range A1:B10. range.insertCheckboxes('yes', 'no'); const 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(); const 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();
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Background(color)
為範圍清單中的每個 Range 設定背景顏色。顏色以 CSS 標記表示,例如 '#ffffff' 或 'white'。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setBackground('red');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
color | String | CSS 標記中的背景顏色代碼,例如 '#ffffff' 或 'white';null 值會重設顏色。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Background RGB(red, green, blue)
將背景設為指定的 RGB 顏色。這是 set 呼叫的便利包裝函式。
const sheet = SpreadsheetApp.getActiveSheet(); const 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 標記法中的藍色值。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Border(top, left, bottom, right, vertical, horizontal)
為範圍清單中的每個 Range 設定邊框屬性。有效值為 true (開啟)、false (關閉) 和 null (不變更)。
const sheet = SpreadsheetApp.getActiveSheet(); const 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 代表不變更。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Border(top, left, bottom, right, vertical, horizontal, color, style)
為範圍清單中的每個 Range 設定邊框屬性,包括顏色和/或樣式。
有效值為 true (開啟)、false (關閉) 和 null (不變)。顏色以 CSS 標記表示,例如 '#ffffff' 或 'white'。
const sheet = SpreadsheetApp.getActiveSheet(); const 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 | Border | 邊框的樣式,null 為預設樣式 (實線)。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Font Color(color)
設定範圍清單中每個 Range 的字型顏色。顏色以 CSS 標記表示,例如 '#ffffff' 或 'white'。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontColor('red');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
color | String | CSS 標記中的字型顏色,例如 '#ffffff' 或 'white';null 值會重設顏色。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Font Family(fontFamily)
為範圍清單中的每個 Range 設定字型系列。字型系列會以字串 ID (例如 Arial 或 Roboto) 說明。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontFamily('Roboto');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
font | String | 要設定的字型系列;null 值會重設字型系列。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Font Line(fontLine)
為範圍清單中的每個 Range 設定字型行樣式。線條樣式選項為 'underline'、'line-through' 或 'none'。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontLine('line-through');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
font | String | 字型線條樣式,可以是 'underline'、'line-through' 或 'none';null 值會重設字型線條樣式。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Font Size(size)
為範圍清單中的每個 Range 設定字型大小 (以點為單位)。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontSize(20);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
size | Integer | 字型大小 (以點為單位)。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Font Style(fontStyle)
為範圍清單中的每個 Range 設定字型樣式。字型樣式選項為 'italic' 或 'normal'。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontStyle('italic');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
font | String | 字型樣式,可以是 'italic' 或 'normal';null 值會重設字型樣式。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Font Weight(fontWeight)
在範圍清單中,為每個 Range 設定字體粗細。字型粗細選項為 'normal' 或 'bold'。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setFontWeight('bold');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
font | String | 字型粗細,可以是 'bold' 或 'normal';null 值會重設字型粗細。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Formula(formula)
更新範圍清單中每個 Range 的公式。提供的公式必須採用 A1 標記法。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A11', 'C11']); rangeList.setFormula('=SUM(B1:B10)');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
formula | String | 代表要設定公式的字串。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Formula R1C1(formula)
更新範圍清單中每個 Range 的公式。提供的公式必須採用 R1C1 標記法。
const sheet = SpreadsheetApp.getActiveSheet(); const 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 | 字串公式。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Horizontal Alignment(alignment)
在範圍清單中,為每個 Range 設定水平對齊方式。對齊選項包括 'left'、'center' 或 'right'。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setHorizontalAlignment('center');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
alignment | String | 對齊方式,可以是 'left'、'center' 或 'normal';null 值會重設對齊方式。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Note(note)
設定範圍清單中每個 Range 的附註文字。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setNote('This is a note');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
note | String | 要設定的附註文字;null 值會移除附註。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Number Format(numberFormat)
為範圍清單中的每個 Range 設定數字或日期格式。
如要瞭解可接受的格式模式,請參閱 Google Sheets API 日期和數字格式指南。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A1:A10', 'C1:C10']); // Always show 3 decimal points for the specified ranges. rangeList.setNumberFormat('0.000');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
number | String | 數字格式字串。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Show Hyperlink(showHyperlink)
設定範圍清單中的每個 Range 是否應顯示超連結。
const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A1:A10', 'C1:C10']); // Show hyperlinks for all the ranges. rangeList.setShowHyperlink(true);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
show | Boolean | 是否顯示超連結。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Text Direction(direction)
為範圍清單中每個 Range 的儲存格設定文字方向。如果指定方向為 null,系統會推斷並設定方向。
// Sets right-to-left text direction each range in the range list. const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A1:A10', 'C1:C10']); rangeList.setTextDirection(SpreadsheetApp.TextDirection.RIGHT_TO_LEFT);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
direction | Text | 所需文字方向;如果 null 方向是在設定前推斷而來。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Text Rotation(degrees)
為範圍清單中每個 Range 的儲存格設定文字旋轉設定。輸入值對應於標準文字方向與所需方向之間的角度。輸入零表示文字設為標準方向。
如果是從左到右的文字方向,正角度為逆時針方向;如果是從右到左,則為順時針方向。
// Sets the cells in the ranges A1:A10 and C1:C10 to have text rotated up 45 // degrees. const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['A1:A10', 'C1:C10']); rangeList.setTextRotation(45);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
degrees | Integer | 標準方向與所需方向之間的角度。如果是從左到右的文字,正角度為逆時針方向。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Value(value)
設定範圍清單中每個 Range 的值。值可以是數字、字串、布林值或日期。如果以「=」開頭,系統會將其解讀為公式。
const sheet = SpreadsheetApp.getActiveSheet(); // Set value of 100 to each range in the range list. const rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.setValue(100);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
value | Object | 範圍的值。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Vertical Alignment(alignment)
在範圍清單中,為每個 Range 設定垂直對齊方式。對齊選項包括 'top'、'middle' 或 'bottom'。
// Sets the vertical alignment to middle for the list of ranges. const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['D4', 'B2:C4']); rangeList.setVerticalAlignment('middle');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
alignment | String | 對齊方式,可以是 'top'、'middle' 或 'bottom';null 值會重設對齊方式。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Vertical Text(isVertical)
設定是否要堆疊範圍清單中每個 Range 的儲存格文字。如果文字是垂直堆疊,系統會忽略文字旋轉角度設定。
// Sets all cell's in ranges D4 and B2:D4 to have vertically stacked text. const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['D4', 'B2:C4']); rangeList.setVerticalText(true);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
is | Boolean | 是否要堆疊文字。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Wrap(isWrapEnabled)
在範圍清單中,為每個 Range 設定文字換行。啟用自動換行後,儲存格會調整大小,顯示完整內容。如果停用自動換行,系統會盡可能在儲存格中顯示內容,不會調整大小或換行。
// Enable text wrap for the list of ranges. const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['D4', 'B2:C4']); rangeList.setWrap(true);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
is | Boolean | 是否要自動換行。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
set Wrap Strategy(strategy)
為範圍清單中的每個 Range 設定文字換行策略。
// Sets the list of ranges to use the clip wrap strategy. const sheet = SpreadsheetApp.getActiveSheet(); const rangeList = sheet.getRangeList(['D4', 'B2:C4']); rangeList.setWrapStrategy(SpreadsheetApp.WrapStrategy.CLIP);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
strategy | Wrap | 所需的換行策略。 |
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets
trim Whitespace()
修剪這個範圍清單中每個儲存格的空白字元 (例如空格、定位點或換行符號)。 移除每個儲存格文字開頭和結尾的所有空白字元,並將所有後續的空白字元縮減為單一空格。
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; const range = sheet.getRange('A1:A4'); range.activate(); range.setValues([ ' preceding space', 'following space ', 'two middle spaces', ' =SUM(1,2)', ]); const rangeList = sheet.getRangeList(['A1', 'A2', 'A3', 'A4']); rangeList.trimWhitespace(); const values = range.getValues(); // Values are ['preceding space', 'following space', 'two middle spaces', // '=SUM(1,2)']
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
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'. const rangeList = SpreadsheetApp.getActive().getRangeList(['D4', 'E6']); rangeList.uncheck();
回攻員
Range - This range list, for chaining.
授權
使用這個方法的指令碼需要透過下列一或多個範圍授權:
-
https://www.googleapis.com/auth/spreadsheets.currentonly -
https://www.googleapis.com/auth/spreadsheets