Manipulating the Format (Font -Color etc) inside the Shape


#1

Hello.
I would like to ask you for some suggestion ,how to modify the formatting of a shape. I was stopped on a place where i didn’t expect.Please help.
I’m intending to do the following:
I have a Text Box object inside a word documet and i want to change only the Font Size ohf the current text inside that Text Box.
I have retrieved this text box object by using (casting ) that node to object of Shape class like this:

Document word_doc = new Document(@“C:\MyDocument.doc”);
NodeCollection coll = word_doc.GetChildNodes(NodeType.Shape, true);
Shape shape = (Shape)coll[0]; // Its only one shape object in the document.

I can retrieve the text in that text box thru this shape object ,but i can’t set the size of the text.
I found that InlineShape has a property named Font but any idea , how is it possible to use InlineShape insteed of Shape class? or some other suggestion.

Please help, this is very urgent.

Thank You in advance.

#2

The primary container of text in the document is always Run node.

To change formatting of the text inside particular document node you need to iterate through its child nodes of the type Run and change the specific properties.

For example, in your case:

Document doc = new Document(filename);

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

Shape shape = (Shape)shapes[0];

foreach(Run run in shape.GetChildNodes(NodeType.Run, true))

{

run.Font.Size = 16;

}