复制代码
- #@&cls&powershell "type '%~0'|out-string|iex"&pause&exit
- $fn='aaaaaa.xlsx'
- $a=new-object -com excel.application
- $a.visible=1
- $b=$a.workbooks.open("$(dir $fn)")
- $c=$b.sheets.item(1)
- $d=$c.usedrange.cells.value()
- $i=$d.length/7
- 2..$i|%{
- if($f){
- if($d[$_,4]){
- $d[$_,7]+=[string]$d[$_,6]+' '
- $d[$_,6]=''
- }else{
- $f+=1
- $d[$f,6]=$d[$_,6]
- $d[$_,6]=''
- }
- }else{
- $f=$_
- }
- }
- $c.usedrange.cells.value()=$d
复制代码
- Sub kk()
- Dim aa As Worksheet, bb As Range, cc As Long
- Set aa = Sheets.Item(1)
- Set bb = aa.Range("A:A")
- cc = bb.Count
- dd = 0
- ee = ""
- zz = 2
- For i = 2 To cc
- ff = aa.Cells(i, 4).Value2
- If dd = 2 Then
- If IsEmpty(ff) Then
- dd = 1
- aa.Cells(zz, 7).NumberFormat = "@"
- aa.Cells(zz, 7).Value2 = ee
- ee = ""
- zz = i
- Else
- ee = ee & " " & aa.Cells(i, 6).Value2
- End If
- ElseIf dd = 1 Then
- If IsEmpty(ff) Then
- zz = i
- Exit For
- Else
- ee = ee & " " & aa.Cells(i, 6).Value2
- dd = 2
- End If
- ElseIf dd = 0 Then
- If IsEmpty(ff) Then
- dd = 1
- zz = i
- Else
- zz = zz
- End If
- End If
- Next i
- If Not zz = 2 Then
- For i = zz To 2 Step -1
- If IsEmpty(aa.Cells(i, 7).Value2) Then
- aa.Rows(i).Delete
- End If
- Next i
- End If
- MsgBox "done!!!"
- End Sub
用以下批处代码(存为 test.bat 运行,与 1.csv 文件同目录)可获取一楼示例的结果文件 2.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,
复制代码
- 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
复制代码
- Sub kk()
- Dim aa As Worksheet, bb As Range, cc As Long
- Set aa = Sheets.Item(1)
- Set bb = aa.Range("A:A")
- cc = bb.Count
- dd = 0
- ee = ""
- zz = 2
- For i = 2 To cc
- ff = aa.Cells(i, 4).Value2
- If dd = 2 Then
- If IsEmpty(ff) Then
- dd = 1
- aa.Cells(zz, 7).NumberFormat = "@"
- aa.Cells(zz, 7).Value2 = ee
- ee = ""
- zz = i
- Else
- ee = ee & ";" & aa.Cells(i, 6).Value2 & "," & aa.Cells(i, 13).Text
- End If
- ElseIf dd = 1 Then
- If IsEmpty(ff) Then
- zz = i
- Exit For
- Else
- ee = ee & aa.Cells(i, 6).Value2 & "," & aa.Cells(i, 13).Text
- dd = 2
- End If
- ElseIf dd = 0 Then
- If IsEmpty(ff) Then
- dd = 1
- zz = i
- Else
- zz = zz
- End If
- End If
- Next i
- zz = zz - 2
- If zz > 2 Then
- For i = zz To 2 Step -1
- If Not IsEmpty(aa.Cells(i, 4).Value2) Then
- aa.Rows(i).Delete
- End If
- Next i
- End If
- MsgBox "done!!!"
- End Sub
欢迎光临 批处理之家 (http://www.bathome.net/) | Powered by Discuz! 7.2 |