1

我正在使用 Microsoft.Office.Interop 打开、操作和保存 Word 文档文件 (.doc)。我可以获得所有文本内容,但在打开的 word 文档中加载添加的控件(即文本框)没有成功。

我使用以下命令获取文本

Microsoft.Office.Interop.Word.ApplicationClass oWordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

Microsoft.Office.Interop.Word.Document oWordDoc = oWordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing);
oWordDoc.Activate();
oWordApp.Selection.TypeParagraph(); 
string test = oWordDoc.Content.Text;

如何访问基本 Word 文档中包含的所有控件?

谢谢。

4

2 回答 2

1

检查这个:

    Word.Document oDoc=...;
    foreach (Word.Shape shape in oDoc.Shapes)
        {
           //do some thing with shape
        }
于 2013-07-07T05:26:12.760 回答
0

通过改变

oWordApp.Selection.TypeParagraph();

oWordApp.Selection.WholeStory();

并深入研究 oWordDoc.shapes,我获得了对所有控件的访问权限。

于 2013-07-07T06:00:22.013 回答