Hi there,
I’ve discovered another minor inconsistency with HTML imports. When importing nested lists from HTML, the style appears to differ from a regular Word list. From my limited inspection of the generated document, it seems that the nested item uses a different list style from the non-nested items, producing additional space between items and inconsistent formatting. Here is a list of the issues I’ve observed:
- With “Auto” space after paragraphs, I would expect that list items would have no space following them, but due to the different formats, Word appears to add additional space between items.
- It also seems that the indentation level of nested items imported from HTML is slightly different from that of the default list style.
I’ve attached a reproduction below which demonstrates both of these inconsistencies.
using GemBox.Document;
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
var doc = new DocumentModel();
var section = new Section(doc);
doc.Sections.Add(section);
var blocks = section.Blocks;
doc.DefaultParagraphFormat.SpaceAfterAuto = true;
ListStyle bulletList = new ListStyle(ListTemplateType.Bullet);
blocks.Add(new Paragraph(doc, "First item.")
{
ListFormat = { Style = bulletList }
});
blocks.Add(new Paragraph(doc, "Second item.")
{
ListFormat = { Style = bulletList, ListLevelNumber = 1 }
});
blocks.Add(new Paragraph(doc, "Third item.")
{
ListFormat = { Style = bulletList }
});
blocks.Add(new Paragraph(doc));
var loadOptions = new HtmlLoadOptions
{
InheritCharacterFormat = true,
InheritParagraphFormat = true,
};
section.Content.End.LoadText("""
<ul>
<li>First item.
<ul>
<li>Sub item.</li>
</ul>
</li>
<li>Third item.</li>
</ul>
""", loadOptions);
doc.Save("test.docx");
My desired result is that the output from the programmatic list construction is as similar as possible to that of the HTML import. I am upgrading a legacy system which used a different library for Word document rendering, and I am aiming to achieve as much compatibility with the legacy implementation as possible. These inconsistencies with HTML imports are one of the few remaining issues left to solve, so I am greatly appreciative of any assistance.
Best,
Michael