【发布时间】:2021-02-17 16:46:43
【问题描述】:
我需要使用 VBScript 从 CSV 文件中删除各个列。
要消除的列是从第101到第106。
我下面的代码不会删除任何列:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, strLine, dataArray, clippedArray()
InputFile="C:\input.csv"
OutputFile="C:\input_n_1.csv"
Set fso = CreateObject("Scripting.FileSystemObject")
Set InFile = fso.OpenTextFile(InputFile, ForReading)
Set OutFile = fso.OpenTextFile(OutputFile, ForWriting, True)
Do While InFile.AtEndOfStream <> True
strLine = InFile.ReadLine
ReDim Preserve clippedArray(x)
clippedArray(x) = Split(strLine,";")
intCount = 0
newLine = ""
For Each Element In clippedArray(x)
If intCount <> (101 OR 102 OR 103 OR 104 OR 105 OR 106) Then
EndChar = "|"
newLine = newLine & Element & EndChar
End If
intCount = intCount + 1
Next
OutFile.WriteLine newLine
Loop
InFile.Close
OutFile.Close
WScript.Echo "Done"
【问题讨论】:
标签: csv vbscript multiple-columns