假设一楼示例的 *.xls* 文件存为 1.csv 如下:- 1,,,,,编号,合并
- 2,,,,,708,
- 3,,,10,,301,
- 4,,,,,709,
- 5,,,10,,301,
- 6,,,,,709,
- 7,,,10,,307,
- 8,,,20,,301,
- 9,,,,,709,
- 10,,,1,,303,
- 11,,,12,,400,
- 12,,,13,,500,
复制代码
用以下批处代码(存为 test.bat 运行,与 1.csv 文件同目录)可获取一楼示例的结果文件 2.csv 如下:- 1,,,,,编号,合并
- 2,,,,,708, 301
- 4,,,,,709, 301
- 6,,,,,709, 307 301
- 9,,,,,709, 303 400 500
复制代码
- @echo off &setlocal enabledelayedexpansion
- echo,1,,,,,编号,合并>2.csv
- (for /f "skip=1 delims=" %%A in (1.csv) do (
- set "a=%%A" &for /l %%n in (1,1,2) do set "a=!a:,,=,#,!"
- for /f "tokens=1-6 delims=," %%a in ("!a!") do (
- if "%%d"=="#" ((if defined s echo,!s!)&set "s=%%A") else (set "s=!s! %%f")
- ))
- if defined s echo,!s!)>>2.csv
- endlocal&pause&exit/b
复制代码