.xlsx to .csv conversion through Powershell in windows server 2012 RRS feed

  • Question

  • Hi Team,

    I have created below function in powershell to convert an .xlsx file into .csv ,the script is running in windows server 2012 machine.The script is getting complete without any error but it not doing the conversion.When same script I have tried in my laptop win 10 its working perfectly.Can you please confirm how to fix this issue.

    function xlsx_to_csv($xlinput,$csvout) {
        # Create a new Excel Workbook with one empty sheet
        $excel = New-Object -ComObject excel.application 
        #Don't prompt the user asking to replace existing file if one already exists with the same name.
        $excel.DisplayAlerts = $false
        $Workbook = $excel.Workbooks.Open("$xlinput") 
        #End the excel object
        $t = $excel.Quit()
        $t = Release-Ref($Workbook) 
        $t = Release-Ref($excel) 
    xlsx_to_csv $yest_xl_in $yest_csv_in

    $yest_xl_in and $yest_csv_in are the location where my file present.

    Monday, April 2, 2018 5:49 PM

All replies

  • I suspect your file path is not what you think it is.


    Monday, April 2, 2018 6:19 PM
  • In windows server excels is not installed, Is this the reason its failing? because I am sure the path settings working fine when I am testing the same code against other windows 7 and windows 10 machines. Its only failing when running on any server OS.
    Tuesday, April 3, 2018 4:27 AM
  • If Excel is not installed of course it won't work but you will get a  very obvious error.  You are claiming you get no error.

    Both assertions cannot be true.


    Tuesday, April 3, 2018 4:30 AM