Search code examples
c#vstoword-automation

VSTO Office Word Add-In Development Overview


C# expert and ASP.NET developer at heart, I find myself assigned now to an Office Add-In project. Luckily I have worked on several Excel Add-Ins in the past, but it's all blurry in my mind and I never had a chance to learn it in a well structured manner.

I was surprised to notice that SO and the whole Internet is lacking proper documentation for VSTO, Word DOM, OpenXML, etc. Lacking might be an exaggeration, but it's not abundant or well organized, that's for sure.

So what I'm looking for basically it's an overview, jump-start, or cheat-sheet, however you want to call it, containing a high level summary of the important parts of Office development.

PS: I will post my findings as well during my study.


Solution

  • Document Level Architecture

    • Document
    • Template (essentially the same as Document from VSTO's perspective)

    "Contained" by the Document.
    Document contains the relevant information required to load the Add-In. Does not use Registry.


    Application Level Architecture

    • Add-in

    Directly plugged into and loaded by Office. Agnostic to Document. It is registered via Registry keys.


    Ribbon

    Supported by Visual Designer. It handles state automatically for you.


    Ribbon X


    It allows a much better customization. It's XAML like. No Visual Designer. It doesn't handle state. You need to handle state on your own, using callbacks.


    Word DOM - Document Object Model

       Application
          Documents
             StoryRanges
                Range
             Styles
                Style
          Windows
             Window
                Panes
                   Pane
    

    It is nothing special, just another DOM, quite similar to the HTML one. However, it will take some time to get used with it and the information on the Internet is not as abundant as one might hope.


    Manipulating the DOM

    • Directly
    • VSTO Controls: Windows Forms Controls, Host Controls

    Windows Forms Controls

    • Powerful (supports .NET databinding for example) however they are not really part of Office so they will feel like a nut in a wall.

    Host Controls (wrappers around the Interop Word objects)

    • Bookmark Control - old method, move on, nothing to see here.
    • XML Node & XML Nodes - deprecated. Removed in USA due to lawsuit.
    • Content Controls - The future! Support real data binding to hidden XML data field in the XML parts of the document.

    Deployment

    • Click-Once - simple and fast. It adds the Registry entries for you. But it doesn't allow much customization. For example you can have a Click-Once project installed only to the current user.
    • Windows Installer, Installshield, etc. You need to add the .manifest and the .vsto files to the output. You need to add the registry keys.