List indentation lost when copying lists

Hi,
Aspose Words (tested v14.5.0 , v14.6.0) loses the list indentation when lists are copied. (see out-copy.png)
We need to copy lists because we don’t want to merge lists while appending documents with UseDestinationStyles (see Controlling How Lists are Handled).

Document doc = new Document("test.rtf");
doc.save("out.rtf");
List copy = doc.getLists().add(doc.getLists().get(0).getStyle());
for (Object p : doc.getChildNodes(NodeType.PARAGRAPH, true))
    ((Paragraph)p).getListFormat().setList(copy);
doc.save("out-copy.rtf");

Thanks
Romain

Hi Romain,

Thanks for your inquiry. Could you please share some detail about your requirement what exact you want to achieve by using Aspose.Words? Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

You are setting the list of same paragraph again. In your case, you also need to set the list level of paragraphs. Please check the following code snippet. Hope this helps you.

Document doc = new Document(MyDir + "test.rtf");
doc.save(MyDir + "out.rtf");
List copy = doc.getLists().add(doc.getLists().get(0).getStyle());
for (Object p : doc.getChildNodes(NodeType.PARAGRAPH, true))
{
    ((Paragraph)p).getListFormat().setList(copy);
    ((Paragraph)p).getListFormat().setListLevelNumber(((Paragraph)p).getListFormat().getListLevelNumber());
}
doc.save(MyDir + "out-copy.rtf");

Hi
As stated before we want to append a document using destination styles and preventing any list numberings from continuing on.
To achieve this we use the code provided in your documentation (Controlling How Lists are Handled).
This code sets the list of same paragraph again:

currentList = srcDoc.getLists().addCopy(para.getListFormat().getList());
...
// Set the list of this paragraph to the copied list.
para.getListFormat().setList(currentList);

Setting the list level number again helps.
However this behavior is not intuitive.

  1. Just copying a list, and applying it to a paragraph removes the indentation.
  2. Applying a the same property(listLevelNumber) again changes something.

This should at least be documented.
Thanks
Romain

Hi Romain,

Thanks for your inquiry.
The article about ‘Controlling How Lists are Handled’ explains how to handle lists when one document is appended to another using KEEP_SOURCE_FORMATTING or USE_DESTINATION_STYLES.

*flammang:

As stated before we want to append a document using destination styles and preventing any list numberings from continuing on.
To achieve this we use the code provided in your documentation (Controlling How Lists are Handled).
This code sets the list of same paragraph again:

currentList = srcDoc.getLists().addCopy(para.getListFormat().getList());

// Set the list of this paragraph to the copied list.
para.getListFormat().setList(currentList);
Setting the list level number again helps.*

It would be great if you please share following detail for investigation purposes.

  • Please attach your input Word documents.
  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

Unfortunately,
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

*flammang:

However this behavior is not intuitive.

  1. Just copying a list, and applying it to a paragraph removes the indentation.
  2. Applying a the same property(listLevelNumber) again changes something.
    This should at least be documented.*

Could you please attach your input, output and expected output Word documents here for this for testing? I will investigate these issues on my side and provide you more information.