none
How to UpdateStyles using OpenXML RRS feed

  • Question

  • Hi

    In Word automation you can use the command ActiveDocument.UpdateStyles to make the document visually apply format specifications from the attached template.

    Is there any known way of doing this using Open XML SDK?

    Thanks in advance


    Best Regards Peter Karlström Midrange AB, Sweden

    Wednesday, January 29, 2014 11:28 AM

Answers

  • Hi Peter

    Well, it's as close as you can get, I'm afraid. Anything that is a method (performs an action) in VBA is not going to have an equivalent in the Open XML SDK. Best I can suggest would be an add-in that runs parallel, checks for this property and deactivates it. But then you could just as well execute the method...

    The "correct" approach would be to copy in the style definitions from the template. If the document has those in it already then they will be applied.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, February 12, 2014 7:25 PM
    Moderator

All replies

  • No, the feature you mention is part of the Word.Application, only, to make life easier for the user.

    I'm not sure what kind of scenario you're envisioning that would come into play using the Open XML SDK but certainly there's nothing that will "look at this" and "apply that formatting to a style". It would have to be coded by you from scratch.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, January 29, 2014 3:15 PM
    Moderator
  • Hi Cindy

    Ths scenario is a Webservice where Word templates are merged with a prefefined text-document.
    I've seen to that the produced document contains all style formats from the template but they are not visually applied to the document body, headers or footers. This doesn't happen untilf you open the document in Word and "Update styles". We want the document to be displayed correcty without any intervention of the Word application.
    If we, for example, decide to render this document to a PDF file, it will not look alright.

    I'm simply trying to see if somebody else has come across this and found a solution.

    Anybody else got some input?


    Best Regards Peter Karlström Midrange AB, Sweden


    Wednesday, January 29, 2014 3:25 PM
  • Thank you for the description, now I understand what you're asking.

    See
    http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.linkstyles(v=office.14).aspx

    How I discovered this:
    I saved a document with this option activated. Then I looked at the content of settings.xml in the Zip package.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, January 29, 2014 4:09 PM
    Moderator
  • Hi Cindy

    Thanks for your support and efforts regarding this issue.

    Unfortunately, the LinkStyles property and setting is not exactly then same as the VBA-function ActiveDocument.UpdateStyles.

    ActiveDocument.UpdateStyles is a onetime event on the contents of the actual document, whilst the LinkStyle property is a "permanent" setting in the document.
    This may have an unwanted effect on our documents, but we will test this and see if this will solve our problem.

    I will get back within a week with a result.

    Thanks again


    Best Regards Peter Karlström Midrange AB, Sweden

    Tuesday, February 11, 2014 9:04 AM
  • Hi Peter

    Well, it's as close as you can get, I'm afraid. Anything that is a method (performs an action) in VBA is not going to have an equivalent in the Open XML SDK. Best I can suggest would be an add-in that runs parallel, checks for this property and deactivates it. But then you could just as well execute the method...

    The "correct" approach would be to copy in the style definitions from the template. If the document has those in it already then they will be applied.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, February 12, 2014 7:25 PM
    Moderator
  • Hi Cindy

    My customer has tested the new solution, and will accept it, even though this setting is unvanted.
    We are able to turn the setting off on clients where our VSTO-addin is installed, and the customer will handle "out of office"-scenarios (with no VSTO-addin) manually.

    Thanks for your support.


    Best Regards Peter Karlström Midrange AB, Sweden

    Thursday, February 13, 2014 8:35 AM