GdPicture.NET.14.API
GdPicture14 Namespace / GdPictureOfficeTemplater Class / Process Method
Example





In This Topic
Process Method (GdPictureOfficeTemplater)
In This Topic
Processes the loaded template, replacing placeholders with actual values.
Syntax
'Declaration
 
Public Function Process() As GdPictureStatus
public GdPictureStatus Process()
public function Process(): GdPictureStatus; 
public function Process() : GdPictureStatus;
public: GdPictureStatus Process(); 
public:
GdPictureStatus Process(); 

Return Value

The GdPictureStatus of the operation.
Example
Process a template using a JSON templateCreate template programmatically
using GdPicture14;
            
string sourceFile = "file.docx";
string outputFile = "output.docx";
string json = @"
{
	'config': {
		'delimiter': {
			'start': '{{',
			'end': '}}'
		}
	},
	'model': {
		'placeholder1': 'replacementValue 1',
		'placeholder2': 'replacementValue 2'
	}
}";
            
using GdPictureOfficeTemplater templater = new();
            
GdPictureStatus status = templater.SetTemplate(json);
            
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);
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