Skip to content
Berteh edited this page Aug 23, 2019 · 3 revisions

Scribus Generator needs your data to be provided as CSV. Many alternative ways to get good CSV exist. This pages dicusses a few, feel free to contribute !

Note this CSV file should preferably be encoded in UTF-8, to ensure funny characters, arrows and other emoticons work just fine.

Spreadsheet

LibreOffice and OpenOffice provide out of the box a great support for CSV. Simply open the spreadsheet tab you want to export (CSV can only export 1 tab at a time), and click File > Save as >, and change output format to text CSV.

So does Google Spreadsheet: pick File > Download As > Comma separated values (CSV).

Excel supports exporting to a variant of CSV (called TSV), but is not good at exporting UTF-8 encoded files. Consider using the free CSVio add-in to export easier your data to proper UTF-8 csv files: http://www.csvio.net/

Strange line jump / data lost

If your data includes linefeeds kindly quote your data fields. In the save as csv settings, telling LibreOffice/OpenOffice to put all fields in quotes fixes some clipped data issues.

Integrating multiple data sources

Many tools already exist and do a good job at integrating data sources.

Data integration (ETL) tools such as https://skyvia.com/ or https://www.singer.io provide many bridges with existing online services, file formats and data bases.

A more manual spreadsheet approach to import and filter works too, for instance with Power Queries in Excel or similar data sources in OpenOffice, including Spreadsheet, CSV, Mozilla Adress Book and even any simple XML file for the later.

When the data is clean (can be turned into a scheduled job): export to CSV and use a document generation tool, like ScribusGenerator ;)

Cleaning messy data

If your data is really messy, then you may be more interested in data (integration and) cleaning tools, such as OpenRefine, that directly integrates data sources such as TSV, CSV, Text file with custom separators or columns split by fixed width, XML, RDF triples, JSON, Google Spreadsheets and Google Fusion Tables, a.o.

Export from a standard database

To use data from a database instead a (manual) spreadsheet you can simply export the related query result to a CSV file. Some examples below for common database engines:

Mysql:

mysql --delimiter="," -u myuser -p mydb -e "select f1,f2 from mytable" > /tmp/mydata.txt

or

mysql  -u myuser -p  mydatabase -e 
"select field1 , field2 FROM mytable INTO OUTFILE 
'/tmp/myfilename.csv' FIELDS TERMINATED BY ','
ENCLOSED BY '\"' LINES TERMINATED BY '\n' "

More over INTO OUTFILE at http://dev.mysql.com/doc/refman/5.1/en/select.html

Postgresql

Locally on the server you can use ''COPY'', as per http://www.postgresqltutorial.com/export-postgresql-table-to-csv-file/:

COPY persons(email)
TO 'C:\tmp\persons_email_db.csv' DELIMITER ',' CSV;

In case you have the access to a remote PostgreSQL database server, but you don’t have sufficient privileges to write to a file on it, you can use the PostgreSQL built-in command \copy.

A third option is to run pgsql client from the commande line, toggle unaligned output with the \a switch, activate a comma as a separator with \f ,. Send output to a file with \o myfile.csv, then query your database.

Sqlite3

You can use sqlite3 -csv in command line or .mode csv in sqlite's interactive shell