Reputation:
I've been looking and googling around for 4h to find a solution for my problem.
I'm trying to set the text of an defined rich text content control. For test purposes i defined just one content control (rich text) in the document where i would like to change the text.
var docx = Application.Documents.Open(@"D:\BaseDocs\Test.docx");
var all = GetAllContentControls(docx); // Returns all content controls in active document
var one = all.First(); // Select first one --> works
((RichTextContentControl)one).Text = "Test" //Trying to set text --> invalid cast exception
I can't set the value of this predefined content control. Any help is really appreciated.
Upvotes: 0
Views: 2638
Reputation: 3382
The real solution of the problem would be to use one.Range.Text = "Test"
. You can only set the text of a range and not of a ContentControl.
Upvotes: 3
Reputation:
Solved. I took bookmarks to solve this problem. Thank you all for helping me out.
Upvotes: 0