转换/加密 Office 2003 文档

转换/加密 Office 2003 文档

我们有大量(数千个)旧的 Excel 2003 电子表格需要加密。Excel 2003 中的加密现已过时,因此我们希望将文件更新为 2010 格式,然后加密它们。我正在尝试寻找一个脚本或程序来执行此操作,但一直找不到。我唯一找到的是包含 OFC 工具的 Microsoft Migration Planning Toolkit。问题是这会转换为 2007 格式,虽然它兼容,但与 2010 格式不同。2007 格式加密使用较弱的 EBC 块链接,而不是 2010 使用的 CBC 方法。此外,在 2010 中打开 2007 文件会要求保存文件,即使未进行任何更改(大概是将其更新为较新的格式)。

答案1

我建议你研究一下脚本语言,例如自动识别。脚本语言将复制用户执行的操作,包括鼠标和键盘输入。您可以将其设置为根据列表或位置转换文件。

答案2

我最终使用 Powershell 来自动完成转换。以下是我的脚本,供感兴趣的人参考:

function ConvertTo-XLSX {

<#
.SYNOPSIS
XLS files within a provided path are recursively enumerated and convert to XLSX files.
.DESCRIPTION
XLS files within a provided path are recursively enumerated and convert to XLSX files.
The original XLS files remain intact, a new XLSX file will be created.
.PARAMETER Path
This parameter takes the input of the path where the XLS files are located.
.PARAMETER Visible
Using the parameter will show you how Excel does the work. Not using the parameter will enable Excel 
to accomplish its tasks in the background.
Note: By not using this parameter you will be able to convert some XLS files which have corruptions 
in them, when using the parameter and therefor the Excel GUI will give you an error.
.PARAMETER ToFolder
This parameter enables you to provide a location where the file is saved. When this parameter is 
not used, the file will be saved as an XLS file in the same location as where the 
original XLS file is located.
.PARAMETER Password
If specified, the password will be used to encrypt the converted Excel document.  Passwords are case
sensitive and must be less than 15 characters long.
.PARAMETER Force
If specified, then files that have already been converted (there is already a file with the same name
but a .xlsx extension in the output directory) will be re-converted.
.EXAMPLE
ConvertTo-XLSX -Path 'D:\Data\2012'
.EXAMPLE
ConvertTo-XLSX -Path 'D:\Data\2012' -Visible
.EXAMPLE
ConvertTo-XLSX -Path 'D:\Data\2012' -ToFolder 'D:\Data\2012XLSX'
.EXAMPLE
ConvertTo-XLSX -Path 'D:\Data\2012' -Visible -ToFolder 'D:\Data\2012XLSX'
.EXAMPLE
ConvertTo-XLSX -Path 'D:\Data\2012' -Password 'SecureP@ssword'
.EXAMPLE
ConvertTo-XLSX -Path 'D:\Data\2012' -Force
#>
    [cmdletbinding()]
    param (
        [parameter(mandatory=$true)][string]$Path,
        [parameter(mandatory=$false)][switch]$Visible,
        [parameter(mandatory=$false)][string]$ToFolder,
        [parameter(mandatory=$false)][string]$Password,
        [parameter(mandatory=$false)][switch]$Force
    )
    begin {
        Add-Type -AssemblyName Microsoft.Office.Interop.Excel
        $xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault
        Write-Verbose 'Opening Excel COM object.'
        $Excel = New-Object -ComObject excel.application
        if ($Visible -eq $true) {
          $Excel.visible = $true
        } else {
          $Excel.visible = $false
          $Excel.DisplayAlerts = $false
          $Excel.ScreenUpdating = $false
          $Excel.UserControl = $false
          $Excel.Interactive = $false
        }
        $filetype = "*xls"
    } process {
        if (Test-Path -Path $Path) {
            Get-ChildItem -Path $Path -Include '*.xls' -recurse | ForEach-Object {
                Write-Verbose "Processing $($_.Basename)"
                if ($ToFolder -ne '') {
                    $FilePath = Join-Path $ToFolder $_.BaseName
                    $FilePath += ".xlsx"
                } else {
                    $FilePath = ($_.fullname).substring(0, ($_.FullName).lastindexOf("."))
                    $FilePath += ".xlsx"
                }
                if (!(Test-Path $FilePath) -Or $Force) {
                  Write-Verbose "Opening $($_.Basename)"
                  $WorkBook = $Excel.workbooks.open($_.fullname)
                  Write-Verbose "Saving $($_.Basename) to $FilePath with password $Password"
                  $WorkBook.saveas($FilePath, $xlFixedFormat, $Password)
                  Write-Verbose "Closing $($_.Basename)"
                  $WorkBook.close()
                } else {
                  Write-Verbose "$($_.Basename) already converted."
                }
            }
        } else {
            return 'No path provided or access has been denied.'
        }
    } end {
        Write-Verbose 'Closing Excel'
        $Excel.Quit()
        $Excel = $null
        [gc]::collect()
        [gc]::WaitForPendingFinalizers()
    }
}

这是基于 Jeff Wouters 的脚本,可在此处找到:http://jeffwouters.nl/index.php/2013/10/powershell-function-to-convert-xls-files-to-xlsx/

相关内容