addCopy() with linked style

Hi there,
When adding the linked style, lets name it to “Heading 1”. Heading 1 has - paragraph level ‘Heading 1’ and character level ‘Heading 1 Char’.

So, while adding this to docA which already has ‘Heading 1’ in it, addCopy would create a copy of it rather than overriding.

We were using a work-around as second copy is added because of character level style - “Heading 1 Char” read again from the document. So, we skipped the applying when it ends with character level.

But now since we are not applying “Heading 1 Char”, the docA’s Heading 1 Char would be retained.

So, after applying the docA would have - ‘Heading 1’ the newly one, and the ‘Heading 1 Char’ the older one.

Since some text is using Heading 1 Char in docA, it is still based upon older ‘Heading 1 Char’ and not the newer one which is with linked - ‘Heading 1’.

So, in this case expected behavior is while applying Heading 1, the Heading 1 Char should also be overridden from docA, and not only Heading 1.

For reproduction you can try adding Heading 1 (tweaked) from some document to the any ‘docA’.

Please suggest us the way to override the ‘Heading 1 Char’ (retained character style, previously part of linked style).
Thanks.

Hi Praneeth,

Thanks for your inquiry. I have tested the scenario using following code example with attached documents. The ‘Heading 1 Char’ is copied to final output document. Please check the styles.xml of attached documents.

Document doc = new Document(MyDir + "DocumentA.docx");
Document docA = new Document(MyDir + "DocumentB.docx");
for (Style srcStyle : (Iterable<Style>)doc.getStyles())
{
    if (srcStyle.getName().contains("Heading"))
    {
        Style newStyle = docA.getStyles().addCopy(srcStyle);
        newStyle.setName(srcStyle.getName());
        System.out.println(srcStyle.getName());
    }
}
docA.save(MyDir + "Out.docx");

*PraneethS:

So, in this case expected behavior is while applying Heading 1, the Heading 1 Char should also be overridden from docA, and not only Heading 1.

Please suggest us the way to override the ‘Heading 1 Char’ (retained character style, previously part of linked style).*

Could you please share the input/output documents to demonstrate the exact issue which you are facing? Please also share some more detail about the expected behaviour of style ‘Heading 1 Char’. We will then provide you more information about your query.