Board logo

标题: [文本处理] 求助:bat如何批量删除多个word文档里的分页符 [打印本页]

作者: 453765918    时间: 2023-10-20 14:06     标题: 求助:bat如何批量删除多个word文档里的分页符

bat如何批量删除多个word文档里的分页符
作者: Five66    时间: 2023-10-21 05:09

你看下面这个行不?
https://www.cnblogs.com/sharer/p/17538327.html
作者: Batcher    时间: 2023-10-21 11:56

回复 1# 453765918


test.bat
  1. # & cls & @cd /d "%~dp0" & powershell -c "Get-Content '%~0' | Out-String | Invoke-Expression " & exit /b
  2. # 设置待处理的文件所在的文件夹路径
  3. $OldFolder = "C:\Test\From"
  4. # 处理之后的文件保存到新的文件夹路径
  5. $NewFolder = "C:\Test\To"
  6. $Word = New-Object -ComObject Word.Application
  7. Get-ChildItem -Path $OldFolder "*.docx" | ForEach-Object {
  8.     $_.FullName
  9.     $NewName = $NewFolder + "\" + $_.Name
  10.     $Doc = $Word.Documents.Open($_.FullName)
  11.     $Select = $Word.Selection
  12.     $Select.WholeStory()
  13.     $OldStr = "^m"
  14.     $NewStr = ""
  15.     $Select.Find.Execute($OldStr, $false, $true, $false, $false, $false, $true, $false, $false, $NewStr)
  16.     $Doc.SaveAs($NewName)
  17.     $Doc.Close()
  18. }
  19. $word.Quit()
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2