同一工作表中一个或多个 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
等字符串标识符描述。
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