本帖最后由 aloha20200628 于 2024-10-24 17:19 编辑
回复 1# liaoguinan
先调用excel外部接口将*.xls*电子表格文件转为*.csv文本文件,然后就是批处自己的功夫了...免去了用vba在电子表格里反复折腾...
以下代码存为 test.bat 其中第2-3行中的目标文件和路径均由楼主自定义...
- @set @x=1 /* &@echo off &setlocal
- set "xF=d:\测试\测试.xls"
- set "pD=d:\测试"
- cscript /e:jscript "%~f0" "%xF%"
- for /f "usebackq delims=" %%F in ("%xF%.csv") do for /f "tokens=2 delims=- " %%a in ("%%F") do (
- setlocal enabledelayedexpansion &set "a=00%%a" &set "a=!a:~-3!"
- if exist "%pD%\!a!.pdf" ren "%pD%\!a!.pdf" "%%F.pdf"
- endlocal
- )
- del/q "%xF%.csv"&endlocal&pause&exit/b */
- v=WSH.arguments, xls=WSH.createobject('excel.application');
- xls.visible=false, xls.displayalerts=false, wb=xls.workbooks.open(v(0));
- wb.saveas(v(0)+'.csv',6), wb.close(), xls.quit(), WSH.quit();
复制代码
|