We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

StyleCollection.addCopy(Style) not working correctly

Hi there,
We have a document where the numbering property in Heading 1 and Heading 2 style is changed to 1,2,3,…+. The node <w:numPr><w:numId w:val=“1 /></w:numPr>, is added in Heading style’s pPr (paragraph property node) in styles.xml (when we unzip it). The style is modified as {style -> modify -> Format -> Numbering -> 1,2,3}. We say this document as “Doclet1.docx”.

Given this, we are trying to add a style from
one document to another but for simplicity here presenting adding “Heading 1” from ‘same’ document.

Document doc = new Document(“Doclet1.docx”);
String styleName = “Heading 1”;

System.out.println(doc.getStyles().get(styleName).getListFormat().getList().getListId()); // 1

// add the style
// using same doc for simplicity, different copy could be used for source style
// but source and destination style should be same tweaked for Numbering property
doc.getStyles().addCopy(doc.getStyles().get(styleName));

// for (Style d: (Iterable)doc.getStyles()) {
// System.out.println(d.getName());
// }

System.out.println(doc.getStyles().get(styleName+"_0").getListFormat().getList().getListId()); // 3

When you try the above code, the style ‘Heading 1_0’ has the list id = 3 (should be 1, the source style).

Our observation is Numbering value is not getting correctly added using StyleCollection.addCopy(Style) method. Please have a look into this.

Thanks.

Hi Praneeth,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you repeat the same scenario using MS Word, you will get the same output. Please let us know if you have any more queries.