Skip to content

Instantly share code, notes, and snippets.

@ghing
Created October 5, 2014 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghing/f99a2cdef7df97efa1e9 to your computer and use it in GitHub Desktop.
Save ghing/f99a2cdef7df97efa1e9 to your computer and use it in GitHub Desktop.
Grab a row from an Excel spreadsheet and output it. Useful for extracting test cases for OpenElections loaders from source results.
#!/usr/bin/env python
import argparse
import xlrd
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Extract rows from an Excel '
'file.')
parser.add_argument('filename', nargs=1,
help='Excel file to load row from')
parser.add_argument('rows', nargs='+',
help='Row numbers to extract')
args = parser.parse_args()
sheet = xlrd.open_workbook(args.filename[0]).sheets()[0]
for row_index in args.rows:
row_index = int(row_index)
print(sheet.row_values(row_index))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment