A global "Search and Replace" function
Purpose
Performs a case-sensitive "Search and Replace". In Word and HTML it can be global (default) or can be limited to just the previous table. In PowerPoint it covers the current slide (default) or, with the 'powerPointScope' parameter, every slide in the presentation; 'scope=previousTable' limits it to the table on the current slide. As with other macros, these are run in the order they appear in the template, so may affect each other. Note that the contents of the report at the time the macro is run are considered.
Compatibility
The macro can be used in all input document types and in Report Studio.
Usage
In PowerPoint, slide notes are never searched: put the macro in the notes of a slide, or in any shape on it, and it acts on that slide's shapes and tables. Text is matched within a single run of identically formatted text. Word and PowerPoint split text into runs at formatting changes and at words flagged as misspelt, so a phrase spanning such a boundary is not matched, whereas a single word always is.
Updates
In Word, a replaceWith value that contains the find value (for example find=Total, replaceWith=Total Logins) now replaces each occurrence once and finishes. Previously the macro replaced its own output again and again, so the report never completed.
History (2)
Can now be used in PowerPoint input documents. By default the replacement covers the current slide (the slide whose notes or shapes contain the macro); the new powerPointScope parameter can widen it to every slide in the presentation, and scope=previousTable limits it to the table on the current slide. Slide notes are never searched. Previously the macro reported that it was not supported in PowerPoint.
An empty replaceWith with scope=previousTable now clears the matched text, instead of the macro failing with an unexpected error when the found text was a cell's entire content.
Behaviour (2)8 additional
| Parameter | Type | Presence | Purpose | Options | Default |
| PowerPointScopeType | Optional | In PowerPoint input documents only: whether to search and replace on the current slide (the slide whose notes or shapes contain the macro), or on every slide in the presentation. When not set, the current slide is used. Slide notes are never searched. In Word and HTML this parameter is ignored, with a warning. |
|
N/A | |
| String | Optional | Whether to search and replace in the entire document or just the previous table. In PowerPoint, previousTable means the table on the current slide (there must be exactly one), and document defers to the 'powerPointScope' parameter. |
|
document |
Additional (8)
| Parameter | Type | Presence | Purpose | Options | Default |
| List<ExecutionResult> | Optional | If specified, asserts the expected execution result of the macro. Accepts a single value or a semicolon-separated list of acceptable values (e.g. 'Success;Warning'). The macro executes normally; if the actual result matches any of the desired values, the result is converted to Success. If the actual result does not match, the result is converted to MacroError with a descriptive message. This is primarily used for testing and diagnostic purposes. Valid values are: 'Unknown', 'Success', 'MacroError', 'WorkerStopped', 'Running', 'Warning', 'NeverRun', 'Cancelled', 'Pending', 'Paused', 'SystemError', 'Deferred' and 'Stopped'. |
|
N/A | |
| Boolean | Optional | Should NCalc expression evaluation throw error on Overflow |
|
true | |
| String | Optional | If specified, asserts the expected output type of the macro result. The macro executes normally; if the actual type does not match, a macro error is generated. Requires 'storeAs', 'storeAsHidden', or 'storeFormattedValueAs' to be set for typed validation. Valid types include CLR names (e.g. Int32, Int64, Single, Double, Boolean, String, JArray, JObject) and C# keyword aliases (e.g. int, long, float, double, bool, string, uint, ulong, short, ushort, byte, sbyte, decimal, char, object). The special value 'Number' matches any numeric type. | N/A | N/A | |
| String | Optional | If specified, asserts the expected output value of the macro result. The macro executes normally; if the actual value does not match, a macro error is generated. When 'storeAs' or 'storeAsHidden' is set, the stored variable value is compared. Otherwise, the document output text is compared. | N/A | N/A | |
| String | Optional | An optional condition that must be true in order for the macro to execute. See [If:] macro for more information. | N/A | N/A | |
| MacroMode | Optional | The mode in which variables are stored. In legacy mode (default for Schedules), the variable created is a string and formatted. In normal mode (default for Report Studio), the output variable is stored as a strongly-typed object, e.g. an Int32 or a JArray etc., rather than a formatted string. |
|
Legacy | |
| ObfuscationType | Optional | Obfuscation type. Use obfuscation to write reports where sensitive data is hidden. When used, ReportMagic guarantees that the same input string will map to the same output string for the whole of the report (but the next time the report runs, it will most likely map to a different value). If you use obfuscation, the property in your macro will not show up and instead, you will see a fake item of the obfuscation type chosen. |
|
None | |
| String | Optional | If specified, adds a warning message for this macro. This is processed as an NCalc, and the warning message will ALWAYS be present and will be the value of the evaluated NCalc expression. | N/A | N/A |
Filtering & Sorting (2)
Output (2)
| Parameter | Type | Presence | Purpose | Options | Default |
| String | Optional | The text to display should the macro fail to execute. Note that a poorly-specified macro (e.g. omitting mandatory parameters) will still result in an error message. | N/A | N/A | |
| String | Optional | The name of a variable to create should the macro fail to execute. The variable will be a text variable, and will contain either the failure text (only if the failureText parameter is set), otherwise it will contain the exception / failure message. | N/A | N/A |
Examples (7)
Example 1
[SearchAndReplace: find=Total Logins, replaceWith=Login attempts]Example 2
Search and replace only in the previous table:
[SearchAndReplace: find=Total Logins, replaceWith=Login attempts, scope=previousTable]Example 3
In PowerPoint, search and replace on the current slide only (the macro can be in the slide's notes or in any shape on the slide):
[SearchAndReplace: find=DRAFT, replaceWith=FINAL]Example 4
In PowerPoint, search and replace on every slide in the presentation:
[SearchAndReplace: find=DRAFT, replaceWith=FINAL, powerPointScope=Presentation]Example 5
Search and replace using the condition parameter and a table - note that you must put the first 2 lines below into a table:
[String: value=True, storeAsHidden=PleaseReplaceItems]
Router1 is here!
[SearchAndReplace: find=Router, replaceWith=Switch, scope=previousTable, if="'{PleaseReplaceItems}' == 'True' "]Example 6
Search and replace using the condition parameter:
[String: value=True, storeAsHidden=PleaseReplaceItems]
Router1 is here!
[SearchAndReplace: find=Router, replaceWith=Switch, if="'{PleaseReplaceItems}' == 'True' "]Example 7
Search and replace using an If/Else macro and condition parameter:
[String: value=Total Logins, storeAs=X] [SearchAndReplace: find=Total Logins, replaceWith=Login attempt] [If: condition="endsWith(X, 't')"]Yes.[Else:] no [EndIf:]