Question

Convert excel to csv and csv to excel using Powershell.

  • 21 July 2023
  • 0 replies
  • 512 views

Userlevel 4
Badge +2

Solution:- 

Convert csv to excel:

Step 1: Use "Tbox Start Program" to open powershell.exe

Step 2: In the argument section, give the command:- 

$xl = new-object -comobject excel.application
$Workbook = $xl.workbooks.open('{CP[File_Path]}')
$Worksheets = $Workbooks.worksheets
$Workbook.SaveAs('{CP[Excel_Path]}',-4143)
$Workbook.Saved = $True
$xl.Quit()

Here, FilePath: you can provide the path of your csv file.

Excel_Path: you can provide the path where you want to save your excel file. The format should be "Excel_Path.xls"

Step 3: Just check in your machine if it getting converted.

Convert excel to csv:

- You just need to replace the code in argument as:

$xl = new-object -comobject excel.application
$Workbook = $xl.workbooks.open('C:\bin\CSV & EXCEL\Dummy.xls')
$Worksheets = $Workbooks.worksheets
$Workbook.SaveAs('C:\bin\CSV & EXCEL\Dummy.csv',1)
$Workbook.Saved = $True
$xl.Quit()


0 replies

Be the first to reply!

Reply