Skip to content

Instantly share code, notes, and snippets.

@xfirebg
Forked from gabceb/ConvertXLS.ps1
Last active March 28, 2019 19:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xfirebg/b73feb218e069cc8e0e08027bc560ff9 to your computer and use it in GitHub Desktop.
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)
$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