共用方式為


Using Power Tools for Video Studio to Modify Open XML Documents

This blog is inactive.
New blog: EricWhite.com/blog

Blog TOC(Update June 22, 2010 - This tool has been released for Visual Studio 2010.)

There is a cool add-in for Visual Studio that I use.  It is the Open XML Package Editor, which is a graphical treeview based editor for examining and editing Open XML Package files.  Once you install the add-in, you can drag an Open XML document into Visual Studio, and browse through the parts, and open specific parts for editing in Visual Studio's great XML editor.  Visual Studio doesn't keep the file open, so you can use it in the following scenarios:

  • You can using Word 2007 to create a file, save the file, and close Word.  You can then drag the document onto Visual Studio, and look at the markup that was created.  You can then open the doc again in Word, change it, close it, and then Visual Studio will tell you that the file has changed outside the editor.  You can tell VS to reload the doc, and see the changed markup.  Because the Open XML Package Editor doesn't keep the file open, you don't need to close the file in VS before opening it again in Word.
  • You can write a program to manipulate the document in C# or VB.  If you have the Open XML document open in VS, you can run the program, and VS will tell you that the file has changed, and you can reload to see the results of your modifications.
  • You can manually modify the XML, and open the file in Word to see if your manual modifications worked and did what you wanted.  You can then close the doc, tweak the XML, and open it in Word again.

This is a very convenient way to examine and edit the XML in Open XML docs!

Of course, Word does not indent the XML when deserializing.  You can use the XML formatting option in the XML editor to make it easy to view and edit the XML.  I like to set an option in VS so that when you format the XML, it lines up the attributes.  This is a far easier way to see the XML when there are lots of attributes, or lots of namespaces.  To set this option, select Tools, Options on the menu, expand Text Editor, expand XML, click on Formatting, and set the option, "Align attributes each on a separate line".

To format an XML document, select Edit, Advanced, Format Document on the menu (or type ^e, d).

You can download the Microsoft Visual Studio Tools for the Office System Power Tools here.

Comments

  • Anonymous
    April 30, 2008
    PingBack from http://microsoftnews.askpcdoc.com/openxml/my-favorite-way-to-write-programs-that-manipulate-open-xml-documents

  • Anonymous
    May 05, 2008
    Library of Congress's standards activity. The Library of Congress has posted an overview of the work

  • Anonymous
    June 13, 2008
    The comment has been removed

  • Anonymous
    July 08, 2008
    Il existe beaucoup d’outils indépendants (PackageExplorer, Word Content Control, PowerTools, etc) mais

  • Anonymous
    October 19, 2008
    Data-bound content controls are a powerful and convenient way to separate the semantic business data