GdPicture.NET.14.API
GdPicture14 Namespace / GdPictureOfficeTemplater Class / SetTemplate Method / SetTemplate(GdPictureOfficeTemplate,GdPictureOfficeTemplateConfiguration) Method
The template model (containing placeholder values) to use.
The configuration for template replacement.
Example





In This Topic
SetTemplate(GdPictureOfficeTemplate,GdPictureOfficeTemplateConfiguration) Method
In This Topic
Sets the template and its configuration for use in replacement operations.
Syntax
Example
Create template programmatically
using GdPicture14;
            
string sourceFile = "file.docx";
string outputFile = "output.docx";
            
GdPictureOfficeTemplate template = GdPictureOfficeDefaultTemplateBuilder.CreateTemplate()
    .AddPlaceholderReplacement(placeholder: "placeholder1", replacementValue: "replacementValue 1")
    .AddPlaceholderReplacement(placeholder: "placeholder2", replacementValue: "replacementValue 2");
            
GdPictureOfficeTemplateConfiguration configuration = new GdPictureOfficeTemplateConfiguration
{
    Delimiter = new GdPictureOfficeTemplateDelimiter
    {
        Start = "{{",
        End = "}}"
    }
};
using GdPictureOfficeTemplater templater = new();
            
GdPictureStatus status = templater.SetTemplate(template, configuration);
if (status == GdPictureStatus.OK)
{
    status = templater.LoadFromFile(sourceFile);
    if (status == GdPictureStatus.OK)
    {
        status = templater.Process();
        if (status == GdPictureStatus.OK)
        {
            status = templater.SaveToFile(outputFile);
            Console.WriteLine("Save status: " + status);
        }
    }
}
Console.WriteLine("Last status: " + templater.GetStat() + Environment.NewLine);
See Also