Friday, 20 August 2021

Convert CSV to Excel

# Collect all CSV name in a TXT File
(get-childitem "C:\SUMANT\test").FullName > C:\SUMANT\CSVName.txt

(gc "C:\SUMANT\CSVName.txt") | foreach-object{
    [string]$csv = $_
    
    $xlsx = ($csv).replace("csv","xlsx")
    $xl = New-Object -ComObject "Excel.Application"
    $xl.Visible=$False
    $wb = $xl.Workbooks.Open($csv)
    $wb.SaveAs($xlsx, 51)
    $xl.Quit()

No comments:

Post a Comment