HOW TO: convert text to spreadsheet data with csv2odf

Share your wisdom. Not for support questions!

Moderator: How-to Curator

HOW TO: convert text to spreadsheet data with csv2odf

Postby polaris96 » November 30th, 2013, 2:20 pm

PRECIS:

Just finished a job that required producing "dumb Access'y" reports from DB data. Found a great little app on SourceForge called csv2odf, which takes comma delimited text and spits out formatted docs.

The documentation is a tad tweaky, so here's a simplified set of steps to use the app.


I. Where To Get It and How To Install it.

Here: http://sourceforge.net/apps/mediawiki/csv2odf/index.php?title=Main_Page

This is NOT a standard repo app, but they have a deb if you're in a hurry (I was), and source code if you want to be anal.

Download the deb and use dpkg -i (as root) to install it if you're using the deb. For source, build it and... I like encap, but, by all means, checkinstall, roll a package, whatever. If you're building, you probably know what you want to do.

A tiny program like this won't break anything, so don't worry about stability or the woes of FrankenLinux.


II. Using it

1. The template must be a document ( not a OO/MSOffice template file ). Set a doc up that posseses as much formatting as you can pack in.

2. You MUST specify a template file. csv2odf will crash without one. Makes sense, after all. It's where the
formatting comes from.

2. Try to keep the template, infile, and outfile in the same directory. Paths clog up the command line.

3. The '-H' tells csv2odf that the header is INCLUDED in the .csv file as line 1. The manpage is ambiguous about that.

4. The outfile must exist. 'touch' the file if there is none. It doesn't need formatting, it just needs to be there.

5. Calling csv2odf will overwrite OUTFILE.

6. As a suggestion, you can create a spreadsheet friendly doc from the command line if you don't specify an INFILE
(csv2odf will use STDIN). I haven't tried this but it seems like a neat little flourish to bust out a table from the
command line (or a pipe from a script).

7. Formatting characters become a serious issue in number fields. Make sure \$, etc are not prepended to number
fields.

8. If you're passing dates USE the -d "${DATEFORMAT}" switch on the csv2odf call. It makes life SO much easier.
A. csv2odf -d "%m/%d/%Y" INFILE.csv TMPLT.ods OUTFILE.ods
1. the call above tells csv2odf that dates look like 12/1/2013
2. date formatting follows python standard conventions if you need to change it.

9. The sourceforge manual is much better than the manpage.
A. http://sourceforge.net/apps/mediawiki/c ... rmat_Codes

10. Make sure the INFILE is comma delimited. The program won't take whitespace, \t, :, or the other common field delimiters. fields must be comma delimited, records must be \n (newline) delimited.


III. Some Final Comments

I'm focusing on the use of this app to generate spreadsheet data, because I needed to produce spreadsheet "reports" from SQL (csv) calls. The program supports creation of tabular data in word processor { .odf .doc } form, html, and other cool formats. I see lots of utility in this, but have no current need for it.

If you experiment and find tweaks or shortcuts, please post a HowTo or else PM me so I can add your notes here (YES, I always footnote my sources).

Also Questions are welcome. I don't visit often, anymore, but I will answer questions (if I can) when I see them
for as long as the world remains. for as long as time remains. so, too, will I remain. To serve. To help. And to make my contribution. Also please visit old friends at forums.debian.net
polaris96
 
Posts: 161
Joined: July 29th, 2011, 4:45 pm

Return to HowTo

Who is online

Users browsing this forum: No registered users and 3 guests

x