本帖最后由 flashercs 于 2022-9-19 23:47 编辑
- <#*,:&cls
- @echo off
- cd /d "%~dp0"
- powershell -C "Set-Location -LiteralPath ([Environment]::CurrentDirectory);. ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~f0\" -ReadCount 0 | Out-String)))"
- pause
- exit /b
- #>
- $wordApp = New-Object -ComObject Word.Application -ErrorAction Stop
- Get-ChildItem -Path .\*.doc, .\*.docx -Recurse | Where-Object { -not $_.PSIsContainer } | ForEach-Object {
- $_ | Resolve-Path -Relative
- try {
- $doc = $wordApp.Documents.Open($_.FullName)
- foreach ($section in $doc.Sections) {
- foreach ($footer in $section.Footers) {
- $null = $footer.Range.Delete()
- }
- }
- } finally {
- if ($doc) {
- $doc.Close([ref]$true)
- $doc = $null
- }
- }
- trap {}
- }
- $wordApp.Quit()
复制代码
|