Skip to content

Instantly share code, notes, and snippets.

@dAnjou
Last active August 29, 2015 14:04
Show Gist options
  • 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é       笑薇       [email protected]     Ms.
Océanne      漫妮       [email protected]       Fr.
Marie-josée  晧宇       [email protected]  Hr.
Örjan        香茹       [email protected]       Frau
Adèle        墨含       [email protected]       Mrs.
Eléonore     韵寒       [email protected]       Fr.
Maëly        韵含       [email protected]  Hr.
Zoé          茹怡       [email protected]         Mr.
Maëly        怡香       [email protected]          Herr
Pélagie      思宏       [email protected]      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