ExcelScript.ReplaceCriteria interface
Represents the replace criteria to be used.
Properties
complete |
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., |
match |
Specifies if the match is case-sensitive. Default is |
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);
}
Office Scripts