spreadsheet

Read and write spreadsheets from and to CSV files in a lazy way

http://www.haskell.org/haskellwiki/Spreadsheet

Version on this page:0.1.3.5
LTS Haskell 22.13:0.1.3.10
Stackage Nightly 2024-03-14:0.1.3.10
Latest on Hackage:0.1.3.10

See all snapshots spreadsheet appears in

BSD-3-Clause licensed and maintained by Henning Thielemann
This version can be pinned in stack with:spreadsheet-0.1.3.5@sha256:1b018fdc5ffcfe6edaafa5760690e4243e7fc969439798e691c776bf8efd7d8d,2416

Module documentation for 0.1.3.5

Used by 2 packages in nightly-2017-10-28(full list with versions):

Example: csvreplace

If you build the package with the Cabal flag -fbuildExamples then the program csvreplace will be built. It allows you to replace placeholders in a template file according to the columns of a CSV file. E.g. given a file template.txt with content

Name: FIRSTNAME SURNAME
Born: BIRTH

and names.csv with content

"FIRSTNAME","SURNAME",BIRTH
"Georg","Cantor",1845
"Haskell","Curry",1900
"Ada","Lovelace",1815

the call

csvreplace template.txt <names.csv

produces the output

Name: Georg Cantor
Born: 1845
Name: Haskell Curry
Born: 1900
Name: Ada Lovelace
Born: 1815

You may also generate one file per CSV row in the following manner:

csvreplace --multifile=FIRSTNAME-SURNAME.txt template.txt <names.csv

Character Encoding

For simple replacement of parts of the text we would not need to decode the input texts and thus we would not need to know the used encoding scheme. Essentially, we would only require that both CSV and template file employ the same character encoding.

However, it is not as simple as that. We need to decode the structure of the CSV file. In multi-file mode we also need to generate proper file names. Both requirements force us to decode both CSV and template file. For the de- and encoding we use the default locale encoding.

If you want essentially a byte-by-byte replacement and you assert that all files are in the same encoding where the commas and quotation marks are compatible with ASCII then you can set the encoding locally to a complete 8-bit encoding like latin1 as in:

LANG=de_DE csvreplace --multifile=FIRSTNAME-SURNAME.txt template.txt <names.csv