如何使用Microsoft.Office.Interop.Word在某些word文档中查找和修改TextBox?

问题描述 投票:1回答:1

我必须通过TextBox id访问和更改某些word文档的某些文本框的文本。例如,假设我在word文档中有一个名为txtDate的对象,并且我想将其内容更改为现在的日期,那么我如何通过其id获取此对象?

c# visual-studio ms-word office-interop
1个回答
4
投票
void SearchTextBox(Word.Document oDoc,string name,string newContent)
    {
        foreach (Word.Shape shape in oDoc.Shapes)
            if (shape.Name == name)
            {
                shape.TextFrame.ContainingRange.Text = newContent;
                return;
            }
    }
© www.soinside.com 2019 - 2024. All rights reserved.