i newbie python. basically, want write program read column d & e excel file, , calculate total incoming , outgoing duration.
which python module used read excel files , how process data inside it?
excel file:
d e incoming 18 outgoing 99 incoming 20 outgoing 59 incoming 30 incoming 40
there couple of options depending on version of excel using.
openpyxl - used reading excel 2010 files (ie: .xlsx)
xlrd - used reading older excel files (ie: .xls)
i have used xlrd, below
** note ** code not tested
import xlrd current_row = 0 sheet_num = 1 input_total = 0 output_total = 0 # path file want extract data src = r'c:\temp\excel sheet.xls' book = xlrd.open_workbook(src) # select sheet data resids in work_sheet = book.sheet_by_index(sheet_num) # total number of rows num_rows = work_sheet.nrows - 1 while current_row < num_rows: row_header = work_sheet.cell_value(current_row, 4) if row_header == 'output': output_total += work_sheet.cell_value(current_row, 5) elif row_header == 'input': input_total += work_sheet.cell_value(current_row, 5) print output_total print input_total
Comments
Post a Comment