同一工作表中的一个或多个 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()
将范围列表中包含的所有水平或垂直合并的单元格再次拆分为单独的单元格。
对范围列表调用此函数相当于选择一组范围,然后选择格式 > 合并 > 取消合并工作表菜单项。
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()
清除范围列表中每个 Range
的备注。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['A:A', 'C:C']); rangeList.clearNote();
弃踢回攻
RangeList
- 此范围列表,用于串联。
授权
使用此方法的脚本需要获得以下一个或多个范围的授权:
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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
中的单元格进行文本旋转设置。输入对应于标准文本方向与所需方向之间的角度。如果输入值为零,则表示文本设置为标准方向。
对于从左到右的文本方向,正角度为逆时针方向,而正角为从右到左的顺时针方向。
// 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