VSTO Office Word Add-In Development Overview

439 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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.
0
On

My 2 cents

1) For latest WordArt in word, you would need OpenXML data to insert in Word. For Excel\Powerpoint, things are easier, you can just use interop.

2) Don't always trust the documentation. If you get an int instead of a bool return value, its mostly a value from MsoTriState. e.g. Bold property should return bool as mentioned here. But, instead it returns int. So, you have to cast it like "(MsoTriState)returnedBoldValue" to figure out what that integer actually means.

3) Installation can be a pain, consider using ready-made products like Advanced Installer(I found it cheaper than others). Others might be good or better as well. 4) Table styling can be a pain. Here is a list of the weird IDs you need to use it for Powerpoint.

5) TextFrame2 is still not valid for Word(even if the documentation might say otherwise). Its only available to Excel and Powerpoint. For Word, you have to use TextFrame.

6) WPF is not supported. But, I was able to get it working just fine after some research. You need to make sure to load resource dictionaries and they work fine as well.

7) Window Association was a bit of an issue(Parent - Child). WindowInteropHelper is your friend there.

For now, I will stop here. I will post some links later.