ExcelScript.RangeAreas interface

RangeAreas 表示同一工作表中一个或多个矩形区域的集合。

注解

示例

/**
 * This script clears all the cells in the current worksheet that are displaying errors.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the used range on the current sheet.
  const currentSheet = workbook.getActiveWorksheet();
  const usedRange = currentSheet.getUsedRange();

  // Get the RangeAreas object for each cell with a formula error.
  const errorCells = usedRange.getSpecialCells(ExcelScript.SpecialCellType.formulas, ExcelScript.SpecialCellValueType.errors);

  // If there are any error cells, clear them.
  if (errorCells) {
    errorCells.clear();
  }
}

方法

addConditionalFormat(type)

将新的条件格式添加到集合的第一个/最高优先级。

calculate()

计算 中的所有 RangeAreas单元格。

clear(applyTo)

清除构成此 RangeAreas 对象的每个区域的值、格式、填充、边框和其他属性。

clearAllConditionalFormats()

清除当前指定区域中处于活动状态的所有条件格式。

convertDataTypeToText()

将 中 RangeAreas 具有数据类型的所有单元格转换为文本。

copyFrom(sourceRange, copyType, skipBlanks, transpose)

将单元格数据或格式从源区域 或 RangeAreas 复制到当前 RangeAreas。 目标 RangeAreas 的大小可以不同于源范围或 RangeAreas。 如果目标小于源,则会自动展开。

getAddress()

返回 RangeAreas A1 样式的引用。 地址值将包含每个矩形单元格块的工作表名称, (例如“Sheet1!A1:B4,Sheet1!D1:D4“) 。

getAddressLocal()

返回 RangeAreas 用户区域设置中的引用。

getAreaCount()

返回构成此 RangeAreas 对象的矩形区域的数目。

getAreas()

返回构成此 RangeAreas 对象的矩形范围的集合。

getCellCount()

返回 对象中的 RangeAreas 单元格数,并汇总所有单个矩形区域的单元格计数。 如果单元格计数超过 2^31-1 (2,147,483,647),则返回 -1。

getConditionalFormat(id)

返回由其 ID 标识的条件格式。 如果条件格式对象不存在,则此方法返回 undefined

getConditionalFormats()

返回与此 RangeAreas 对象中的任何单元格相交的条件格式的集合。

getDataValidation()

返回 中所有范围 RangeAreas的数据验证对象。

getEntireColumn()

返回一个 RangeAreas 对象,该对象代表 (的 RangeAreas 整个列,例如,如果当前 RangeAreas 表示单元格“B4:E11, H2”,则返回一个 RangeAreas 表示列“B:E, H:H”) 。

getEntireRow()

返回一个 RangeAreas 对象,该对象代表 (的整个行 RangeAreas ,例如,如果当前 RangeAreas 表示单元格“B4:E11”,则返回表示 RangeAreas 行“4:11”) 。

getFormat()

返回一个 RangeFormat 对象,该对象封装对象中 RangeAreas 所有区域的字体、填充、边框、对齐方式和其他属性。

getIntersection(anotherRange)

返回 RangeAreas 表示给定区域或 RangeAreas的交集的对象。 如果未找到交集,则此方法返回 undefined

getIsEntireColumn()

指定此 RangeAreas 对象上的所有区域是否表示整个列 (例如“A:C, Q:Z”) 。

getIsEntireRow()

指定此 RangeAreas 对象上的所有区域是否表示 (整行,例如“1:3, 5:7”) 。

getOffsetRangeAreas(rowOffset, columnOffset)

返回由 RangeAreas 特定行和列偏移量移动的对象。 返回 RangeAreas 的 维度将与原始对象匹配。 如果生成的 RangeAreas 强制超出工作表网格的边界,将引发错误。

getPredefinedCellStyle()

表示此 RangeAreas 对象中所有区域的样式。 如果单元格的样式不一致, null 将返回 。 对于自定义样式,将返回样式名称。 对于内置样式,将返回一个表示枚举中的 BuiltInStyle 值的字符串。

getSpecialCells(cellType, cellValueType)

返回一个 RangeAreas 对象,该对象表示与指定类型和值匹配的所有单元格。 如果未找到与条件匹配的特殊单元格,则此方法返回 undefined

getTables(fullyContained)

返回与此 RangeAreas 对象中的任何范围重叠的表的作用域集合。

getUsedRangeAreas(valuesOnly)

返回包含对象中RangeAreas各个矩形区域的所有已用区域的使用的 RangeAreas 。 如果 中 RangeAreas没有使用的单元格,则此方法返回 undefined

getWorksheet()

返回当前 RangeAreas的工作表。

setDirty()

RangeAreas设置在下一次重新计算时要重新计算的 。

setPredefinedCellStyle(predefinedCellStyle)

表示此 RangeAreas 对象中所有区域的样式。 如果单元格的样式不一致, null 将返回 。 对于自定义样式,将返回样式名称。 对于内置样式,将返回一个表示枚举中的 BuiltInStyle 值的字符串。

方法详细信息

addConditionalFormat(type)

将新的条件格式添加到集合的第一个/最高优先级。

addConditionalFormat(type: ConditionalFormatType): ConditionalFormat;

参数

type
ExcelScript.ConditionalFormatType

要添加的条件格式的类型。 有关详细信息,请参阅 ExcelScript.ConditionalFormatType

返回

calculate()

计算 中的所有 RangeAreas单元格。

calculate(): void;

返回

void

clear(applyTo)

清除构成此 RangeAreas 对象的每个区域的值、格式、填充、边框和其他属性。

clear(applyTo?: ClearApplyTo): void;

参数

applyTo
ExcelScript.ClearApplyTo

可选。 确定清除操作的类型。 有关详细信息,请参阅 ExcelScript.ClearApplyTo。 默认值为“All”。

返回

void

示例

/**
 * This script clears all the cells in the current worksheet that are displaying errors.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the used range on the current sheet.
  const currentSheet = workbook.getActiveWorksheet();
  const usedRange = currentSheet.getUsedRange();

  // Get the RangeAreas object for each cell with a formula error.
  const errorCells = usedRange.getSpecialCells(ExcelScript.SpecialCellType.formulas, ExcelScript.SpecialCellValueType.errors);

  // If there are any error cells, clear them.
  if (errorCells) {
    errorCells.clear();
  }
}

clearAllConditionalFormats()

清除当前指定区域中处于活动状态的所有条件格式。

clearAllConditionalFormats(): void;

返回

void

convertDataTypeToText()

将 中 RangeAreas 具有数据类型的所有单元格转换为文本。

convertDataTypeToText(): void;

返回

void

copyFrom(sourceRange, copyType, skipBlanks, transpose)

将单元格数据或格式从源区域 或 RangeAreas 复制到当前 RangeAreas。 目标 RangeAreas 的大小可以不同于源范围或 RangeAreas。 如果目标小于源,则会自动展开。

copyFrom(
            sourceRange: Range | RangeAreas | string,
            copyType?: RangeCopyType,
            skipBlanks?: boolean,
            transpose?: boolean
        ): void;

参数

sourceRange

ExcelScript.Range | ExcelScript.RangeAreas | string

要从中复制的源范围或 RangeAreas 。 当源 RangeAreas 具有多个区域时,必须能够通过从矩形区域中删除完整的行或列来创建其窗体。

copyType
ExcelScript.RangeCopyType

要复制的单元格数据或格式的类型。 默认值为“All”。

skipBlanks

boolean

如此 如果跳过源区域或 RangeAreas中的空白单元格。 默认为 false。

transpose

boolean

如此 如果转置目标 RangeAreas中的单元格。 默认为 false。

返回

void

getAddress()

返回 RangeAreas A1 样式的引用。 地址值将包含每个矩形单元格块的工作表名称, (例如“Sheet1!A1:B4,Sheet1!D1:D4“) 。

getAddress(): string;

返回

string

getAddressLocal()

返回 RangeAreas 用户区域设置中的引用。

getAddressLocal(): string;

返回

string

getAreaCount()

返回构成此 RangeAreas 对象的矩形区域的数目。

getAreaCount(): number;

返回

number

getAreas()

返回构成此 RangeAreas 对象的矩形范围的集合。

getAreas(): Range[];

返回

getCellCount()

返回 对象中的 RangeAreas 单元格数,并汇总所有单个矩形区域的单元格计数。 如果单元格计数超过 2^31-1 (2,147,483,647),则返回 -1。

getCellCount(): number;

返回

number

getConditionalFormat(id)

返回由其 ID 标识的条件格式。 如果条件格式对象不存在,则此方法返回 undefined

getConditionalFormat(id: string): ConditionalFormat | undefined;

参数

id

string

条件格式的 ID。

返回

getConditionalFormats()

返回与此 RangeAreas 对象中的任何单元格相交的条件格式的集合。

getConditionalFormats(): ConditionalFormat[];

返回

getDataValidation()

返回 中所有范围 RangeAreas的数据验证对象。

getDataValidation(): DataValidation;

返回

getEntireColumn()

返回一个 RangeAreas 对象,该对象代表 (的 RangeAreas 整个列,例如,如果当前 RangeAreas 表示单元格“B4:E11, H2”,则返回一个 RangeAreas 表示列“B:E, H:H”) 。

getEntireColumn(): RangeAreas;

返回

getEntireRow()

返回一个 RangeAreas 对象,该对象代表 (的整个行 RangeAreas ,例如,如果当前 RangeAreas 表示单元格“B4:E11”,则返回表示 RangeAreas 行“4:11”) 。

getEntireRow(): RangeAreas;

返回

getFormat()

返回一个 RangeFormat 对象,该对象封装对象中 RangeAreas 所有区域的字体、填充、边框、对齐方式和其他属性。

getFormat(): RangeFormat;

返回

示例

/**
 * This script finds and highlights all the cells in the current worksheet that contain a formula.
 */
function main(workbook: ExcelScript.Workbook) {
  // Get the used range on the current sheet.
  const currentSheet = workbook.getActiveWorksheet();
  const usedRange = currentSheet.getUsedRange();

  // Get the RangeAreas object for each cell with a formula.
  const formulaCells = usedRange.getSpecialCells(ExcelScript.SpecialCellType.formulas);

  // Add a light blue background to the cells containing formulas.
  formulaCells.getFormat().getFill().setColor("#ADD8E6");
}

getIntersection(anotherRange)

返回 RangeAreas 表示给定区域或 RangeAreas的交集的对象。 如果未找到交集,则此方法返回 undefined

getIntersection(anotherRange: Range | RangeAreas | string): RangeAreas;

参数

anotherRange

ExcelScript.Range | ExcelScript.RangeAreas | string

用于确定交集的区域、 RangeAreas 对象或地址。

返回

getIsEntireColumn()

指定此 RangeAreas 对象上的所有区域是否表示整个列 (例如“A:C, Q:Z”) 。

getIsEntireColumn(): boolean;

返回

boolean

getIsEntireRow()

指定此 RangeAreas 对象上的所有区域是否表示 (整行,例如“1:3, 5:7”) 。

getIsEntireRow(): boolean;

返回

boolean

getOffsetRangeAreas(rowOffset, columnOffset)

返回由 RangeAreas 特定行和列偏移量移动的对象。 返回 RangeAreas 的 维度将与原始对象匹配。 如果生成的 RangeAreas 强制超出工作表网格的边界,将引发错误。

getOffsetRangeAreas(
            rowOffset: number,
            columnOffset: number
        ): RangeAreas;

参数

rowOffset

number

要偏移的行数 (正、负或 0) RangeAreas 。 正值表示向下偏移,负值表示向上偏移。

columnOffset

number

正、负或 0) 的列数 (,将按其 RangeAreas 进行偏移。 正值表示向右偏移,负值表示向左偏移。

返回

getPredefinedCellStyle()

表示此 RangeAreas 对象中所有区域的样式。 如果单元格的样式不一致, null 将返回 。 对于自定义样式,将返回样式名称。 对于内置样式,将返回一个表示枚举中的 BuiltInStyle 值的字符串。

getPredefinedCellStyle(): string;

返回

string

getSpecialCells(cellType, cellValueType)

返回一个 RangeAreas 对象,该对象表示与指定类型和值匹配的所有单元格。 如果未找到与条件匹配的特殊单元格,则此方法返回 undefined

getSpecialCells(
            cellType: SpecialCellType,
            cellValueType?: SpecialCellValueType
        ): RangeAreas;

参数

cellType
ExcelScript.SpecialCellType

要包含的单元格类型。

cellValueType
ExcelScript.SpecialCellValueType

如果 cellTypeconstantsformulas,则此参数用于确定结果中要包含的单元格类型。 这些值可以组合在一起以返回多个类型。 默认情况下,将选择所有常量或公式,无论类型如何。

返回

getTables(fullyContained)

返回与此 RangeAreas 对象中的任何范围重叠的表的作用域集合。

getTables(fullyContained?: boolean): Table[];

参数

fullyContained

boolean

如果 true为 ,则仅返回完全包含在范围边界内的表。 默认值为 false

返回

getUsedRangeAreas(valuesOnly)

返回包含对象中RangeAreas各个矩形区域的所有已用区域的使用的 RangeAreas 。 如果 中 RangeAreas没有使用的单元格,则此方法返回 undefined

getUsedRangeAreas(valuesOnly?: boolean): RangeAreas;

参数

valuesOnly

boolean

是否仅将具有值的单元格视为已用单元格。

返回

getWorksheet()

返回当前 RangeAreas的工作表。

getWorksheet(): Worksheet;

返回

setDirty()

RangeAreas设置在下一次重新计算时要重新计算的 。

setDirty(): void;

返回

void

setPredefinedCellStyle(predefinedCellStyle)

表示此 RangeAreas 对象中所有区域的样式。 如果单元格的样式不一致, null 将返回 。 对于自定义样式,将返回样式名称。 对于内置样式,将返回一个表示枚举中的 BuiltInStyle 值的字符串。

setPredefinedCellStyle(predefinedCellStyle: string): void;

参数

predefinedCellStyle

string

返回

void

示例

/**
 * This script sets the cell style to "warning text"
 * on every cell with a formula error.
 */ 
function main(workbook: ExcelScript.Workbook) {
  // Get the used range in the current worksheet.
  const sheet = workbook.getActiveWorksheet();
  const usedRange = sheet.getUsedRange();

  // Get any cells that are displaying errors.
  const errorCells = usedRange.getSpecialCells(
    ExcelScript.SpecialCellType.formulas,
    ExcelScript.SpecialCellValueType.errors
  );

  // Check if there are error cells before proceeding.
  if (errorCells) {
    // Use the built-in warning text style on the error cells.
    errorCells.setPredefinedCellStyle(
      ExcelScript.BuiltInStyle.warningText.toString()
    );
  } else {
    console.log("No formula errors in the worksheet.");
  }
}