How to read text from a text box in a Word document via C #

2

I'm using Interop to manipulate a word, through a console application.

using Word = Microsoft.Office.Interop.Word; 

I can extract the byte array, save as Pdf, as image etc, but a relatively simple thing that I'm needing I still can not do.

I need to give a replace in a certain text of the document, which is inside a text box, but I do not know how to do it.

From the variable _documentoWord I can access the elements, but in my attempts it still did not work.

_aplicativoWord = new Word.Application() {Visible = false};
_documentoWord = _aplicativoWord.Documents.Open(caminho);
    
asked by anonymous 17.07.2015 / 18:42

1 answer

2

I've found a way that will suit me:

    public static void SearchTextBox(string name, string newContent)
    {
        _documentoWord.Content.ShapeRange.Ungroup();

        foreach (Word.Shape i in _documentoWord.Content.ShapeRange)
        {
            if (i.AlternativeText.IndexOf(name) != -1)
            {
                i.TextFrame.TextRange.Text = "";
            }
        }
    }

First I unraveled everything that could be clustered. Then I swept the shapes of the document. If the alternative text is the same as the text I'm looking for I enter the TextFrame.TextRange.Text and modify the text by deleting it.

    
17.07.2015 / 20:55