<ol> tag issue in docx and aspose23

below is input file
input.docx (12.0 KB)

actual output

why ol tag is taking some left padding in docx what is the correct way for docx format.

expected output

@QATESTGHS You can use the following code to get the expected output:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.Writeln("Some regular paragraph");
builder.InsertHtml(@"<ol><li>Accès</li><li>ALTA - Garantie - Propriétaire</li><li>Arbitrage (suppression)</li><li>Certificat de localisation (Absence de Certificat)</li></ol>", true);

foreach (Paragraph p in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (p.IsListItem)
        p.ParagraphFormat.LeftIndent = p.ParagraphFormat.LeftIndent - p.ListFormat.ListLevel.NumberPosition;
}

doc.Save(@"C:\Temp\out.docx");

When you insert a list using InsertHtml method, default list formatting is applied to it.

Hi @alexey.noskov still issue persists below is my code pls have look and suggest me.

public class HandleMergeFieldInsertHtml : a.MailMerging.IFieldMergingCallback
{
    void a.MailMerging.IFieldMergingCallback.FieldMerging(a.MailMerging.FieldMergingArgs e)
    {
        if (e.DocumentFieldName.StartsWith("html", StringComparison.OrdinalIgnoreCase))
        {
            var builder = new a.DocumentBuilder(e.Document);
            builder.MoveToMergeField(e.DocumentFieldName);

            //builder.InsertHtml(BuildHtmlFontString(builder.Font) + (string)e.FieldValue + "</font>");

            if (e.FieldValue != null)
                builder.InsertHtml(e.FieldValue.ToString(), a.HtmlInsertOptions.UseBuilderFormatting);

            foreach (a.Paragraph p in e.Document.GetChildNodes(a.NodeType.Paragraph, true))
            {
                if (p.IsListItem)
                    p.ParagraphFormat.LeftIndent = p.ParagraphFormat.LeftIndent - p.ListFormat.ListLevel.NumberPosition;
            }
            e.Text = "";
        }

    }

@QATESTGHS Could you please attach your sample template and output documents here or our reference? We will check the issue and provide you more information.

@alexey.noskov

Below is actual output

this one is expected output

this one is input tempate
Inpute_template.docx (26.1 KB)

@QATESTGHS The code works fine on my side. Please see the following code used for testing on my side:

DataTable data = new DataTable("Table6");
data.Columns.Add("RowNumber");
data.Columns.Add("htmlEndorsementIndex");
data.Rows.Add(
    "Les aveants suivants font partie integrante de la Police:",
    @"<ol><li>Accès</li><li>ALTA - Garantie - Propriétaire</li><li>Arbitrage (suppression)</li><li>Certificat de localisation (Absence de Certificat)</li></ol>");

Document doc = new Document(@"C:\Temp\in.docx");
doc.MailMerge.FieldMergingCallback = new HandleMergeFieldInsertHtml();
doc.MailMerge.ExecuteWithRegions(data);
doc.Save(@"C:\Temp\out.docx");
public class HandleMergeFieldInsertHtml : IFieldMergingCallback
{
    public void FieldMerging(FieldMergingArgs e)
    {
        if (e.DocumentFieldName.StartsWith("html", StringComparison.OrdinalIgnoreCase))
        {
            DocumentBuilder builder = new DocumentBuilder(e.Document);
            builder.MoveToField(e.Field, true);

            if (e.FieldValue != null)
            {
                Node currentNode = builder.CurrentParagraph;
                builder.InsertHtml(e.FieldValue.ToString(), HtmlInsertOptions.UseBuilderFormatting);

                while (currentNode != builder.CurrentParagraph)
                {
                    Paragraph p = currentNode as Paragraph;
                    if (p != null && p.IsListItem)
                        p.ParagraphFormat.LeftIndent = p.ParagraphFormat.LeftIndent - p.ListFormat.ListLevel.NumberPosition;

                    currentNode = currentNode.NextSibling;
                }
            }

            e.Text = "";
        }
    }

    public void ImageFieldMerging(ImageFieldMergingArgs args)
    {
        // Do nothing
    }
}

Here is the output document: out.docx (19.4 KB)