-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreplace-in-sheet.ts
More file actions
24 lines (23 loc) · 881 Bytes
/
replace-in-sheet.ts
File metadata and controls
24 lines (23 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* Replaces all occurrences of a value in a worksheet with a new value.
*
* @param sheetName Name of the worksheet to perform replacements in.
* @param oldValue The value to search for.
* @param newValue The value to replace matches with.
* @param matchCase Whether the search should be case-sensitive (defaults to false).
* @param matchEntireCellContents Whether to match only cells whose entire contents equal oldValue (defaults to false).
*/
function main(
workbook: ExcelScript.Workbook,
sheetName: string,
oldValue: string,
newValue: string,
matchCase: boolean = false,
matchEntireCellContents: boolean = false
) {
const sheet = workbook.getWorksheet(sheetName);
if (!sheet) {
throw new Error(`Worksheet '${sheetName}' not found.`);
}
sheet.replaceAll(oldValue, newValue, { matchCase: matchCase, completeMatch: matchEntireCellContents });
}