Issue with MSWord bullet/paragrah list

The following issue occurs, if I define a bookmark in MsWord and the bookmark starts with a numbered list, or simply a bullet list and I fill this bookmark as a list with values, an extra bullet or number is always the result. For example:
1.value1
2.value2
3.value3
4.value4
5.

It seems to occur due to the fact that in the template, a bullet or numbered (or whatever) list is defined on which the bookmark appends. However it should start at the first point and result only in the number of bullets equal to the number of elements for the list. How to solve this? The next numbered item, in the example 5., doesn’t seem to be visible for Aspose…

@mVeeDoubleUs

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Please find the resources attachedConsoleAppAspose.zip (379.0 KB)

@mVeeDoubleUs

You are facing the expected behavior of Aspose.Words. Please use ListFormat.RemoveNumbers to remove numbers or bullets from the current paragraph as shown below.

private void SetListBookmarks(KeyValuePair<string, List<string>> bookmark, ref AsposeWords.DocumentBuilder documentBuilder)
{
    documentBuilder.MoveToBookmark(bookmark.Key);

    foreach (var iterateValue in bookmark.Value)
    {
        if (iterateValue.StartsWith("<html>") && iterateValue.EndsWith("</html>"))
        {
            documentBuilder.InsertHtml(iterateValue);
        }
        else
        {
            documentBuilder.Writeln(iterateValue);
        }
    }
    documentBuilder.ListFormat.RemoveNumbers();
}

If I do RemoveNumbers, it removes all the presentation (e.g. bullets, numbers, image labels) that’s setup from the input template which is functionality I want to maintain. However, I understand this is not possible?

Otherwise I was looking for removing the last bullet (or number) however I can’t seem to remove ListLevels. Only thing I can do is iterate through the levels and build a new list, however a user can also setup an image as label, which, if I were to extract this image and attach it to the new list, results in a lot of conditions and checks.

Is there some way to fix this while maintaining the markup of the template?

@mVeeDoubleUs

We tested this scenario using the latest version of Aspose.Words for .NET 19.11 and did not face the shared issue. So, please use Aspose.Words for .NET 19.11.

This solves the problem (also with version 18.10), however an other issue arises, since it should only remove a bullet or numbered label that has no following value. However if I already place some values of a bullet list, and fill this up via Aspose with more values, it removes the first value that was already there.

Please find the input template and output attached. As you see, the input has a bullet list with Test and Test2. If I run this via Aspose, with the removenumbers, the bullet of Test is removed.Input_output.zip (38.0 KB)

@mVeeDoubleUs

We have attached the output PDF generated by the latest version of Aspose.Words with this post for your kind reference. out.pdf (43.2 KB)

We have not found the shared issue at our end. So, please use Aspose.Words for .NET 19.11.

I’ve upgraded the version however the problem still occurs. ConsoleAppAspose.zip (428.9 KB)
Please find the test project attached.

@mVeeDoubleUs

In this case, the last paragraph of table’s cell is empty. You can remove it using following modified code. We have attached the output PDF with this post for your kind reference. output_20191210.pdf (41.4 KB)

Hope this helps you.

private void SetListBookmarks(KeyValuePair<string, List<string>> bookmark, ref AsposeWords.DocumentBuilder documentBuilder)
{
    documentBuilder.MoveToBookmark(bookmark.Key);

    foreach (var iterateValue in bookmark.Value)
    {
        if (iterateValue.StartsWith("<html>") && iterateValue.EndsWith("</html>"))
        {
            documentBuilder.InsertHtml(iterateValue);
        }
        else
        {
            documentBuilder.Writeln(iterateValue);
        }
    }

    documentBuilder.ListFormat.RemoveNumbers();

    if (documentBuilder.CurrentParagraph.GetAncestor(AsposeWords.NodeType.Cell) != null
        && documentBuilder.CurrentParagraph.IsEndOfCell  
        && documentBuilder.CurrentParagraph.ToString(AsposeWords.SaveFormat.Text).Trim().Length == 0)
    {
                
        documentBuilder.CurrentParagraph.Remove();
    }
}

Great. that helps!

@mVeeDoubleUs

hanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.