0

我有一个 VBScript,可以将文件夹中的任何 XML 文件转换为 XLS,然后删除 XML 文件 - 一切正常。

但是,我知道需要将 XML 转换为 CSV 而不是 XLS。

我需要在脚本中进行哪些更改才能允许这样做?简单地更改结果文件的扩展名显然是行不通的。

Dim xlApp, xlWkb, SourceFolder,TargetFolder,file
Set xlApp = CreateObject("excel.application")
Set fs = CreateObject("Scripting.FileSystemObject")

Const xlNormal=1

SourceFolder="c:\xml-to-xls\xml"
TargetFolder="c:\xml-to-xls\xls"

xlApp.Visible = false

for each file in fs.GetFolder(SourceFolder).files
  Set xlWkb = xlApp.Workbooks.Open(file)
  BaseName= fs.getbasename(file)
  FullTargetPath=TargetFolder & "\" & BaseName & ".xls"
  xlWkb.SaveAs FullTargetPath, xlNormal
  xlWkb.close
next

fs.DeleteFile("C:\xml-to-xls\xml\*.xml")

Set xlWkb = Nothing
Set xlApp = Nothing
Set fs = Nothing

谢谢

4

2 回答 2

2

根据评论更新:谢谢大家

Const xlCSV = 6
xlWkb.SaveAs FullTargetPath, xlCSV, , , , , , 2
xlWbk.Saved = True
xlWkb.close
于 2013-10-29T08:50:31.983 回答
2

谢谢大家...这是完成的脚本

Dim xlApp, xlWkb, SourceFolder,TargetFolder,file
Set xlApp = CreateObject("excel.application")
Set fs = CreateObject("Scripting.FileSystemObject")

Const xlNormal=1
Const xlCSV=6

SourceFolder="c:\xml-to-xls\xml"
TargetFolder="c:\xml-to-xls\xls"

xlApp.Visible = false

for each file in fs.GetFolder(SourceFolder).files
  Set xlWkb = xlApp.Workbooks.Open(file)
  BaseName= fs.getbasename(file)
  FullTargetPath=TargetFolder & "\" & BaseName & ".csv"
  xlWkb.SaveAs FullTargetPath, xlCSV, , , , , , 2
  xlWkb.Saved = True
  xlWkb.close
  file.Delete
next

Set xlWkb = Nothing
Set xlApp = Nothing
Set fs = Nothing
于 2013-11-04T12:00:33.213 回答