Solved need batch file to convert txt file to xls

January 11, 2015 at 01:18:01
Specs: Windows 7
comma separated txt file to convert into xls format

See More: need batch file to convert txt file to xls

Report •


✔ Best Answer
January 11, 2015 at 19:36:34
You will have to use VBS or some other means to access the Excel object. Here's a very rudimentary VBS:

'---------------- begin vbscript "csv2xls.VBS"
Set xl = WScript.CreateObject("Excel.application")

xl.Visible = TRUE
xl.displayalerts=False
'paths must be FULLY QUALIFIED, esp. for INPUT files.

set book=xl.workbooks
source=wscript.arguments(0)
'wscript.echo "trying to convert: ["+source+"]"
dest=wscript.arguments(1)
'wscript.echo "output going to: "+dest+".xls"
set f=book.open (source)
f.saveas dest+".xls",35
xl.quit
'====== end vbscript

example call from batch:
cscript csv2xls c:\subd1\subd2\any.csv c:\converted\any

my familiarity with the excel object is "slim to none". You might want to do more research on your own to make things work like you want.
Batch not tested, vbscript tested.

message edited by nbrane



#1
January 11, 2015 at 07:49:07
You should be able to just open the file with Excel.

See here:

https://support.office.com/en-nz/ar...

Also, for future reference, Excel questions are best asked in the Office Software Forum.

MIKE

http://www.skeptic.com/


Report •

#2
January 11, 2015 at 10:21:18
But I need to convert 100s of files to convert

Report •

#3
January 11, 2015 at 17:15:25
There is software out there that will do what you want for a price,
several offer free trials, but I don't know for how long or if they
only allow a certain number of file to be converted.

Here is a site that has a Macro, you could see how it works:

http://www.pcreview.co.uk/forums/ba...

Sorry, but my Macro skills are just above nill,
so I can offer only very limited assistance.

MIKE

http://www.skeptic.com/


Report •

Related Solutions

#4
January 11, 2015 at 19:36:34
✔ Best Answer
You will have to use VBS or some other means to access the Excel object. Here's a very rudimentary VBS:

'---------------- begin vbscript "csv2xls.VBS"
Set xl = WScript.CreateObject("Excel.application")

xl.Visible = TRUE
xl.displayalerts=False
'paths must be FULLY QUALIFIED, esp. for INPUT files.

set book=xl.workbooks
source=wscript.arguments(0)
'wscript.echo "trying to convert: ["+source+"]"
dest=wscript.arguments(1)
'wscript.echo "output going to: "+dest+".xls"
set f=book.open (source)
f.saveas dest+".xls",35
xl.quit
'====== end vbscript

example call from batch:
cscript csv2xls c:\subd1\subd2\any.csv c:\converted\any

my familiarity with the excel object is "slim to none". You might want to do more research on your own to make things work like you want.
Batch not tested, vbscript tested.

message edited by nbrane


Report •

Ask Question