Created
September 7, 2011 03:02
-
-
Save nhoffman/1199652 to your computer and use it in GitHub Desktop.
Example demonstrating openpyxl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
from openpyxl.reader.excel import load_workbook | |
def getrows(sheet, cols): | |
headers = [c.value for c in sheet.rows[0] if c.value] | |
for row in sheet.rows[1:]: | |
d = dict(zip(headers, [c.value for c in row])) | |
yield dict((k2, d[k1]) for k1,k2 in cols) | |
def main(): | |
infile = sys.argv[1] | |
wb = load_workbook(infile) | |
lab = wb.get_sheet_by_name('Laboratory') | |
keep = [ | |
(u'Order #','order_id'), | |
(u'Activity Sub Type','activity_subtype'), | |
(u'PROD name','prod_name'), | |
(u'Alias','alias'), | |
(u'Legal Description','legal_desc'), | |
(u'Common Name','common_name'), | |
(u'Alternate Name (Direct Care Provider Synonym)','alt_name'), | |
(u'Alternate Name 2','alt_name2'), | |
] | |
rows = getrows(lab, keep) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment