【发布时间】:2017-02-02 21:16:54
【问题描述】:
我有一个 Gulp 任务监视 Excel 文件并运行 VBScript:
Gulp 代码:
.pipe(shell([
'XlsToCsv.vbs test test.xlsx test.csv'
]))
VBScript 代码:
If WScript.Arguments.Count < 3 Then
WScript.Echo "Please specify the sheet, the source, the destination files. Usage: ExcelToCsv <sheetName> <xls/xlsx source file> <csv destination file>"
Wscript.Quit
End If
csv_format = 6
Set objFSO = CreateObject("Scripting.FileSystemObject")
src_file = objFSO.GetAbsolutePathName(Wscript.Arguments.Item(1))
dest_file = objFSO.GetAbsolutePathName(WScript.Arguments.Item(2))
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(src_file)
oBook.Sheets(WScript.Arguments.Item(0)).Select
oBook.SaveAs dest_file, csv_format
oBook.Close False
oExcel.Quit
它工作正常,除了当我以 CSV 格式重新保存文件时提示跳转。 比如“同名的文件已经存在。要保存吗?”
我无法在保存之前删除之前的文件,因为 Gulp 观察程序会触发代码执行。
oBook.Close SaveChanges = True 和 oExcel.DisplayAlerts = False 不起作用。
我需要在每次保存时静默运行此脚本。
我应该在脚本中添加什么命令?
附:我不介意使用任何其他脚本,除了 PowerShell - Set-ExecutionPolicy remotesigned 导致错误
Set-ExecutionPolicy : 拒绝访问注册表项 HKEY_LOCAL_MACHINE...\Microsoft.PowerShell'
【问题讨论】:
-
Re: PowerShell - 您需要在提升的提示符下运行
Set-ExecutionPolicy
标签: excel powershell csv vbscript gulp