Using styles

Hi,
I have a rather strange problem happening that I can’t figure out. I have a set of Microsoft Word document templates that I use with Aspose.Words in my web application to create documents. What happens is that one the styles defined in one of the templates is changed in the document that is created from it.
For example, in my template document, I have the style “HEADING 1” defined as Times New Roman, 12pt, left justified and bold. If I use Microsoft Word to create a document using this template, the style “HEADING 1” in the document is also defined as Times New Roman, 12pt, left justified and bold. However, if I produce a document through my web application using Aspose.Words and the exact same template, the style “HEADING 1” in the document ends up being defined as Arial, 16pt!!
I can’t figure out why this is happening and it’s driving me crazy. Any help you can give would be greatly appreciated.
Thanks so much!

Hello!
Thank you for your inquiry.
That’s very strange. But I cannot even guess why this happens. Please attach the template and show the code snippet that you are using to create and manipulate with your document. I’ll try on my side.
Regards,

Thanks Viktor. I’ve attached the code for the entire page that produces the documents so you can see exactly what its doing.
I will attach the template file in another reply.
Thanks very much!

Hi again Viktor,
Here is the template file.
Thanks!

Hi!
Thank you for your materials.
I have tried running minimal sample – just loaded the template and immediately saved the document. All works fine. Heading 1 style is the same. Your code is quite complex. I cannot debug it since it’s a detached class. What I can recommend is checking this style between operations performed with the Document object. You can do this by querying properties of this object:

Style h1 = doc.Styles["Heading 1"];

When you discover the change to Arial 16 you will see the operation that causes such a strange behavior. At least this helps to narrow down the problem. Let me know whether this helps.
Regards,

Hi Viktor,
Thanks for the debugging suggestion. I tried it and it definitely showed where the problem was. What was happening is that in my code, I was creating an Aspose.Words document object based on my template (let’s call it Document A) and appending it to another “master” document (another Aspose.Words document object). This allows us to insert documents into each other so we can combine documents as needed.
The problem was I forgot to specify a template to create the “master” document from, so it looks like it used the default Microsoft Word normal.dot template, which specifies Arial 16 for the Heading 1 style. The template that the Document A was produced from has style Heading 1 defined as Times New Roman 12, but the style is not acutally used within the template (the style is only defined for use in future editting of any document produced from the template).
Since the Heading 1 style is defined, but not in use in the template, it is also defined, but not in use in Document A. Thus, when Document A is appended to the “master” document, the Heading 1 style definition gets overwritten with the “master” document’s Heading 1 style definition (i.e. Arial 16). I did some further experimenting and found that if the Heading 1 style is defined and also in use in Document A, when Document A is appended to the “master” document, Document A’s Heading 1 style gets renamed to Heading 1_1 and the “master” document’s Heading 1 style remains unchanged.
What I did to correct this is create another normal.dot template and put it in the application folder with all the other templates my application uses. I modified this normal.dot to be the way I want it and I modified the application so that it creates the “master” document now based on this new normal.dot template.
Everything is working fine now, so thanks again very much for all your help.
Chris.

Hello!
That’s great if you found a solution. Please let us know if you have any other questions.
Have a nice day,