Main_Page

Anonymous Alexey Ivanov Larry Jordan
Attachments
Insert2.png (32964 bytes)

csv2odf Project

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 is useful for creating reports from databases and other data sources that produce csv files. csv2odf can be combined with cron and shell scripts to automatically generate business reports.

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 Microsoft Office.

Requirements

csv2odf requires Python 2.6 or later. OpenOffice.org, LibreOffice or Microsoft Office 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.4; and with OpenOffice.org 2.4, 3.0, 3.1 and 3.2. It has been tested on Windows XP with Python 2.7 and 3.2-3.4.

If you test with other versions of these programs, you can send your results.

Download

Download Latest tar.gz

Browse All Files

We also release a deb file

Installation

Debian based Linux

Download the deb file then run:

 sudo dpkg -i csv2odf_1.07-1.deb

Windows, Linux, Others

  1. Install Python
  2. unpackage csv2odf-1.08.tar.gz
  3. Run from command prompt by entering: python csv2odf

Using cvs2odf

Manual

You can read the [Manual] online. It's also available in some other languages.

Tutorials

Usage Summary

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 [csv2odf-date] tag (csv2odf-date enclosed in square brackets). The date tag will be replaced by the current date. The date format can be changed using format codes (see below), for example [csv2odf-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 [cav2odf-date-1] would insert the date before today.

Example Files

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 Spreadsheet 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 Spreadsheet 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:

  odt2pdf report.odt

Running Faster

Pypy is a alternative Python interpreter that can run csv2odf about twice as fast. The speed improvement is more noticable with large csv files.

Bugs

Report a Bug

Contact the developer

If csv2odf has worked well for you, consider rating it on the project summary page.

Version History

csv2odf Version Release Date Requires Python Version Notes
2.01 2014-09-09 2.6-3.4+ Additional decrease in memory. Fixed xml output crash in windows.
2.00 2014-07-31 2.6-3.4+ Can now process large data file serially, using less memory. The date tag changed to [csv2odf-date].
1.11 2014-05-20 2.6-3.3+ Bugfix to handle blank cells more cleanly.
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.
1.00 2009-10-06 2.5-2.6 First release.

SourceForge Project Summary

SourceForge Developer Page

Contact the developer

ohloh


Project Admin, [Wiki_Admin]


Related

Wiki: Database_to_Document
Wiki: Manual
Wiki: Program_Options_by_Example
Wiki: Quick_Template_Tutorial
Wiki: Wiki_Admin