-
-
Save xfirebg/b73feb218e069cc8e0e08027bc560ff9 to your computer and use it in GitHub Desktop.
Powershell script to convert all .xls documents to .xlsx in a folder and delete the old one(full auto)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook | |
write-host $xlFixedFormat | |
$excel = New-Object -ComObject excel.application | |
$excel.visible = $false | |
$folderpath = "D:\Users\Username\Desktop\test" | |
$filetype ="*xls" | |
Get-ChildItem -Path $folderpath -Include $filetype -recurse | | |
ForEach-Object ` | |
{ | |
$path = ($_.fullname).substring(0, ($_.FullName).lastindexOf(".")) | |
"Converting $path" | |
$workbook = $excel.workbooks.open($_.fullname) | |
$path += ".xlsx" | |
$workbook.saveas($path, $xlFixedFormat) | |
$workbook.close() | |
remove-item $_.fullname | |
} | |
$excel.Quit() | |
$excel = $null | |
[gc]::collect() | |
[gc]::WaitForPendingFinalizers() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment