Open csv with semi column separator and save as excel format RRS feed

  • Question

  • 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?

    Wednesday, June 27, 2012 12:29 PM


  • 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

    • Marked as answer by Yan Li_ Tuesday, July 3, 2012 7:11 AM
    Wednesday, June 27, 2012 12:53 PM

All replies