Document Solutions for Word
Report Templates / Template Configuration / Formatters / Restart List Formatter
In This Topic
    Restart List Formatter
    In This Topic

    DsWord provides 'restart' formatter in Report Templates which can be used for numbered lists to make them restart on each iteration within a template range. The template range here refers to a range where a template tag starts with a '#' and ends with a '/'.

    The below example explains the usage of 'restart' formatter when two numbered lists are used. As can be observed from the output, the numbered list is not restarted where the formatter itself is used, rather it is restarted on the inner numbered list.

    Template Tags Output (Template processing using a datasource)

    1. {{#companies}:restart()}{{companies.id}}

          a. {{companies.items.id}}{{/companies}}

    1. Company A

           a. Milk

           b. Eggs

    2. Company B

           a. Steel

           b. Aluminium

    3. Company C

           a. Wool

           b. Cotton

    The below example explains the usage of 'restart' formatter with 'all' parameter (optional) and two numbered lists. As can be observed from the output, the numbered list is restarted at both levels, with each iteration. 

    Template Tags Output (Template processing using a datasource)

    1. {{#companies}:restart(all)}{{companies.id}}

          a. {{companies.items.id}}{{/companies}}

    1. Company A

           a. Milk

           b. Eggs

    1. Company B

           a. Steel

           b. Aluminium

    1. Company C

           a. Wool

           b. Cotton

    The below example shows how to create a numbered list of oceans with a numbered list of seas unders its listing. Here, the numbered list of seas is restarted on each iteration by using the 'restart' formatter. The below image shows the template tags used inside the template. You can also download the Template layout here.

    The below code example loads the above template and processes it using a JSON data source:

    C#
    Copy Code
    var doc = new GcWordDocument();
    //Load template
    doc.Load("RestartFormatter[Template].docx");
                
    //Add datasource
    var oceans = File.OpenRead("oceans.json");
    doc.DataTemplate.DataSources.Add("ds", oceans);
    
    //Process template
    doc.DataTemplate.Process();
    doc.Save("RestartListFormatter.docx");

    The output of above code example will look like below: