Windows - Convert XLS To CSV On Command Line
Windows - Convert XLS To CSV On Command Line
13 Answers
if WScript.Arguments.C
WScript.Echo "Erro
XlsToCsv SourcePath.xl
Wscript.Quit
End If
Dim oExcel
Set oExcel = CreateObj
Dim oBook
Set oBook = oExcel.Wor
oBook.SaveAs WScript.A
oBook.Close
By using our site, you acknowledge thatFalse
you have read and understand our Cookie Policy, Privacy Policy, and our
oExcel.Quit
Terms of Service. WScript.Echo "Done"
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 1/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
Then from a
command line, go to
the folder you saved
the .vbs file in and
run:
XlsToCsv.vbs [sourcexl
4 Requires fully
resolves path
names on my XP
instance. – Andrew
Mar 23 '11 at 6:25
3 I have posted
below a slightly
modified version
which handles file
paths better.
Thanks ScottF! –
plang May 31 '12
at 14:26
7
The code converts
only the active
worksheet. To
select another
worksheet, add the
following line after
the
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our
oExcel.Workbook
Terms of Service. s.Open line with
the desired index of
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 2/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
the worksheet
(starts at 1):
oBook.Worksheets
(1).Activate –
humbads Oct 30
'13 at 18:19
1 It ought to be noted
that this functional
not just on xls or
xlsx, but on any file
that Excel itself can
open. –
user1318135 Aug
23 '17 at 19:26
A slightly modified
version of ScottF
68 answer, which does
not require absolute
file paths:
if WScript.Arguments.C
WScript.Echo "Plea
<xls/xlsx source file>
Wscript.Quit
End If
csv_format = 6
src_file = objFSO.GetA
dest_file = objFSO.Get
Dim oExcel
Set oExcel = CreateObj
Dim oBook
Set oBook = oExcel.Wor
oBook.SaveAs dest_file
oBook.Close False
oExcel.Quit
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 4/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
1 @Rieaux: Regarding
your comment-as-
an-edit: if this gives
the files a double
extension, a second
simple batch file can
rename them. This is
drifting into a new
question, though;
please give it a try
and, if you're unable
to make it work, post
a new question here
on SU. –
user565869 Sep 30
'13 at 20:20
this automation
saved my life. :)
Thank u –
Pushker Yadav Aug
6 '15 at 18:45
1
I put this answer
together with
@plang 's answer in
a Gist with simple
instructions. See:
Script to convert
Excel File to CSV –
10GritSandpaper
By using our site, you acknowledge
Jan 6 '17that you have read and understand our Cookie Policy, Privacy Policy, and our
at 16:44
Terms of Service.
@10GritSandpaper
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 5/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
Using Excel 2007.
Script in your link
didn't work for me. –
Boris_yo Dec 18 '17
at 8:34
$xlCSV = 6
$Excel = New-Object -C
$Excel.visible = $Fals
$Excel.displayalerts=$
$WorkBook = $Excel.Wor
$Workbook.SaveAs("YOUR
$Excel.quit()
Here is a post
explaining how to use
it
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 6/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
Joel Dec 7 '09 at
8:46
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 7/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
if WScript.Arguments.C
WScript.Echo "Plea
ExcelToCsv <sheetName>
Wscript.Quit
End If
csv_format = 6
src_file = objFSO.GetA
dest_file = objFSO.Get
Dim oExcel
Set oExcel = CreateObj
Dim oBook
Set oBook = oExcel.Wor
oBook.Sheets(WScript.A
oBook.SaveAs dest_file
oBook.Close False
oExcel.Quit
Christian Lemer
plang
ScottF
Open Notepad,
By using our site, you acknowledge create
that you have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service. a file called
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 8/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
XlsToCsv.vbs and
paste this in:
WScript.Quit(0)
Function ExportExcelFi
'* Settings
Dim oExcel, oFSO,
Set oExcel = Creat
Set oFSO = CreateO
iCSV_Format = 6
'* Set Up
sExtension = oFSO.
if sExtension = ""
ExportExcelFil
Exit Function
end if
sTest = Mid(sExten
operator
if not (sTest = "
if (PromptForS
ExportExce
Exit Funct
end if
End If
sAbsoluteSource =
sAbsoluteDestinati
'* Do Work
Set oExcelFile = o
For Each oSheet in
sThisDestinati
oExcelFile.She
oExcelFile.Sav
Next
ExportExcelFileToC
Exit Function
End Function
Function PromptForSkip
if not (VarType(gS
By using our site, you acknowledgePromptForSkip
that you have read and understand our Cookie Policy, Privacy Policy, and our
Exit Function
Terms of Service. end if
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 9/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
Dim oFSO
Set oFSO = CreateO
sTitle = "Unrecogn
sResponse = MsgBo
Select Case sRespo
Case vbYes
gSkip = True
Case vbNo
gSkip = False
Case vbCancel
oExcel.Quit
WScript.Quit(1
abort (1 because wasn'
End Select
PromptForSkip = gS
Exit Function
End Function
Is there a way to do
UTF-8 Encoding? –
StuBob Sep 27 '17
at 17:54
@TharunRaja The
By using our site, you acknowledge that you
script opens have read and understand our Cookie Policy, Privacy Policy, and our
the file
Terms of Service. in excel, then does a
"save as" to CSV,
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 10/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
just like if you'd done
it by hand except it
hides it in the
background.
Because the script
itself isn't doing the
conversion, and
you're automating it,
my suggestion would
be to call a second
script on the csv files
this outputs,
message me if you
need help making
one that strips out
the first line of a file
you pass it. –
Chris Rudd Nov 26
'17 at 2:41
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 11/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
Actually, I have
never written any C#
ever. But I think I'll
give it a crack with
the Excel Data
Reader. – Joel Dec
7 '09 at 8:49
By default Alasql
converts data from
"Sheet1", but you can
change it with
parameters:
{headers:false, sheeti
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 12/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
language
constructions (see
User Manual for
examples).
There's an Excel
OLEDB data provider
1 built into Windows;
you can use this to
'query' the Excel sheet
via ADO.NET and
write the results
By using our site, you acknowledge tohave
that you a read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service. CSV file. There's a
small amount of
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 13/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
I tried ScottF VB
solution and got it to
1 work. However I
wanted to convert a
multi-tab(workbook)
excel file into a single
.csv file.
On Error Resume
Next <- To account for
a missing xls files in
my batch processing
at the top.
oBook.Application.C
olumns("A:J").Numb
erFormat =that
By using our site, you acknowledge "@"you<-
have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service. Before the SaveAs
line to make sure my
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 14/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
data is saved
formatted as text to
keep excel from
deleting leading zero's
and eliminating
commas in number
strings in my data i.e.
(1,200 to 1200). The
column range should
be adjusted to meet
your neeeds (A:J).
' https://stackoverflo
' https://gist.github.
' https://stackoverflo
'* Global Settings and
Set args = Wscript.Arg
WScript.Quit(0)
Function ConvertExcelF
if IsEmpty(srcFile
WScript.Echo "
WScript.ScriptName & "
ConvertExcelFo
Exit Function
'Wscript.Quit
End If
srcExt = objFSO.Ge
If LCase(Mid(srcEx
outputFormat =
srcDest = "csv
Else
outputFormat =
srcDest = "xls
End If
'srcFile = objFSO.
srcFile = objFSO.G
destFile = Replace
Dim oExcel
Set oExcel = Creat
Dim oBook
Set oBook = oExcel
' preserve formatt
'oBook.Application
oBook.SaveAs destF
oBook.Close False
oExcel.Quit
WScript.Echo "Conv
objFSO.GetFileName(des
End Function
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service.
answered Aug 10 '18 at 17:29
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 16/17
4/26/2019 windows - Convert XLS to CSV on command line - Stack Overflow
drzaus
15.8k 7 90 150
protected by
Community ♦ Jan 9
'12 at 1:36
Thank you for your
interest in this
question. Because it
has attracted low-
quality or spam
answers that had to be
removed, posting an
answer now requires
10 reputation on this
site (the association
bonus does not count).
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our
Terms of Service.
https://stackoverflow.com/questions/1858195/convert-xls-to-csv-on-command-line 17/17