Convert .xls and .csv to tab-delimited .txt

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sixty_watt_shaman
Posts: 1
Joined: 23 Apr 2009 02:12

Convert .xls and .csv to tab-delimited .txt

#1 Post by sixty_watt_shaman » 23 Apr 2009 02:19

Hi,

I have a question. Is it possible to convert a .xls-file and a .csv-file into a tab-delimited .txt-file with a batch-file. If so, how can this be done?

Thanks in advance.

Bram.

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Convert .xls and .csv to tab-delimited .txt

#2 Post by Samir » 17 Jun 2014 08:25

I hate to bump an older thread, but is there an answer to this? I'm wondering the exact same thing.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Convert .xls and .csv to tab-delimited .txt

#3 Post by Squashman » 17 Jun 2014 10:10

Not with batch.
Working with excel files requires Excel to be installed. Vbscript and Powershell are the only scripting languages that I know of that can use excel as an object to do this.

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Convert .xls and .csv to tab-delimited .txt

#4 Post by ShadowThief » 17 Jun 2014 17:53

You can't edit .xls files, but .csv files are just text files where values are separated by commas, so you can use something like findrepl.bat to just replace all of the commas with tabs.

On a related note, you can edit .xlsx files since they're just an archive of .xml files, but the whole thing is so ludicrously complicated and interconnected that it's really not a good idea to do so.

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Convert .xls and .csv to tab-delimited .txt

#5 Post by dbenham » 17 Jun 2014 20:28

ShadowThief wrote:... but .csv files are just text files where values are separated by commas, so you can use something like findrepl.bat to just replace all of the commas with tabs.

Potentially it is not that simple because CSV allows both comma and newlines literals within values if they are quoted. And quote literals within a quoted value are escaped as two quotes.


Dave Benham

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Convert .xls and .csv to tab-delimited .txt

#6 Post by ShadowThief » 17 Jun 2014 22:24

dbenham wrote:
ShadowThief wrote:... but .csv files are just text files where values are separated by commas, so you can use something like findrepl.bat to just replace all of the commas with tabs.

Potentially it is not that simple because CSV allows both comma and newlines literals within values if they are quoted. And quote literals within a quoted value are escaped as two quotes.


Dave Benham

You could first delimit by double quotes and then only convert the commas in the odd-numbered tokens

carlsomo
Posts: 91
Joined: 02 Oct 2012 17:21

Re: Convert .xls and .csv to tab-delimited .txt

#7 Post by carlsomo » 24 Jun 2014 22:02

Hybrid batch/jscript:

viewtopic.php?f=3&t=4628&p=33475#p33475

Last post
XLS2CSV "D:\XLpath\my file.xlsx" "D:\CSVfiles\my file.csv" /S=/t

Converts xlsx to tab delimited txt file. I don't think there is a pure batch solution.

Post Reply