2013-11-21 152 views
0

我正在嘗試在C#中讀取.doc和.docx文件,但它不會像我們在文檔文件中看到的那樣顯示。它只是閱讀的文本,我想解決方案,我可以看到表,設計,圖片我們就可以在文檔文件中看到,請幫助在C#窗體中讀取.doc文件

Word.Application word = new Word.Application(); 
Word.Document doc = new Word.Document(); 
object fileName = @"C:\wordFile.docx"; 
// Define an object to pass to the API for missing parameters 
object missing = System.Type.Missing;     
doc = word.Documents.Open(ref fileName, 
          ref missing, ref missing, ref missing, ref missing, 
          ref missing, ref missing, ref missing, ref missing, 
          ref missing, ref missing, ref missing, ref missing, 
          ref missing, ref missing, ref missing); 
string ReadValue = string.Empty; 
// Activate the document 
doc.Activate(); 

foreach (Word.Range tmpRange in doc.StoryRanges) 
{ 
    ReadValue += tmpRange.Text; 
} 

在上述解決方案,我們可以讀取文檔文件只有文字。

回答

4

不幸的是,這並沒有微不足道的實現,因爲Word有很多功能和格式選項。

如果你有錢,你可以購買第三方控件(只需搜索「Winforms Word控件」)。

如果你有時間(和你感興趣的細節),有一箇舊的控制與在CodeProject完整的源代碼: Word control for .NET

+0

我看到上面寫着Word文檔一些應用程序一樣的原始文檔,我會做一些研究,並找到一些解決方案,可以幫助其他 –

+1

我會爲此推薦Aspose.Words – Pondidum