[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.Workbook.ProcessTemplate

ProcessTemplate Method

ProcessTemplate()

Processes the workbook as a template by evaluating template fields and replacing them with data from the workbook's data sources.

Call this method after adding one or more data sources with AddDataSource(string, object).

Declaration
public void ProcessTemplate()
Public Sub ProcessTemplate()
Implements
Examples
worksheet.Range["A1"].Value = "{{ds.name}}";
string json = "[{\"name\":\"jack\",\"age\":12,\"height\":160},{\"name\":\"alice\",\"age\":25,\"height\":165},{\"name\":\"peter\",\"age\":21,\"height\":180}]";
workbook.AddDataSource("ds", new JsonDataSource(json));
workbook.ProcessTemplate();
object value = worksheet.Range["A1"].Value;

ProcessTemplate(CancellationToken)

Processes the workbook as a template and observes cancellation requests through the specified cancellation token.

Use this method to process template data in the current workbook while allowing the operation to be canceled through a CancellationToken.

Declaration
public void ProcessTemplate(CancellationToken cancellationToken)
Public Sub ProcessTemplate(cancellationToken As CancellationToken)
Parameters
Type Name Description
CancellationToken cancellationToken

A token used to monitor cancellation requests. Use None if cancellation is not required.

Implements
Examples
worksheet.Range["A1"].Value = "{{ds.name}}";
string json = "[{\"name\":\"jack\",\"age\":12,\"height\":160},{\"name\":\"alice\",\"age\":25,\"height\":165},{\"name\":\"peter\",\"age\":21,\"height\":180}]";
workbook.AddDataSource("ds", new JsonDataSource(json));
using (CancellationTokenSource cancellation = new CancellationTokenSource())
{
    workbook.ProcessTemplate(cancellation.Token);
}
Exceptions
Type Condition
OperationCanceledException

Thrown if cancellationToken is canceled while template processing is in progress.