Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

ExcelScript.ReplaceCriteria interface

Package:
ExcelScript

Represents the replace criteria to be used.

Properties

completeMatch

Specifies if the match needs to be complete or partial. A complete match matches the entire contents of the cell. A partial match matches a substring within the content of the cell (e.g., cat partially matches caterpillar and scatter). Default is false (partial).

matchCase

Specifies if the match is case-sensitive. Default is false (case-insensitive).

Property Details

completeMatch

Specifies if the match needs to be complete or partial. A complete match matches the entire contents of the cell. A partial match matches a substring within the content of the cell (e.g., cat partially matches caterpillar and scatter). Default is false (partial).

completeMatch?: boolean;

Property Value

boolean

Examples

/**
 * 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

Specifies if the match is case-sensitive. Default is false (case-insensitive).

matchCase?: boolean;

Property Value

boolean

Examples

/**
 * 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);
}

Feedback

Was this page helpful?