none
Convert excel .xlsx to .csv using Powershell RRS feed

  • Question

  • Hi All,

    I am getting and excel report with file extension .xlsx and I want to convert the file to .csv using Powershell 

    Can this be done ? I alreay tried but did not find any concrete way/method to do so

    Please guide


    Thanks in Advance, Jiniv Thakkar

    Wednesday, November 16, 2016 6:49 PM

Answers

  • Hi Jiniv Thakkar,

    You could try the following PowerShell:

    Function ExcelCSV ($File)
    
    {
    
        $pwd = "C:\Users\Administrator.CONTOSO\Desktop"
    
        $excelFile = "$pwd\" + $File + ".xlsx"
    
        $Excel = New-Object -ComObject Excel.Application
    
        $Excel.Visible = $false
    
        $Excel.DisplayAlerts = $false
    
        $wb = $Excel.Workbooks.Open($excelFile)
    
        foreach ($ws in $wb.Worksheets)
    
        {
    
            $ws.SaveAs("$pwd\" + $File + ".csv", 6)
    
        }
    
        $Excel.Quit()
    
    }
    
    $FileName = "excel2"
    
    ExcelCSV -File $FileName
    

    Note: Don’t forget to change the file name and the location.

    Best Regards,

    Linda Zhang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by Jiniv Thakkar Friday, November 18, 2016 2:47 PM
    Thursday, November 17, 2016 5:58 AM
    Moderator
  • Hi Jiniv Thakkar,

    Yes, you should run this cmdlet on the server which has Excel application. Otherwise, we cannot use the Excel comObject.

    Another workaround, you could try the following cmdlets.

    https://blogs.technet.microsoft.com/pstips/2014/06/02/get-excel-data-without-excel/

    Best Regards,

    Linda Zhang


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by Jiniv Thakkar Saturday, November 26, 2016 8:30 AM
    Monday, November 21, 2016 7:55 AM
    Moderator

All replies