我也来练练手,用楼主提供的 1.csv 另存为 1.xlsx
就是说直接读取 excel 文件,不用先转换为 csv 再读取
用数据库SQL语言统计结果
win7x64测试通过- rem 另存为 ANSI 编码 bat
- ' & cls & %windir%\SysWOW64\cscript.exe /nologo /e:vbscript "%~f0" %* & pause & exit /b
-
- f1 = "1.xlsx" '源文件
- f2 = "2.csv" '输出文件
-
- s = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & f1 & ";Extended Properties='Excel 12.0 Xml;HDR=YES'"
- Set oConnection = CreateObject("ADODB.Connection")
- oConnection.Open s
- Set oRecordset = oConnection.OpenSchema(20) 'adSchemaTables
- Do Until oRecordset.EOF = True
- Select Case oRecordset("TABLE_TYPE")
- Case "TABLE"
- s = oRecordset("TABLE_NAME")
- End Select
- oRecordset.MoveNext()
- Loop
- oRecordset.Close()
- Set oRecordset = CreateObject("ADODB.Recordset")
- oRecordset.CursorLocation = 3 'adUseClient
- oRecordset.Open "SELECT 基因名称, MAX(基因长度) AS 基因长度 FROM [" & s & "] GROUP BY 基因名称", oConnection
- s = ""
- For i = 0 To oRecordset.Fields.Count - 1
- s = s & oRecordset(i).Name & ","
- Next
- s = Left(s, Len(s) - 1) & vbCrLf
- Do Until oRecordset.EOF = True
- For i = 0 To oRecordset.Fields.Count - 1
- s = s & oRecordset(i).Value & ","
- Next
- s = Left(s, Len(s) - 1) & vbCrLf
- oRecordset.MoveNext()
- Loop
- oRecordset.Close()
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- Set oTextStream = oFSO.OpenTextFile(f2, 2, True)
- oTextStream.Write s
- oTextStream.Close()
- wsh.Echo "ok"
复制代码
|