【问题标题】:How to load all controls added to a word document (Microsoft Office Interop Word)?如何加载添加到 Word 文档(Microsoft Office Interop Word)的所有控件?
【发布时间】:2013-07-04 18:34:38
【问题描述】:

我正在使用 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 文档中包含的所有控件?

谢谢。

【问题讨论】:

    标签: c# ms-word office-interop backend


    【解决方案1】:

    检查一下:

        Word.Document oDoc=...;
        foreach (Word.Shape shape in oDoc.Shapes)
            {
               //do some thing with shape
            }
    

    【讨论】:

    • 感谢@Ramin,但 oWordDoc.Shapes.Count() 等于零!
    • 我知道了,使用 oWordApp.Selection.WholeStory() 而不是 oWordApp.Selection.TypeParagraph() 并使用您的解决方法就可以了。
    【解决方案2】:

    通过改变

    oWordApp.Selection.TypeParagraph();

    oWordApp.Selection.WholeStory();

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-27
      • 2011-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多