2013-07-07 80 views
1

我正在使用Microsoft.Office.Interop打開,處理和保存Word文檔文件(.doc)。 我可以獲取所有文本內容,但在打開的Word文檔中加載添加的控件(即TextBoxes)時無法成功。如何加載添加到Word文檔的所有控件(Microsoft Office Interop 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文檔中?

謝謝。

回答

0

通過改變

oWordApp.Selection.TypeParagraph();

oWordApp.Selection.WholeStory();

在oWordDoc.shapes中挖掘,我獲得了對所有控件的訪問權限。

1

檢查此:

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

感謝@Ramin,但oWordDoc.Shapes.Count()等於零! –

+1

我明白了,使用oWordApp.Selection.WholeStory()而不是oWordApp.Selection.TypeParagraph()並使用您的解決方法取得了訣竅。 –

相關問題