J
Jens Gyldenkærne Clausen
Hi group. I am working with ContentControls in Word 2007 and have now
(once again) stumbled upon something peculiar.
The basic Microsoft.Office.Tools.Word.ContentControl class - the type
that can represent all eight types of content controls - has lots of
members, some of them specific to certain types (such as
DateCalendarType and ShowingPlaceholderText). But one very important
property is missing - a simple .Text property to expose the textual
content in a PlainTextContentControl, RichTextContentControl,
DatepickerContentControl etc. Why is that??
I'm programming a solution where I need to access all content controls
in a Word template - and for every textual content control be able to
read and set the content. This seems to be frustratingly difficult. I'm
now trying to write a wrapper class implementing the missing .Text
property - but in doing that, I discovered that 1) the ContentControl
class is sealed, making it impossible to expand; 2) the
ContentControlBase class has a note stating that one shouldn't derive
own types from it.
What would be "best practice" in this case? I'm thinking of
A) Ignore the note and derive from ContentControlBase since I need a
handle to the Text property
B) Drop the wrapper class and handle the Text set/get with type probing
and duplicated internal code
C) Try to implement some kind of cast functionality, using the
PlainTextContentControl as the lowest denominator (in my programmatic
manipulations I have no need for methods/properties other than the ones
supported by a PlainTextContentControl.
Reference link:
http://msdn.microsoft.com/library/microsoft.office.tools.word.contentcontrol(en-us).aspx
(once again) stumbled upon something peculiar.
The basic Microsoft.Office.Tools.Word.ContentControl class - the type
that can represent all eight types of content controls - has lots of
members, some of them specific to certain types (such as
DateCalendarType and ShowingPlaceholderText). But one very important
property is missing - a simple .Text property to expose the textual
content in a PlainTextContentControl, RichTextContentControl,
DatepickerContentControl etc. Why is that??
I'm programming a solution where I need to access all content controls
in a Word template - and for every textual content control be able to
read and set the content. This seems to be frustratingly difficult. I'm
now trying to write a wrapper class implementing the missing .Text
property - but in doing that, I discovered that 1) the ContentControl
class is sealed, making it impossible to expand; 2) the
ContentControlBase class has a note stating that one shouldn't derive
own types from it.
What would be "best practice" in this case? I'm thinking of
A) Ignore the note and derive from ContentControlBase since I need a
handle to the Text property
B) Drop the wrapper class and handle the Text set/get with type probing
and duplicated internal code
C) Try to implement some kind of cast functionality, using the
PlainTextContentControl as the lowest denominator (in my programmatic
manipulations I have no need for methods/properties other than the ones
supported by a PlainTextContentControl.
Reference link:
http://msdn.microsoft.com/library/microsoft.office.tools.word.contentcontrol(en-us).aspx