मैंने रूपांतरण को स्वचालित करने के लिए 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()
}
}
यह जेफ वाउटर्स की एक स्क्रिप्ट पर आधारित था जो यहां पाया गया: http://jeffwouters.nl/index.php/2013/10/powershell-function-to-convert-xls-files-to-xlsx/