tclcsv

tclcsv (by APN) is a binary extension for reading and writing CSV format files. The parsing code is based on the Python / pandas CSV parser.

2018-03-12: Version 2.3 released. Changes since 2.2

  • ability to write CSV files
  • much faster parsing performance

Compared to the Tcllib CSV module:

  • Tcllib CSV is pure Tcl which has obvious advantages in portability.
  • On the other hand, tclcsv, being binary, is much faster. It also supports more flexibility in terms of CSV formats and includes a Tk dialog to configure, preview and interactively select the appropriate CSV dialect (similar to the CSV import dialog in Excel).

MHo 2020-06-30: It is difficult to create correct CSVs for Excel: If one enters, within Excel, a manual line break within a cell and then saves a file, that line break is stored internally as 0x0a, compared to 0x0d0a for the line endings of the complete row. Ok. To create such a CSV one have to separate values in one cell with 0x0a. But as the data is written out, Tcl automatically translates this to 0x0d0a, on windows. My trick is to fconfigure the channel to lf (so nothing is translated), and in addition calling csv_write with -terminator \x0D\x0A. This produces what I want... LibreOffice, instead, always treats CSVs as expected, even if cells contain 0x0d0a (if they are enclosed in double quotes etc.). I stumbled upon the same problems in using tcllibs csv module.