csv2odf is a command line tool that can convert comma seperated value (csv) files into odf documents. It can produce reports using templates in the following file formats: ods, odt, xlsx, docx, xlsm, docm, html.
csv2odf requires Python 2.6 or later. OpenOffice.org, LibreOffice or Microsoft Office programs are also needed to create templates and view output files. It can run on any operating system that Python and OpenOffice.org run on, including Linux, Mac, and Windows.
csv2odf has been tested on Linux with python 2.6, 2.7, 3.0, 3.1, and 3.2; and with OpenOffice.org 2.4, 3.0, 3.1 and 3.2. It has been tested on Windows XP with Python 3.2.
If you test with other versions of these programs, you can send your results.
We also release a deb file
Debian based Linux
Download the deb file then run:
sudo dpkg -i csv2odf_1.07-1.deb
Windows, Linux, Others
- Install Python
- unpackage csv2odf-1.08.tar.gz
- Run from command prompt by entering: python csv2odf
The csv data is merged with a template file to produce the output file. The template is a standard open document file as produced by OpenOffice.org or ooxml formats as produced by Office programs. You will need to create this file. The template can be a spreadsheet file (ods or xlsx) or document file (odt or docx).
If the template is a spreadsheet, the first row will be treated as a header row (Override with -H). The second row is repeated for every row in the csv file. The formatting in the second row cells will be applied to each data cell of the output file. In a spreadsheet template, the second row needs to contain some data: cells that may contain letters (not just numbers) should have letters; adjacent cells should not contain repeated data or else OpenOffice may merge/compress them.
If the template is a document, it must contain a table that the csv data will be inserted into. The table will be processed the same as a spreadsheet.
In the header or footer of the template, you can insert a [date] tag (the word "date" enclosed in brackets). The date tag will be replaced by the current date. The date format can be changed using format codes (see below), for example [date %Y-%m-%d] will produce a date like 2008-02-04. A date with a day offset from the current date can be created by using +n or -n, for example [date-1] would insert the date before today.
|File||Type||What it is|
|ExampleData.csv||csv||Sample csv data file|
|ExampleTemplate.ods||ods||Spreadsheet template example|
|ExampleTemplate.odt||odt||Document template example|
|ExampleTemplate.xlsx||xlsx||Document template example|
|ExampleCommands.sh||shell script||example script for running csv2odf|
|ExampleReport.ods||ods||Spreadsheet output example|
|ExampleReport.odt||odt||Document output example|
|ExampleReport.xlsx||xlsx||Document output example|
Converting to Other File Formats
The unoconv package contains utilities for converting OpenOffice files to other formats such as pdf, doc, xls etc.
Example of running odt2pdf to create a pdf file from a odt file:
If csv2odf has worked well for you, consider rating it on the project summary page.
|csv2odf Version||Release Date||Requires Python Version||Notes|
|1.10||2014-04-03||2.6-3.3+||Fixed to preserve the position of filters when options are in the template. Fixed injection of multiple lines within csv data cells.|
|1.09||2012-11-30||2.6-3.2+||Fixed bug causing unreadable output in xlsx format. Graphs pointing to the template data row are adjusted to point to inserted data range.|
|1.08||2012-01-03||2.6-3.2+||Now handles compressed template cells by expanding instead of generating an error; handles missing template rows or cells instead of generating an error; added progress indication in verbose mode for large files; some improvements in error messages.|
|1.07||2011-09-26||2.6-3.2+||Added support for html files (html, htm); Added option to support reading of the template from stdin; improved support for tab delimiters and support for tsv (tab seperated values) data file extension; modified to use Python csv module for reading data files.|
|1.06||2011-06-16||2.6-3.2+||Added ability to display line feeds in a table cell; add a comment from the command line to a document; and handle these file extensions: docm, xlsm, dotx, xltx, dotm, xltm.|
|1.05||2011-03-09||2.6-3.2+||Now supports piping of input csv data and output document.|
|1.04||2011-02-15||2.6-3.0+||Now supports Excel xlsx and Word docx formats.|
|1.03||2010-04-13||2.6-3.0+||Options can now be placed in the template file. Rewritten to use python xml.dom module, simplifying the code.|
|1.02||2009-12-26||2.6-3.0+||Now compatible with Python 3; csv file is now optional when not merging data; date styles are now preserved.|
|1.01||2009-11-08||2.5-2.6||Minor code cleanup.|