Open csv with semi column separator and save as excel format


  • I Open csv with semi column separator and want save as excel format
    Excel can be open and format as proper excel column separate by semi column but when save, it give error
    $workbook.SaveAs("c:\temp\merged.xlsx")  -> give You cannot call a method on a null-valued expression

    $excel = New-Object -ComObject excel.application
    $excel.visible = $False
    $workbook = $excel.Workbooks.OpenText("c:\temp\merged.csv",$xlWindows,1,1,1,$True,$True,$False,$True,$False,$False)
    #$workbook = $excel.Workbooks.Open("$workdir\merged.csv")
    $excel = $null


    when $excel.Workbooks.Open -> write-host $workbook give System.__ComObject
    when $excel.Workbooks.Opentext -> write-host $workbook give blank/nothing

    Can someone please help?

    mercoledì 27 giugno 2012 12:29


  • You could pre-process your csv file and just open the csv file normally with Excel:

    Import-CSV $inputfile -Delimeter ';' | Export-CSV $outputfile -NoType

    Grant Ward, a.k.a. Bigteddy

    mercoledì 27 giugno 2012 12:53

Tutte le risposte