banner



Convert CSV to Excel (XLS or XLSX) using Command line in Windows

Download PC Repair Tool to speedily find & set up Windows errors automatically

Here is a tutorial to convert CSV to XLS or XLSX using the command-line interface in Windows 11/10. There are multiple ways to convert a CSV file to Excel formats (XLS, XLSX). Y'all can employ Microsoft Excel, a defended converter freeware, or an online tool to perform the conversion. But, did you know that you tin can also utilize Windows command-line interface to convert CVS to Excel? And, yous don't even need any third-party tool for that? If not, this tutorial will be pleasantly surprising for y'all.

In this commodity, we are going to testify you how y'all can convert a CSV file to an Excel workbook. For that, we volition exist using a VBScript. Permit us check out the script and steps that you need for conversion.

How to Convert CSV to Excel using Command line

Here are the steps to convert CSV to Excel using Command Line Interface in Windows xi or Windows 10:

  1. Open Notepad.
  2. Write a Visual Bones Script (VBS).
  3. Save the VBS file.
  4. Open Control Prompt in the folder.
  5. Enter the CSV to Excel conversion control.

Let'due south hash out these steps in particular!

Firstly, open the Notepad application on your Windows 10 PC. You now accept to write a VBScript with related commands. Beneath is the full script that y'all need to enter in the Notepad; just copy from here and paste it into your Notepad:

'====================================== ' Convert CSV to Excel ' ' arg1: source - CSV path\file ' arg2: target - Excel path\file '======================================  srccsvfile = Wscript.Arguments(0)  tgtxlsfile = Wscript.Arguments(1)  'Create Spreadsheet 'Look for an existing Excel instance. On Error Resume Next ' Turn on the error handling flag Set objExcel = GetObject(,"Excel.Application") 'If not found, create a new instance. If Err.Number = 429 So '> 0 Set objExcel = CreateObject("Excel.Application") End If  objExcel.Visible = false objExcel.displayalerts=faux  'Import CSV into Spreadsheet Set objWorkbook = objExcel.Workbooks.open(srccsvfile) Gear up objWorksheet1 = objWorkbook.Worksheets(1)  'Adjust width of columns Prepare objRange = objWorksheet1.UsedRange objRange.EntireColumn.Autofit() 'This code could be used to AutoFit a select number of columns 'For intColumns = ane To 17 ' objExcel.Columns(intColumns).AutoFit() 'Side by side  'Make Headings Bold objExcel.Rows(one).Font.Bold = True  'Freeze header row With objExcel.ActiveWindow .SplitColumn = 0 .SplitRow = ane End With objExcel.ActiveWindow.FreezePanes = Truthful  'Add Information Filters to Heading Row objExcel.Rows(one).AutoFilter  'gear up header row grayness objExcel.Rows(ane).Interior.ColorIndex = 15 '-0.249977111117893  'Save Spreadsheet, 51 = Excel 2007-2010  objWorksheet1.SaveAs tgtxlsfile, 51  'Release Lock on Spreadsheet objExcel.Quit() Set objWorksheet1 = Nix Gear up objWorkbook = Goose egg Set ObjExcel = Nothing

After entering the in a higher place script, you need to save the file with the .vbs file extension. For that, click on the File > Salvage Equally pick. In the Save Every bit dialog prompt, set Relieve Every bit Type to All Files and then enter the filename followed by the .vbs file extension. Later that, click on the Save push button to salve the VBS file.

Now, go to the binder where y'all have saved the above VBS script and open up Command Prompt in this folder.

Side by side, you accept to enter a command with the beneath syntax in CMD:

VBSFilename [Input CSV file with path] [Output Excel file with path]

Let'due south say you have named the VBS file as "csv-to-excel", then your control will look something like the below one:

csv-to-excel C:\Users\KOMAL\Desktop\twc.csv C:\Users\KOMAL\Desktop\twc1.xlsx

In case yous want to create an Excel file with the older file extension i.due east., XLS, but replace xlsx with xls. Here is an instance:

csv-to-excel C:\Users\KOMAL\Desktop\twc.csv C:\Users\KOMAL\Desktop\twc1.xls

Do recall that you have to mention the full path of both input CSV and output Excel files.

How to Convert CSV to Excel (XLS or XLSX) using Command line in Windows 10

Every bit y'all enter the higher up command, you will get the output Excel file.

Convert CSV to Excel using Command line

In the above VBScript, there are options to conform column width, freeze pane, apply filter, make header bold, etc. Yous can easily tweak the VBScript to customize these options and and then run the command to catechumen CSV to Excel through CMD. If you are a programmer, you lot can farther customize the script appropriately.

Then, this is how you lot can convert CSV to Excel using Command-Line with aid of a VBScript created by Jeff.

Related reads:

  • How to convert DBF to Excel in Windows
  • How to catechumen a Text (TXT/CSV) file into an Excel file
  • Free Batch PDF to Excel Converter Software.

Convert CSV to Excel using Command line

Komal has washed M.Tech in CSE. For the concluding 4 years, she has been writing technical blogs - and she is keen on finding and bringing solutions to solar day-to-day tech problems.

Source: https://www.thewindowsclub.com/how-to-convert-csv-to-excel-xls-or-xlsx-using-command-line-in-windows-10

Posted by: rodriguenother44.blogspot.com

0 Response to "Convert CSV to Excel (XLS or XLSX) using Command line in Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel