[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "skip=1 tokens=1,2,3 delims=        " %%a in (test.xls) do (
  3.   if not defined flag >test.xls echo job        money
  4.   set flag=1
  5.   if "%%b"=="total" (
  6.     >>test.xls echo %%a:%%b        !total:~0,-2!.!total:~-2!
  7.     set total=0) else (
  8.     >>test.xls echo %%b        %%c
  9.     call :count %%c
  10.   )
  11. )
  12. pause
  13. set flag=&set total=&set money=
  14. exit
  15. :count
  16. set money=%1
  17. if "%money:~-3,1%"=="." (set money=%money:.=%) else (
  18.   if "%money:~-2,1%"=="." (set money=%money:.=%0) else (
  19.     set money=%money%00
  20.   )
  21. )
  22. set /a total=%total%+%money%
  23. goto :eof
复制代码
注:delims是以TAB来分开提取的,echo句中也是TAB来分开的

[ 本帖最后由 shqf 于 2008-12-14 10:36 编辑 ]
1

评分人数

    • batman: 在通用和简洁上还可提高PB + 10

TOP

  1. @echo off&setlocal enabledelayedexpansion
  2. for /f "skip=1 tokens=1,2,3 delims= " %%a in (test.xls) do (
  3.   if not defined flag >test.xls echo job money
  4.   set flag=1
  5.   if "%%b"=="total" (
  6.     >>test.xls echo %%a:%%b !total:~0,-5!.!total:~-5!
  7.     set total=0) else (
  8.     >>test.xls echo %%b %%c
  9.     call :count %%c
  10.     set /a total=!total!+!money!
  11.   )
  12. )
  13. test.xls
  14. exit
  15. :count
  16. for /f "tokens=1,2 delims=." %%i in ("%1") do (
  17.   set money=%%j00000
  18.   set money=!money:~0,5!
  19.   set money=%%i!money!
  20. )
  21. goto :eof
复制代码
小数计算部分略作改善,5位小数内可行。其他地方不知如何再精简了。

TOP

二位版主的代码还真简洁,又一次学习了。

TOP

返回列表