Powershell Convert XLS file to CSV using Powershell


Hi All,

Below is the little snippet used to convert the Excel file to Csv format. Remember irrespective of how many sheets you had, after converting CSV file would have only one sheet

function ConvertFromExceltoCSV ( $Inputfilepath) {

$excel = New-Object -ComObject excel.application

$excel.visible = $false

Start-Sleep -Seconds 1

$fileOutputPath = $ Inputfilepath.Split(".")[0] + ".csv"

$reportOut = $excel.Workbooks.Open("$Inputfilepath ")

$reportOut.SaveAs("$fileOutputPath ", [Microsoft.Office.Interop.Excel.XlFileFormat]::xlCSV)

$reportOut.Close(0)

$excel.Quit()

}

# Calling the function with Excel file as input by giving the location of excel sheets

Get-ChildItem -Path ‘C:\Users\Chaitanya\Documents\PS_Cert-Removal\Certs’ -Recurse | ForEach-Object -Process {

ConvertFromExceltoCSV – Inputfilepath $_.FullName

}

Regards,

Chaitanya

Leave a comment