Skip to content

Instantly share code, notes, and snippets.

/ConvertXLStoCSV.ps1 Secret

Created Jul 25, 2013
Embed
What would you like to do?
$object = New-Object -comObject Shell.Application
$folder = $object.BrowseForFolder(0, 'Select the folder', 0)
if (!$folder) {exit}
$excel = New-Object -comObject Excel.Application
$excel.Visible = $false
$excel.DisplayAlerts = $false
foreach ($file in Get-ChildItem -literalPath $folder.self.Path*.xls? -recurse) {
$workbook = $excel.Workbooks.Open($file.Fullname)
foreach ($worksheet in $workbook.Sheets) {
$worksheet.activate()
$newpath = $File.DirectoryName +"\"+ $file.BaseName + " - " + $worksheet.name + ".csv"
$workbook.SaveAs($newpath,-4158 ,$null,$null)
}
$workbook.Close()
}
$excel.quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($workbook)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment