Text formatting error

Hi,

I was tried to replace the bookmark with HTML data, but i was lost the paragraph formatting after replacement. Here is my test code to reproduce this issue and PFA for my doc template and html.

Document od = new Document(@"D:\QualItem.dot");
DocumentBuilder builderDocReplace = new DocumentBuilder(od);
Bookmark bkHTML = od.Range.Bookmarks["TestResultResult1"];
if (bkHTML != null)
{
    bkHTML.Text = "";
    builderDocReplace.MoveToBookmark("TestResultResult1");
    builderDocReplace.InsertHtml(File.ReadAllText(@"D:\text.html"));
    builderDocReplace.EndBookmark("TestResultResult1");
}
od.Save(@"D:\text.doc");

In Actual Results column, The paragraph numbers 1,2,3… are missing. only 7 and 13 are showing. Please let me know how fix this issue.

Thanks,

Hi

Thanks for your request. Actually numbers are there. The problem seems to occur because you did not specify left margin of list items. For example if you specify left margin as shown below numbers are shown correctly.

  • Use the Rater Station to create one or more sample csv data files Best regards.
  • Hi Alexey,

    Thanks for your response, If i insert the same HTML content into the document at outside of table without replacing bookmark, I was getting all the numbers properly.

    This problem was happening when I inserting this html string in a table cell.

    Are they any limitations inserting this HTML string outside the table and inside table cell?

    Thanks,

    Hi Srinu,

    Thanks for your inquiry. No, there are no limitations. You should just note if negative left margin is specified for paragraph inside table cell, paragraph text can be hidden behind the table borders.
    Best regards.

    Hi Alexey,

    Thanks for your response. What I understood from your last reply is, the table cell where I replaced the bookmark with HTML string having negative left margin.

    If so, how can I identify the negative left margin in table cell and reset/remove negative value, before replacing bookmark with html data to overcome hiding paragraph text behind table borders.

    Thanks,

    Hi

    Thank you for additional information. Actually, the paragraphs which are inserted have negative left indents. As a workaround, you can try using code like the following (see the highlighted code)

    string html = File.ReadAllText(@"Test001\text.html");
    Document doc = new Document(@"Test001\template.dot");
    DocumentBuilder builder = new DocumentBuilder(doc);
    // Insert HTML if bookmark exists.
    Bookmark bk = doc.Range.Bookmarks["TestResultResult1"];
    if (bk != null)
    {
        bk.Text = "";
        builder.MoveToBookmark("TestResultResult1");
        builder.InsertHtml(html);
    }
    NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
    foreach(Paragraph paragraph in paragraphs)
    {
        if (paragraph.IsListItem)
            paragraph.ParagraphFormat.LeftIndent = paragraph.ListFormat.ListLevel.NumberPosition;
    }
    doc.Save(@"Test001\out.doc");
    

    Hope this helps.
    Best regards.