大概像这样- #@&cls&powershell "type '%~0'|out-string|iex"&pause&exit
- $in='测试.docx'
- $out=$in+'.zip'
- copy $in ($in+'.zip')
- $f=gi $out
- $xf='document.xml'
- $shell=New-Object -com shell.application
- $shell.Namespace("$pwd").MoveHere($($shell.NameSpace($f.fullname+'\word').items()|?{ $_.name -eq $xf }))
- $xf=gi $xf
- $a=gc $xf -enc utf8
- $a[1] -match '(?<=\<w:body\>).*(?=\<w:sectpr)'
- $b=$matches[0]
- $c=$b -split '(?<!^)(?=<w:p\s[^>]+><w:ppr><w:pStyle w:val="1"/>.*</w:p>)'
- del $xf
- $c|%{
- $d=$_ -split '(?<!^)(?=<w:p\s[^>]+>)'
- $fn=$d[0] -replace '<[^>]+>'
- $zip=$fn+'.zip'
- copy $out $zip
- $zip=gi $zip
- [io.file]::WriteAllLines($xf.fullname,($a -replace '(?<=\<w:body\>).*(?=\<w:sectpr)',$_))
- $shell.Namespace($zip.fullname+'\word').moveHere($xf.fullname)
- while(test-path $xf){sleep -m 100}
- mv $zip ($zip.basename+'.docx')
- }
- del $out
复制代码
|