Free Support Forum - aspose.com

Attempting to alter an existing style

I am trying to update the "Normal" style in a new document. However an exception is thrown "Cannot add a style because a style with the same name already exists". What am I doing wrong?

Document doc = new Document();
doc.removeAllChildren();

StyleCollection styles = doc.getStyles();
Style style = styles.get("Normal");
if(style == null)
style = styles.add(StyleType.PARAGRAPH,"Normal");
style.getFont().setSize(10);
style.getFont().setName("Helvetica");
style.getParagraphFormat().setSpaceAfter(10);

Thanks!

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. I cannot reproduce the problem on my side using the latest version of Aspose.Words for Java (4.0.0). Which version do you use?

You can download the latest version of Aspose.Words for Java from here:

http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/category1378.aspx

Best regards,

Thanks, Mysteriously after turning on my computer this morning the problem has gone away! Oh well it works now.