将旧式的 Word 文档转为新的 .docx 格式需要比较多工作量。多谢 PowerShell,您可以自动完成该转换工作:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| function Convert-WordDocument { param ( [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)] [string] [Alias('FullName')] $Path ) begin { $word = New-Object -ComObject Word.Application }
process { $pathOut = [System.IO.Path]::ChangeExtension($Path, '.docx')
$doc = $word.Documents.Open($Path)
Write-Progress -Activity 'Converting' -Status $PathOut
$doc.Convert()
$doc.SaveAs([ref]$PathOut,[ref]16)
$word.ActiveDocument.Close() } end { $word.Quit() } }
|