wiki.getshifting.com

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


powershellconvertxlsxtocsvwithdelimiter

PowerShell: Convert Excel File to CSV with Special Delimiter

Summary: Or actually, save an excel file as CSV and then recreate it with a specific delimiter
Date: Around 2013
Refactor: 22 March 2025: Checked links and formatting.

cd "D:\filedir\"
$Excel = New-Object -ComObject Excel.Application
$Excel.visible = $false
$Excel.DisplayAlerts = $False
$file = "D:\filedir\excelfile.xlsx"
$csv = "D:\filedir\excelfile.csv"
$csvfinal = "D:\filedir\excelfilefinal.csv"
$workfile = $Excel.Workbooks.open($file)
$Sheet = $workfile.Worksheets.Item(1)
$Sheet.Activate()
$Sheet.SaveAs($csv,[Microsoft.Office.Interop.Excel.XlFileFormat]::xlCSVWindows)
$workfile.Close()
sleep 5
$Excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel)
Import-Csv $csv | Export-Csv $csvfinal -Delimiter ";" -NoTypeInformation
powershellconvertxlsxtocsvwithdelimiter.txt · Last modified: by 127.0.0.1