Skip to content

Instantly share code, notes, and snippets.

@dAnjou
Last active August 29, 2015 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dAnjou/83642b547b7a797a6218 to your computer and use it in GitHub Desktop.
Save dAnjou/83642b547b7a797a6218 to your computer and use it in GitHub Desktop.
Testing import of Excel files

Usage

Run like this for example:

python2 excel_test.py | column -t

Output should look like this:

first_name   last_name  email                     gender
Salomé       笑薇       rjenkins@linktype.com     Ms.
Océanne      漫妮       gandrews@trudoo.gov       Fr.
Marie-josée  晧宇       egutierrez@bubblemix.edu  Hr.
Örjan        香茹       gfrazier@dynava.edu       Frau
Adèle        墨含       rjenkins@talane.org       Mrs.
Eléonore     韵寒       revans@edgeclub.net       Fr.
Maëly        韵含       mcunningham@buzzster.com  Hr.
Zoé          茹怡       vlynch@voonyx.org         Mr.
Maëly        怡香       hrogers@muxo.mil          Herr
Pélagie      思宏       hgibson@devcast.info      Fr.
#!/usr/bin/env python
import sys
import codecs
# needed to be able to pipe output
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
from xlrd import open_workbook
book = open_workbook('test_data.xls')
sheet = book.sheet_by_index(0)
for row in range(sheet.nrows):
line = [sheet.cell(row,col).value for col in range(4)]
print " ".join(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment