0

not a super strong powershell guy.I am trying to convert a CSV file to XLSX using Powershell. With the code below i can only save it as XLS not XLSX. If i put "$Workbook.SaveAs(“c:\sdk\AdEmployeeNumber.xlsX”,1)" excel thinks the file is corrupted.

$xl = new-object -comobject excel.application
$xl.visible = $true`enter code here`
$Workbook = $xl.workbooks.open(“c:\sdk\AdEmployeeNumber.csv”)
$Worksheets = $Workbooks.worksheets
$Workbook.SaveAs(“c:\sdk\AdEmployeeNumber.xls”,1)
$Workbook.Saved = $True
$xl.Quit()
lakeek
  • 25
  • 4
  • Try `$Workbook.SaveAs(“c:\sdk\AdEmployeeNumber.xlsx”,51)` – BigBen Nov 29 '22 at 20:38
  • 2
    If you want to give [`ImportExcel` Module](https://github.com/dfinke/ImportExcel) a try this task is as easy as `Import-Csv .\source.csv | Export-Excel .\destination.xlsx` – Santiago Squarzon Nov 29 '22 at 21:41
  • Pass it a proper excel file format. `$Workbook.SaveAs("c:\sdk\AdEmployeeNumber.xlsx",[Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook)` – Abraham Zinala Nov 29 '22 at 22:26
  • [This thread](https://stackoverflow.com/questions/17688468/how-to-export-a-csv-to-excel-using-powershell) has a couple solutions that may help you. – kconsiglio Nov 29 '22 at 22:46

0 Answers0