CSV文件批量转换为EXCEL文件

把如下文件存为 runvbs.cmd

rem wscript.exe //e:vbscript Deploy.vbs
wscript.exe w.vbs


把如下文件存为  w.vbs

Set fso=createobject("scripting.filesystemobject")
'创建一个文件系统对象
set self=fso.opentextfile(wscript.scriptfullname,1)


sub scan(folder_) 'scan函数定义,
on error resume next '如果出现错误,直接跳过,防止弹出错误窗口
set folder_=fso.getfolder(folder_)
set files=folder_.files ' 当前目录的所有文件集合
'for each file in filesext=fso.GetExtensionName(file)
for each file in files
ext=fso.GetExtensionName(file)
 '获取文件后缀
ext=lcase(ext) '后缀名转换成小写字母
'Wscript.echo (ext)
if ext="csv" then '如果后缀名是csv,则进行转换。

'请自己建立相应后缀名的文件,最好是非正常后缀名 ,以免破坏正常程序。
'Wscript.echo (file)

convertCSV2EXCEL(file)

end if
'ifnextset subfolders=folder_.subfoldersfor each subfolder in subfolders '搜索其他目录;递归调用
'  scan( ) scan(subfolder)
' next
next
end sub

 

scan("c:\css")


sub convertCSV2EXCEL(csvfilename)

Set xlApp = CreateObject("excel.Application")
xlApp.Visible = false

Dim xlbook '创建工作簿
'set xlbook=CreateObject("Excel.Workbook")
'xlbook=xlApp.Workbooks


Set xlbook = xlApp.Workbooks.Open(csvfilename) '打开CSV文件

'Dim WshShell,Path
'Set WshShell=WScript.CreateObject("WScript.Shell")
'Path="""\test1.exe""" 这句的路径怎么写?不是写绝对路径!!
'WshShell.Run Path

xlbook.SaveAs csvfilename+".xls",1
xlbook.close
xlApp.quit
set xlapp=nothing
END SUB

 


 

posted @ 2007-08-05 19:20  观我生,君子无咎  阅读(7532)  评论(0)    收藏  举报