vb.net怎么实现读取指定WORD文档中的内容

如题所述

添加spire.doc.dll为引用,在vb.net中读取指定word文档的内容到 txt文件,代码示例如下:

    '加载Word文档

    Dim doc As Document = New Documentdocument.LoadFromFile("测试文档.docx")

    '使用GetText方法获取文档中的所有文本

    Dim s As String = doc.GetText

    File.WriteAllText("文本1.txt", s.ToString)

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-12-27
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then

Dim docApp As Word.Application
Dim docDocument As Word.Document
Try
docApp = New Word.Application
docDocument = docApp.Documents.Open(OpenFileDialog1.FileName, , , , , , , , , , , , , , , )
Dim strTemp As String
For i = 1 To docDocument.Paragraphs.Count
'''''这里是一段一段的读出,你也可以选择别的方式

strTemp = docDocument.Paragraphs(i).Range.Text.Trim
Debug.Print(strTemp)
Next
Catch ex As Exception
Throw ex
End Try
End If

工程里面引用Microsoft Word 14.0 Object Library
另外,网上vb.net的资料真心少,查资料的时候可以查c#的,改改语法就是了,都是.net家族的,通用
第2个回答  2016-11-25
怎么理解你这里说的“指定”?
相似回答