Solved How to display the output of an excel/csv in cmd prompt?

February 17, 2016 at 23:26:44
Specs: Windows 7
I have an excel which has 3 rows and 3 columns. I want to run a VBScript ot a bat script and display the contents in cmd prompt.

E.g. viewExcel.vbs
OUTPUT EXPECTED:
Header1, Header2, Header3
A,B,C
D,E,F.

Please help.


See More: How to display the output of an excel/csv in cmd prompt?

Report •

#1
February 18, 2016 at 10:11:26
✔ Best Answer
:: XLS2CSV.BAT - ver 0.21 - Usage: xls2csv Excel_PathName/FileName
@echo off
echo.
if not exist "%~f1" (echo.  File "%~f1" not found & exit /B 1)
echo.  Converting "%~f1", please wait...
echo.
:: XLS2CSV.VBS - VBScript to export an Excel .xls/.xlsx sheet
(
  echo.Dim objXL
  echo.Set objXL = CreateObject^("Excel.Application"^)
  echo.Const xlType = 6 'Comma delimitedtext
  echo.With objXL.Application
  echo.  .DisplayAlerts = False
  echo.  .Visible = False
  echo.  .Workbooks.Open "%~f1"
  echo.  .Workbooks^("%~nx1"^).SaveAs "%~dpn1.csv", xlType
  echo.  .Workbooks^("%~n1.csv"^).Close,SaveChanges = True
  echo.End With
  echo.objXL.Quit
  echo.Set objXL = Nothing
) > %~n0.vbs
:: End_Of_VBScript [XLS2CSV.VBS]

%~n0.vbs
del %~n0.vbs

if not exist "%~dpn1.csv" (echo.  Conversion failed & exit /B 2)
cls & echo.
type "%~dpn1.csv"
del "%~dpn1.csv"
:: End_Of_Batch


Report •
Related Solutions


Ask Question