Skip to content

Replace

Replaces every occurrence of a text in the range.

1
myContentRange.Replace(search: string, replacement: string, format?: object):void

Parameters

string search
    The text to find.

string replacement
    The text to insert.

object format optional
    Character format properties applied to the inserted text.

Remarks

When format is given, its character format properties, such as Bold, Italic or Size, are applied to the replaced text. Use distinctive placeholders, such as {CustomerName}, so that ordinary text is not replaced by accident.

Examples

Fill the placeholders of a Word template

1
2
3
4
5
6
7
8
9
var writer = new Writer();
writer.LoadFromBase64($Files.GetBase64($Xml.Evaluate('Template')));

writer.Content.Replace('{CustomerName}', $Xml.Evaluate('Customer/Name'));
writer.Content.Replace('{OrderDate}', $Xml.Evaluate('OrderDate'));
writer.Content.Replace('{Total}', $Xml.Evaluate('Total'), { Bold : true });

var file = $Files.AddBase64(writer.SaveToBase64('.pdf'), 'Order.pdf', 'application/pdf');
$Xml.SetValue('OrderDocument', file.Id);