|
服了
写个蜗牛,43万行折成1万行一个的,要50秒左右
Sub csv拆分多个文件1()
t = Timer
Dim cnn As Object
Set cnn = CreateObject("adodb.connection")
Dim rst As New ADODB.Recordset
MyPath = "d:\tmp\"
cnn.Open "rovider=Microsoft.Ace.OLEDB.12.0;Extended Properties='text;FMT=DELIMITED';Data Source=" & MyPath
SQL$ = "select * from test.csv"
rst.Open SQL, cnn, 1, 1
For i = 0 To rst.Fields.Count - 1
s = s & "," & rst.Fields(i).Name
Next
Open MyPath & "test0.csv" For Output As #1
Print #1, Mid(s, 2)
r& = 1
f% = 0
Do While r <= rst.RecordCount
stmp = ""
For j% = 0 To rst.Fields.Count - 1
stmp = stmp & "," & rst.Fields(j).Value
Next
rst.MoveNext
Print #1, Mid(stmp, 2)
If r Mod 10000 = 0 Then
Close #1
f = f + 1
Open MyPath & "test" & f & ".csv" For Output As #1
Print #1, Mid(s, 2)
End If
r = r + 1
Loop
If Len(stmp) Then Print #1, Mid(stmp, 2)
Close #1
cnn.Close
Set cnn = Nothing
[a2] = Timer - t
End Sub
|
|