把下面的程式碼儲存到指令碼檔案中(比如test.vbs),然後將這個檔案複製到你那4000個txt檔案所在的目錄,然後雙擊執行它,結果會儲存到檔案output.csv中,雙擊這個檔案就能用Excel開啟它。Set objFSO = CreateObject("Scripting.FileSystemObject") Set objOutput = CreateObject("ADODB.Stream")objOutput.Type = 2 "Specify stream type - we want To save text/string data.objOutput.Charset = "utf-8" "Specify charset For the source text data.objOutput.Open "Open the stream And write data To the objectFor i=1 To 4000 fn = i & ".txt" If objFSO.FileExists(fn) Then Set objInput = objFSO.OpenTextFile(fn, 1) Do Until objInput.AtEndOfStream str = Trim(objInput.ReadLine) If Len(str)>0 Then objOutput.WriteText(Replace(str, "|", ",", 1) & vbCrLf) End If Loop objInput.Close Else "Wscript.Echo "File " & fn & " does not exist." End If NextobjOutput.SaveToFile "output.csv", 2 "Save data To disk
把下面的程式碼儲存到指令碼檔案中(比如test.vbs),然後將這個檔案複製到你那4000個txt檔案所在的目錄,然後雙擊執行它,結果會儲存到檔案output.csv中,雙擊這個檔案就能用Excel開啟它。Set objFSO = CreateObject("Scripting.FileSystemObject") Set objOutput = CreateObject("ADODB.Stream")objOutput.Type = 2 "Specify stream type - we want To save text/string data.objOutput.Charset = "utf-8" "Specify charset For the source text data.objOutput.Open "Open the stream And write data To the objectFor i=1 To 4000 fn = i & ".txt" If objFSO.FileExists(fn) Then Set objInput = objFSO.OpenTextFile(fn, 1) Do Until objInput.AtEndOfStream str = Trim(objInput.ReadLine) If Len(str)>0 Then objOutput.WriteText(Replace(str, "|", ",", 1) & vbCrLf) End If Loop objInput.Close Else "Wscript.Echo "File " & fn & " does not exist." End If NextobjOutput.SaveToFile "output.csv", 2 "Save data To disk