beyondcompare 的word 直接转txt 脚本

自带的word转换不稳定,直接调用word转出来的格式好看,缺点当然是依赖word。

 

命令行:wscript Helpers\doc2txt.vbs %s %t

脚本内容:(转换UTF-8的文本格式)

' ==> doc2txt.cmd <==
' cscript //Nologo "%~dpn0.vbs" "%~1"
' if errorlevel 1 pause

Option Explicit
On Error Resume Next
 
Dim objWordApp
Dim objWordDoc

Dim objFileSys
Dim objFile

Dim strWordFilePath
Dim strTextFilePath
 
Set objFileSys = CreateObject("Scripting.FileSystemObject")


strWordFilePath = WScript.Arguments(0)
Set objFile     = objFileSys.GetFile(strWordFilePath)

strTextFilePath = WScript.Arguments(1)


Set objWordApp = WScript.CreateObject("Word.Application")

If Err.Number = 0 Then
  'WScript.Echo "create success"

  Set objWordDoc = objWordApp.Documents.Open(objFile.Path, false, true)
  'WScript.Echo "will save to" & strTextFilePath
  If Err.Number = 0 Then

    'WScript.Echo "open success"
    objWordDoc.SaveAs2 strTextFilePath, 2, false, "", true, "", false, false, false, false, false, 65001
 
    objWordDoc.Close
    objWordApp.Quit
  Else
    WScript.Echo "error:" & Err.Description
  End If
Else
  WScript.Echo "error:" & Err.Description
End If
 
Set objWordDoc = Nothing
Set objWordApp = Nothing
Set objFileSys = Nothing
Set objFile    = Nothing

 

posted @ 2021-12-15 17:19  dzqabc  阅读(170)  评论(0编辑  收藏  举报