我想知道是否有办法使用批处理脚本从excel文件中提取和过滤(仅选择一些列和行)数据。我已经在谷歌寻找答案但是徒劳无功。
答案 0 :(得分:1)
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""C:\Users\David Candy\Documents\Alcohol.xls"";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"
objRecordset.Open "SELECT * FROM `C:\Users\David Candy\Documents\Alcohol`.`Sheet1$` `Sheet1$`", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText
Do Until objRecordset.EOF
Wscript.Echo "Name: " & objRecordset.Fields.Item("Price")
objRecordset.MoveNext
Loop
使用cscript运行
cscript //nologo c:\pathto\script.vbs
它将Price列写入控制台