Convert multiple xls to csv using powershell

后端 未结 3 1309
傲寒
傲寒 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:40

    You can just wrap it in a loop that iterates over all the files and change the xls extension to csv:

    foreach($file in (Get-ChildItem "C:\temp")) {
    
      $newname = $file.FullName -replace '\.xls$', '.csv'
      $ExcelWB = new-object -comobject excel.application
      $Workbook = $ExcelWB.Workbooks.Open($file.FullName) 
      $Workbook.SaveAs($newname,6)
      $Workbook.Close($false)
      $ExcelWB.quit()
    
    }
    

提交回复
热议问题