我有一个VBScript,可以在一个文件夹中打开任何XML文件,并将它们作为excel文件保存到另一个文件夹中。
它似乎有效,虽然生成的excel文件没有XLS扩展,但为什么会有任何想法?
我希望脚本可以删除源文件夹中的所有文件。 我该怎么做?
Dim xlApp, xlWkb, SourceFolder,TargetFolder,file
Set xlApp = CreateObject("excel.application")
set fs = CreateObject("Scripting.FileSystemObject")
Const xlNormal=1
SourceFolder="c:\test\xml"
TargetFolder="c:\test\xls"
'Hide Excel
xlApp.Visible = false
'Process each file in SourceFolder
for each file in fs.GetFolder(SourceFolder).files
'Open file in SourceFolder
Set xlWkb = xlApp.Workbooks.Open(file)
'Get Filename
BaseName= fs.getbasename(file)
'Concatenate full path. Extension will be automatically added by Excel
FullTargetPath=TargetFolder & "\" & BaseName
'Save as XLS file into TargetFolder
xlWkb.SaveAs FullTargetPath, xlNormal
'Close file
xlWkb.close
next
Set xlWkb = Nothing
Set xlApp = Nothing
Set fs = Nothing
答案 0 :(得分:0)
文件没有扩展名,因为你没有给它。
输出文件是
TargetFolder & "\" & fs.GetBaseName( file )
GetBaseName不包含扩展名。只需添加扩展名
即可TargetFolder & "\" & fs.GetBaseName( file ) & ".xls"