Xlsx 转 csv 在 Jenkins 上运行

Xlsx 转 csv 在 Jenkins 上运行

我有一个 bat 脚本,可以将 xlsx 文件转换为 csv 文件。当我从命令提示符运行批处理脚本时,我没有收到任何错误,它会正确转换,并且 csv 文件会在该位置生成。但是当我从 Jenkins 运行相同的 bat 脚本时,我收到如下错误

C:\Users\SVCT-WI-Jenkins\Desktop\Post_Patching\Mapping_Server\Excel2csv.vbs(9, 1) Microsoft Excel: Microsoft Excel cannot access the file 'C:\Users\SVCT-WI-Jenkins\Desktop\Post_Patching\Mapping_Server\WI_non_cluster_server_list.xlsx'. There are several possible reasons:

 The file name or path does not exist.
 The file is being used by another program.
 The workbook you are trying to save has the same name as a currently open workbook

有人有想法吗请帮忙

我的XLS2CSV.bat

    ::XLS2CSV.bat <xlsx_file> [csv_file_name]
REM @echo off&
setlocal
if "%~1"=="" echo(Excel file input missing...&goto:eof
if not exist "%~dp0excel2csv.vbs" (
(
echo Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
echo src_file = objFSO.GetAbsolutePathName^(Wscript.Arguments.Item^(0^)^)
echo dest_file = objFSO.GetAbsolutePathName^(WScript.Arguments.Item^(1^)^)
echo Dim oExcel
echo Set oExcel = CreateObject^("Excel.Application"^)
echo oExcel.DisplayAlerts = FALSE
echo oExcel.Interactive = FALSE
echo Dim oBook
echo Set oBook = oExcel.Workbooks.Open^(src_file, 0 , TRUE^)
echo Set objWorksheet = oExcel.Worksheets^(1^)
echo objWorksheet.Activate
echo oBook.SaveAs dest_file, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, TRUE
echo oBook.Close False
echo Set objWorksheet = Nothing
echo set oBook = Nothing
echo oExcel.Quit
echo set oExcel = Nothing
)>>"excel2csv.vbs"
)
if "%~2"=="" set "outfile=%~dpn1.csv" else set "Outfile=%~2"
"C:\Windows\System32\cscript.exe" %~dp0Excel2csv.vbs "C:\Program Files (x86)\Jenkins\workspace\test\Post_Patching\Mapping_Server\%~1" "%Outfile%"
echo %errorlevel%
exit/b %errorlevel%

我从 Jenkins Build 部分调用了我的批处理脚本。调用我的脚本XLS2CSV.bat WI_non_cluster_server_list.xlsx

相关内容