none
Copy the style from dotx into docx.

    Question

  • The questions is what 'xml' manipulations (programatically) needs to be done in the server side in order to copy all the template style definitions into an existing word document (docx):

    I understand that you can not apply the template definitions to an existing document. You can create a new document with the template definitions but you can not apply the template definitions to an existing document. I am particularly interested in copying the style definitions from the template into an existing document.

    1. Whats is the implications of copying the style.xml contents from template (dotx) into document (docx):

    - When I copied the style.xml contents from template to docx, I can see the style gallery of the document similar to that in template. Also the document opens properly. But the components will carry some attributes (like revision Ids) from the template into the document during the copy.. Will this have any impact on how the document behave?

    Thanks.

    Monday, March 11, 2013 10:20 AM

Answers

  • << When I choose a different theme in the template and try and copy theme (from theme.xml) and style (from style.xml) into the document programatically, I can not open the document in WORD. WORD says that there is unreadable data and ask to recover.   >>

    I think you need to compare the XML of the styles.xml files. As far as I know, the styles.xml mainly references information contained in the theme XML file for the defaults and the general font information if the major or minor font from the theme has been used. For example:

    <w:docDefaults>
      <w:rPrDefault>
       <w:rPr><w:rFonts w:cstheme="minorBidi" w:hAnsiTheme="minorHAnsi" w:eastAsiaTheme="minorHAnsi" w:asciiTheme="minorHAnsi"/><w:sz w:val="22"/><w:szCs w:val="22"/><w:lang w:val="en-US" w:bidi="ar-SA" w:eastAsia="en-US"/></w:rPr></w:rPrDefault>
      <w:pPrDefault>
      <w:pPr><w:spacing w:lineRule="auto" w:line="259" w:after="160"/></w:pPr></w:pPrDefault></w:docDefaults>
    But, as you can see, there is no direct reference to the theme. So the only thing I can imagine is that the non-default theme XML file doesn't include all the necessary information, such as, for example, minorBidi that the styles.xml is trying to look up.

    Cindy Meister, VSTO/Word MVP, my blog

    Friday, March 15, 2013 5:44 PM
    Moderator

All replies

  • Also please note that I am trying this manipulations in Java on the server side.


    Monday, March 11, 2013 10:23 AM
  • Its a related question that I posted in the below link:

    http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/199ff247-529e-4fe3-a8aa-bf292aa11010


    - I had copied all the styles in style.xml from the template to an existing document(docx) programatic on the server side and could see the document style gallery similar to the template when I open the document in WORD. This works well for default theme. When I choose a different theme in the template and try and copy theme (from theme.xml) and style (from style.xml) into the document programatically, I can not open the document in WORD. WORD says that there is unreadable data and ask to recover.    

    How to copy the style from the template to an existing document when a different theme to default is selected programatic on the server side? I am trying this in Java and I would like to know what xml manipulations involved so that I can try them out in Java


    Thanks.




    Monday, March 11, 2013 10:33 AM
  • Hi Gpbk,

    Thank you for posting in the MSDN Forum.

    I'll consult your issue with my colleague. You'll be informed if there's any update.

    Thank you for your patience and understanding.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 12, 2013 4:51 AM
    Moderator
  • Hi Quist Zhang,

    Thanks for the response. Understanding these two aspects of how WORD works (1. Implications of the style definitions copy for a scenario that is working and 2. how to copy the style definitions when the theme is altered which has the impact on the style definitions of the docx ) are very important for one of our project since we are trying to do the same on the server side using Java.  Your teams help in this regard is very much Appreciated.

    For one of the aspect mentioned here (for implication of the style copy I have posted another entry:

    http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/8bbd4fbd-8674-4eba-953f-af65ca9358e4

    )

    Thanks.

    Thursday, March 14, 2013 11:34 AM
  • << When I choose a different theme in the template and try and copy theme (from theme.xml) and style (from style.xml) into the document programatically, I can not open the document in WORD. WORD says that there is unreadable data and ask to recover.   >>

    I think you need to compare the XML of the styles.xml files. As far as I know, the styles.xml mainly references information contained in the theme XML file for the defaults and the general font information if the major or minor font from the theme has been used. For example:

    <w:docDefaults>
      <w:rPrDefault>
       <w:rPr><w:rFonts w:cstheme="minorBidi" w:hAnsiTheme="minorHAnsi" w:eastAsiaTheme="minorHAnsi" w:asciiTheme="minorHAnsi"/><w:sz w:val="22"/><w:szCs w:val="22"/><w:lang w:val="en-US" w:bidi="ar-SA" w:eastAsia="en-US"/></w:rPr></w:rPrDefault>
      <w:pPrDefault>
      <w:pPr><w:spacing w:lineRule="auto" w:line="259" w:after="160"/></w:pPr></w:pPrDefault></w:docDefaults>
    But, as you can see, there is no direct reference to the theme. So the only thing I can imagine is that the non-default theme XML file doesn't include all the necessary information, such as, for example, minorBidi that the styles.xml is trying to look up.

    Cindy Meister, VSTO/Word MVP, my blog

    Friday, March 15, 2013 5:44 PM
    Moderator
  • Hi Guru K,

    I temporarily marked the reply as answer. You can unmark it if it provides no help.

    Please feel free to let us know if you need any help.

    Have a nice day.


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 28, 2013 2:39 AM
    Moderator