【问题标题】:how can i convert a RTF docoment to docx如何将 RTF 文档转换为 docx
【发布时间】:2020-01-13 23:22:42
【问题描述】:

我在here 上发现了类似的东西,但是当我尝试运行它时,我得到了错误。 因此我想知道是否可以制作一个可以获取 .RTF 文档并将它们全部转换为 .docx 文档的 Powershell 脚本?

【问题讨论】:

标签: powershell


【解决方案1】:

使用它来将 rtf 转换为 docx:

Function Convert-Dir($path){
    $Files=Get-ChildItem "$($path)\*.docx" -Recurse
    $Word=New-Object –ComObject WORD.APPLICATION

    foreach ($File in $Files) {
        # open a Word document, filename from the directory
        $Doc=$Word.Documents.Open($File.fullname)

        # Swap out DOCX with PDF in the Filename
        $Name=($Doc.Fullname).replace("docx","doc")

        if (Test-Path $Name){

        } else {
            # Save this File as a PDF in Word 2010/2013
            Write-Host $Name
            $Doc.saveas([ref] $Name, [ref] 0)  
            $Doc.close()
        }
    }

    $Files=Get-ChildItem "$($path)\*.rtf" -Recurse
    $Word=New-Object –ComObject WORD.APPLICATION

    foreach ($File in $Files) {
        # open a Word document, filename from the directory
        $Doc=$Word.Documents.Open($File.fullname)

        # Swap out DOCX with PDF in the Filename
        $Name=($Doc.Fullname).replace("rtf","doc")

        if (Test-Path $Name){

        } else {
            # Save this File as a PDF in Word 2010/2013
            Write-Host $Name
            $Doc.saveas([ref] $Name, [ref] 0)  
            $Doc.close()
        }
    }
}

Convert-Dir "RtfFilePath";

代码来自和归属:https://gist.github.com/rensatsu/0a66a65c3a508ecfd491#file-rtfdocxtodoc-ps1

【讨论】:

  • 在我尝试运行它时出错。 “找不到类型 word.apploication”等等。是否缺少一些我需要导入的模块?
猜你喜欢
  • 2021-04-19
  • 1970-01-01
  • 2017-09-23
  • 2014-04-04
  • 2017-01-22
  • 2011-06-03
  • 1970-01-01
  • 2021-03-02
相关资源
最近更新 更多