Converting XLS to CSV from Ubuntu command line?

Soldato
Joined
9 May 2005
Posts
7,400
Location
Berkshire
Anyone got any advice on how I can do this? I have a report automatically saving as an xls daily, the nature of the reporting software means that I can't save it as anything other than xls. What I'm looking to do, via clever script or simple application, is convert said xls to a csv from the command line so it can be imported into a mysql database.

So anyone got any ideas? I've got an app called xls2csv but I can't get it to produce a file, regardless of what operators I use :(
 
You might be able to use OpenOffice or its libraries to do it, e.g. write a macro in OpenoOfice Calc and then call that from the command line?
 
Is it just the extension that is different?

Have you tried opening the xls file in VI or similar? i.e. what is the file structure - could use something like sed/awk to restructure it ?
 
Is it just the extension that is different?

Have you tried opening the xls file in VI or similar? i.e. what is the file structure - could use something like sed/awk to restructure it ?

Don't do this, lol aftershxck, get a load of xls files put them in a directory and do
cat *.xls

and report back with your findings
 
I thought the obvious thing to do would be to use Excel under Windows to export particular worksheets as CSV using VBA. Using Linux to fix a Windows problem is just a retarded approach tbh.

BTW the idea of using a text editor to analyse a file's structure and then parse it programmatically isnt actually that bad an approach, except that these sort of files tend to be full of binary MS crap.
 
Can you not just open it in openoffice and convert it? or is it something you want to do automatically?
 
Don't do this, lol aftershxck, get a load of xls files put them in a directory and do
cat *.xls

and report back with your findings


What? I thought his question was about changing one files contents to something else, not adding the contents of multiple files already in the correct format up.
 
Yes my point (as Whiskas) points out that you'll never in a month of Sundays manage to write a program that'll parse Xls files they are full of binary nonsense, my point is doing cat *.xls will show you exactly the problem.

you might be able to use something like gnumeric or something that can read xls files an has a batch mode
 
OK, in that case it won't work then :p, I was just under the impression the file may have been exported as a csv of some type with just a different extension :)
 
Heh quite the discussion I've started here :D.

I thought the obvious thing to do would be to use Excel under Windows to export particular worksheets as CSV using VBA. Using Linux to fix a Windows problem is just a retarded approach tbh.


Perhaps I could have been clearer in my original post but this wouldn't work. The reporting agent runs on a server that, aside from scheduling, I have no interaction with. So no running of VBA scripts against Excel. That said it's since come to light that the reporting software can produce a tab delimited text file. So I just need to brush up on mysql so I can import that from the command line.

Also I don't believe the open office solutions would have worked as I'm running Ubuntu server.
 
Last edited:
Back
Top Bottom