Skip to content

Instantly share code, notes, and snippets.

@kavyasukumar
Created November 6, 2014 18:29
Show Gist options
  • Save kavyasukumar/149c59669430dc7f5bf7 to your computer and use it in GitHub Desktop.
Save kavyasukumar/149c59669430dc7f5bf7 to your computer and use it in GitHub Desktop.
Powershell Excel-to-csv
param(
$inputPath,
$outputPath
)
$xlCSV=6
$inputPath = (Resolve-path $inputPath).Path
$outputpath = (Resolve-path $outputpath).Path
get-childitem $inputPath -File | foreach {
write-host "processing $_ "
$Excelfilename = $_.fullname
if(!$outputPath)
{
$outputPath = $_.DirectoryName
}
$CSVfilename =join-path $outputpath $_.BaseName
$CSVfilename+=".csv";
#open excel and save
$Excel = New-Object -comobject Excel.Application
$Excel.Visible = $False
$Excel.displayalerts=$False
$Workbook = $Excel.Workbooks.Open($ExcelFileName)
$Workbook.SaveAs($CSVfilename,$xlCSV)
$Excel.Quit()
If(ps excel){
kill -name excel
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment