That Wacky Office API

Friday, May 27, 2005

Like Ben @ CodeBetter, I admire the power behind the Office API. We finally have some customers buying into the promise of smart clients, and it is amazing to see the amount of functionality available through the object model of Word, Excel, and the rest of the family.

But, after reviewing the code, I still think it sucks. The rough edges of interop poke out in every corner, and the constant appearance of Sytem.Object in parameter lists and return values ruins the discoverability.

object currentDateBookmark = "CurrentDate";

Word.Range range =

    thisDocument.Bookmarks.get_Item(ref currentDateBookmark).Range;

"Quit whining", I hear you say. "There is a leaning curve involved". Yes, there is a leaning curve, but even once you have the vocabulary down there is unattractive code involved.

CategoryList = commandBar.Controls.Add(

        Office.MsoControlType.msoControlComboBox,

        missing,

        missing,

        missing,

        (object)true

    ) as Office.CommandBarComboBox;

Ok, this is unattractive C# code. Make no doubt about it, Office automation currently looks best in VB.NET.


Comments
PitDog Friday, May 27, 2005
I hear you man. What a joke. Even if you glance over the ugly code you will see there are many other issues with the interop stuff. I did some digging with the heap profiler and found lots of objects hanging around dispite my best effort to clean up the mess.
<br>
<br>MS is not there yet. But in time.. =-)
<br>
<br>My coworker said it up best.
<br>&quot;What a pile.&quot;
Scott Saturday, May 28, 2005
I have not looked at the VSTO 2005 bits yet, but I don't think there is a vast improvement from the articles I've read. Perhaps the next version of Office...
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!