我正在开发一个应用程序,我需要将.docx和.pdf文件转换为基本格式的.txt文件。我在互联网上搜索它但找不到任何免费的第三方dll。任何人都可以建议我最好的方式和一些dll参考。
提前致谢
http://support.microsoft.com/kb/316383描述了你想要用.docx文件做什么。 http://visualbasic.about.com/od/quicktips/qt/disppdf.htm描述相同,但使用.pdf文件。
一旦将文件读入代码,就可以使用VB.NET的内置文件写入功能输出到txt文件。
下面的代码将为您处理工作。这是我为大老板写的东西哈哈。我希望它有所帮助。代码将工作表中的第一个单元格作为docx文件所在的文件夹读取,然后将它们逐个转换为保存在同一文件夹中的txt文件。
Const wdFormatText = 2
If Not Len(Cells(1, "A").Value) > 0 Or Dir(Cells(1, "A").Value, vbDirectory) = "" Then
MsgBox ("Invalid Folder")
Exit Sub
End If
Dim StrFile As String
StrFile = Dir(Cells(1, "A").Value & "\*.docx")
Do While Len(StrFile) > 0
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(Cells(1, "A").Value & "\" & StrFile, False, True)
objDoc.SaveAs Cells(1, "A").Value & "\" & StrFile & ".txt", wdFormatText
objWord.Quit
StrFile = Dir
Loop