Popular recipes tagged "csv" but not "excel"http://code.activestate.com/recipes/tags/csv-excel/2017-01-07T12:21:39-08:00ActiveState Code Recipes[xtopdf] Publish Delimiter-Separated Values (DSV data) to PDF (Python) 2016-12-17T19:08:33-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580736-xtopdf-publish-delimiter-separated-values-dsv-data/ <p style="color: grey"> Python recipe 580736 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/tsv/">tsv</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to publish delimiter-separated values (a commonly used tabular data format) to PDF, using the xtopdf toolkit for PDF creation. It lets the user specify the delimiter via one of two command-line options - an ASCII code or an ASCII character. As Unix filters tend to do, it can operate either on standard input or on input filenames given as command-line arguments. In the case of multiple inputs via files, each input goes to a separate PDF output file.</p> Read CSV with D and write it to PDF with Python (Python) 2016-10-26T17:49:00-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580710-read-csv-with-d-and-write-it-to-pdf-with-python/ <p style="color: grey"> Python recipe 580710 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/formats/">formats</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to read data from a CSV file with a D program and write that data to a PDF file with a Python program - all in a single command-line invocation (after writing the individual programs, of course).</p> <p>It requires the xtopdf toolkit, which you can get from:</p> <p><a href="https://bitbucket.org/vasudevram/xtopdf" rel="nofollow">https://bitbucket.org/vasudevram/xtopdf</a></p> <p>Instructions for installing xtopdf:</p> <p><a href="http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html" rel="nofollow">http://jugad2.blogspot.in/2012/07/guide-to-installing-and-using-xtopdf.html</a></p> <p>xtopdf in turn requires the open source version of the ReportLab toolkit, which you can get from:</p> <p><a href="http://www.reportlab.com/ftp" rel="nofollow">http://www.reportlab.com/ftp</a> (<a href="http://www.reportlab.com/ftp/reportlab-1.21.1.tar.gz%29" rel="nofollow">http://www.reportlab.com/ftp/reportlab-1.21.1.tar.gz)</a></p> <p>It also requires the DMD compiler to compile the D program - this was the version used:</p> <p>DMD32 D Compiler v2.071.2</p> CSV export / import of PDF bookmarks (table of contents) (Python) 2017-01-07T12:21:39-08:00Jorj X. McKiehttp://code.activestate.com/recipes/users/4193772/http://code.activestate.com/recipes/580743-csv-export-import-of-pdf-bookmarks-table-of-conten/ <p style="color: grey"> Python recipe 580743 by <a href="/recipes/users/4193772/">Jorj X. McKie</a> (<a href="/recipes/tags/bookmarks/">bookmarks</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/pdf/">pdf</a>). </p> <p>Two little utilities to export or import a PDF's table of contents from / to a standard CSV file. Typical usecase would be:</p> <ol> <li>export TOC to CSV file</li> <li>edit CSV file</li> <li>import TOC from CSV file</li> </ol> Convert CSV to XML (Python) 2010-10-11T06:20:19-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577423-convert-csv-to-xml/ <p style="color: grey"> Python recipe 577423 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>Convert CSV to XML.</p> CSV to Flat File Converter (Python) 2015-08-02T17:31:59-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/579091-csv-to-flat-file-converter/ <p style="color: grey"> Python recipe 579091 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>Converts a CSV file to a flat file (table).</p> Convert CSV to XML (Python) 2012-12-17T16:16:04-08:00Tom Wissinghttp://code.activestate.com/recipes/users/4184629/http://code.activestate.com/recipes/578384-convert-csv-to-xml/ <p style="color: grey"> Python recipe 578384 by <a href="/recipes/users/4184629/">Tom Wissing</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>Convert CSV to XML.</p> Ordered CSV read / write with colum based lookup (Python) 2012-03-02T12:45:29-08:00Gregory Nicholashttp://code.activestate.com/recipes/users/4180332/http://code.activestate.com/recipes/578059-ordered-csv-read-write-with-colum-based-lookup/ <p style="color: grey"> Python recipe 578059 by <a href="/recipes/users/4180332/">Gregory Nicholas</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/lookup/">lookup</a>). </p> <p>This allows you to hold on to your csv in a dict form, do lookups and modifications, and also write it in a preserved order. You can also change which column you want to be your lookup column (making sure that there is a unique id for every row of that column. In my example of usage, it assumes that both classes are contained withing the same file named 'CustomDictReader.py'</p> Ordered CSV read / write with colum based lookup (Python) 2011-12-24T19:44:13-08:00__nerohttp://code.activestate.com/recipes/users/4177968/http://code.activestate.com/recipes/577996-ordered-csv-read-write-with-colum-based-lookup/ <p style="color: grey"> Python recipe 577996 by <a href="/recipes/users/4177968/">__nero</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/lookup/">lookup</a>). </p> <p>This allows you to hold on to your csv in a dict form, do lookups and modifications, and also write it in a preserved order. You can also change which column you want to be your lookup column (making sure that there is a unique id for every row of that column. In my example of usage, it assumes that both classes are contained withing the same file named 'CustomDictReader.py'</p> Export Oracle Database to CSV using cx_Oracle (Python) 2010-07-11T19:49:42-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577304-export-oracle-database-to-csv-using-cx_oracle/ <p style="color: grey"> Python recipe 577304 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/database/">database</a>). </p> <p>Creates a CSV file for each table in the target Oracle database.</p> Correctly reading CSV files in arbitrary encodings (Python) 2011-07-25T07:29:08-07:00Devin Jeanpierrehttp://code.activestate.com/recipes/users/4178508/http://code.activestate.com/recipes/577778-correctly-reading-csv-files-in-arbitrary-encodings/ <p style="color: grey"> Python recipe 577778 by <a href="/recipes/users/4178508/">Devin Jeanpierre</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/unicode/">unicode</a>). Revision 4. </p> <p>Recipe for using unicode files (i.e. files opened with <code>codecs.open</code>) with the csv module.</p> Populate SQL tables from CSV data files (Python) 2011-02-02T21:21:49-08:00James Millshttp://code.activestate.com/recipes/users/4167757/http://code.activestate.com/recipes/577559-populate-sql-tables-from-csv-data-files/ <p style="color: grey"> Python recipe 577559 by <a href="/recipes/users/4167757/">James Mills</a> (<a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sql/">sql</a>). </p> <p>Just a quick recipe I developed a few years ago that I thought might be useful to others. Basically it takes as input a data file with comma separated values (CSV) and translates this into a series of SQL "INSERT" statements allowing you to then feed this into MySQL, SQLite, or any other database.</p> <p>Example Usage:</p> <p>$ cat cars.csv Year,Make,Model,Length 1997,Ford,E350,2.34 2000,Mercury,Cougar,2.38</p> <p>$ sqlite3 cars.db "CREATE TABLE cars (Year, Make, Model, Length)"</p> <p>$ ./csv2sql.py cars.csv | sqlite3 cars.db </p> <p>$ sqlite3 cars.db "SELECT * FROM cars" 1997|Ford|E350|2.34 2000|Mercury|Cougar|2.38</p> <p>Enjoy! Feedback welcome!</p> <p>cheers James Mills / prologic</p> Filtering CSV data by fields (cut for csv) (Python) 2011-02-02T21:39:45-08:00James Millshttp://code.activestate.com/recipes/users/4167757/http://code.activestate.com/recipes/577560-filtering-csv-data-by-fields-cut-for-csv/ <p style="color: grey"> Python recipe 577560 by <a href="/recipes/users/4167757/">James Mills</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/cut/">cut</a>, <a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/filter/">filter</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Ever wanted to take a CSV file as input, cut it up and only extract the fields that you want ?</p> <p>Here's how!</p> <p>$ cat cars.csv Year,Make,Model,Length 1997,Ford,E350,2.34 2000,Mercury,Cougar,2.38</p> <p>$ csvcut.py -f 0 -f -1 - &lt; cars.csv Year,Length 1997,2.34 2000,2.38</p> <p>--JamesMills (prologic)</p> Query CSV file (Python) 2010-10-12T00:08:22-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577419-query-csv-file/ <p style="color: grey"> Python recipe 577419 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/database/">database</a>). Revision 4. </p> <p>The user can define a query expression for (almost) any CSV file. (The first row assumed to contain column headers.) Then the code outputs all data rows matching to the given query expression.</p> Cheetah template processor for CSV and XML data (Python) 2010-05-21T10:00:14-07:00Raphaël Jolivethttp://code.activestate.com/recipes/users/4135673/http://code.activestate.com/recipes/577234-cheetah-template-processor-for-csv-and-xml-data/ <p style="color: grey"> Python recipe 577234 by <a href="/recipes/users/4135673/">Raphaël Jolivet</a> (<a href="/recipes/tags/cheetah/">cheetah</a>, <a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/merge/">merge</a>, <a href="/recipes/tags/populate/">populate</a>, <a href="/recipes/tags/template/">template</a>, <a href="/recipes/tags/xml/">xml</a>). </p> <p>This script allows to populate Cheetah text templates (<a href="http://www.cheetahtemplate.org/" rel="nofollow">http://www.cheetahtemplate.org/</a>) with XML or CSV input data.</p> <p>This is useful in my day2day work, where I often need to quickly generate bunch of files based on a templates and data.</p> <p>Cheetah template are very easy to write and understand, and I find it easy to use with CSV or XML data.</p> Oracle Database String Search using cx_Oracle (Python) 2013-07-26T21:58:30-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577302-oracle-database-string-search-using-cx_oracle/ <p style="color: grey"> Python recipe 577302 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/database/">database</a>). Revision 2. </p> <p>Finds all database rows in all tables that contain a given search string and outputs a CSV file for each table that has any match.</p> Oracle Database Regex Search using cx_Oracle (Python) 2010-07-11T19:39:21-07:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/577303-oracle-database-regex-search-using-cx_oracle/ <p style="color: grey"> Python recipe 577303 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/csv/">csv</a>, <a href="/recipes/tags/database/">database</a>). </p> <p>Finds all database rows in all tables that contain any column which matches to given regex and outputs a CSV file for each table containing matches.</p> Compare CSV Inventory files (Python) 2009-08-18T14:14:04-07:00Mike Burkehttp://code.activestate.com/recipes/users/4171487/http://code.activestate.com/recipes/576885-compare-csv-inventory-files/ <p style="color: grey"> Python recipe 576885 by <a href="/recipes/users/4171487/">Mike Burke</a> (<a href="/recipes/tags/compare/">compare</a>, <a href="/recipes/tags/csv/">csv</a>). </p> <p>Program will compare two CSV files using a unique ID field and save any changes to ID as well as two secondary fields (qty &amp; price). The code was written to pick out updates from supplier inventory files.</p>