ExcelScript.ReplaceCriteria interface

表示要使用的替换条件。

属性

completeMatch

指定匹配是需要完整匹配还是部分匹配。 完全匹配与单元格的整个内容匹配。 部分匹配与单元格内容中的子字符串匹配 (例如, cat 部分匹配 caterpillarscatter) 。 默认值为 false (部分) 。

matchCase

指定匹配项是否区分大小写。 默认值 (false 不区分大小写) 。

属性详细信息

completeMatch

指定匹配是需要完整匹配还是部分匹配。 完全匹配与单元格的整个内容匹配。 部分匹配与单元格内容中的子字符串匹配 (例如, cat 部分匹配 caterpillarscatter) 。 默认值为 false (部分) 。

completeMatch?: boolean;

属性值

boolean

示例

/**
 * This script normalizes the text in a column so that values don't include both "OK" and "okay". 
 * It replaces "OK" and all the case-based variants with "okay".
 */ 
function main(workbook: ExcelScript.Workbook) {
  // Get the range representing column D.
  const currentSheet = workbook.getActiveWorksheet();
  const column = currentSheet.getRange("D:D");

  // Create a ReplaceCriteria object for the Range.replaceAll call.
  const criteria: ExcelScript.ReplaceCriteria = {
    completeMatch: true, /* Use a complete match to skip cells that already say "okay". */
    matchCase: false /* Ignore case when comparing strings. */
  };

  // Replace all instances of "ok" (case-insensitive) with "okay".
  column.replaceAll("ok", "okay", criteria);
}

matchCase

指定匹配项是否区分大小写。 默认值 (false 不区分大小写) 。

matchCase?: boolean;

属性值

boolean

示例

/**
 * This script replaces instances of "NA" with "North America", 
 * using the casing to ignore parts of words.
 */ 
function main(workbook: ExcelScript.Workbook) {
  // Get the currently used range.
  const currentSheet = workbook.getActiveWorksheet();
  const usedRange = currentSheet.getUsedRange();

  // Create a ReplaceCriteria object for the Range.replaceAll call.
  const criteria: ExcelScript.ReplaceCriteria = {
    completeMatch: false, 
    matchCase: true /* Match with "NA market", not "navigate" */
  }

  // Replace all instances of "NA" (case-sensitive) with "North America".
  usedRange.replaceAll("NA", "North America", criteria);
}