Convert multiple xls to csv using powershell

后端 未结 3 1308
傲寒
傲寒 2020-12-16 21:24

I\'m trying to convert multiple excel files (xls) to csv which is located in a folder using powershell.

I can convert a single file but need help converting multiple

3条回答
  •  轮回少年
    2020-12-16 21:50

    There are caveats with this untested code but it should help wrap your head around your issue

    $ExcelWB = new-object -comobject excel.application
    
    Get-ChildItem -Path c:\folder -Filter "*.xls" | ForEach-Object{
        $Workbook = $ExcelWB.Workbooks.Open($_.Fullname) 
        $newName = ($_.Fullname).Replace($_.Extension,".csv")
        $Workbook.SaveAs($newName,6)
        $Workbook.Close($false)
    }
    $ExcelWB.quit()
    

    Take the lines in between the first and last and build a loop. Use Get-ChildItem to grab your xls files and then build a new name by replacing the extension if the FullName of the file

提交回复
热议问题