转换/加密Office 2003文档

卡纳迪亚人

我们有大量(1000个)旧的Excel 2003电子表格需要加密。Excel 2003中的加密现在已经过时,因此我们想将文件更新为2010格式,然后再对其进行加密。我正在尝试找到执行此操作的脚本或程序,但我一直无法做到。我发现的唯一东西是Microsoft迁移计划工具包,其中包括OFC工具。问题在于,此格式转换为2007格式,尽管兼容,但与2010格式不同。2007格式加密使用较弱的EBC块链接,而不是2010使用的CBC方法。同样,在2010年打开2007年的文件将要求保存文件,即使未进行任何更改(大概是将其更新为较新的格式)。

卡纳迪亚人

我最终使用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/

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

LibreOffice 3.6.0.4呈现MS Office 2007文档的问题

来自分类Dev

默认情况下如何在“查看”模式下打开Office 365文档?

来自分类Dev

Office Word。如何在单独的窗口中打开同一文档?

来自分类Dev

打开的在线office 365文档的位置(skydrive)在哪里?

来自分类Dev

将Word 2010文档标签从德语转换为英语?

来自分类Dev

如何默认将我的所有Office365文档打开在桌面上?

来自分类Dev

Mondrian 4文档

来自分类Dev

Kibana 3文档

来自分类Dev

Visual Studio 2013文档链接

来自分类Dev

HTML 5文档概述算法

来自分类Dev

克隆libxml2文档

来自分类Dev

OpenSaml3文档

来自分类Dev

调试Roxygen 2文档

来自分类Dev

Google Play服务4.1文档?

来自分类Dev

Laravel 4.1文档如何工作?

来自分类Dev

Bootstrap 3.1文档-下载示例

来自分类Dev

Mongodump 0文档已转储

来自分类Dev

Google Play服务4.1文档?

来自分类Dev

Visual Studio 2013文档链接

来自分类Dev

注册SharePoint 2010文档库

来自分类Dev

SharePoint Foundation 2013文档管理

来自分类Dev

将A3文档分为两个A4文档

来自分类Dev

为什么JavaFX文档与Java 8文档分开?

来自分类Dev

GScript可以将同一文档中的多个工作表转换为单独的PDF,并将每个PDF发送到每个工作表的单元格B2中包含的电子邮件地址

来自分类Dev

R S4 roxygen2文档

来自分类Dev

Python poppler Qt5文档加载错误

来自分类Dev

Swift 1.2文档更改(Markdown支持)

来自分类Dev

如何从Word 2010文档中删除VBA脚本?

来自分类Dev

Python BeautifulSoup 4文档中给出的示例