number_of_sales = 0 worksheet_list = [] worksheet_list.append(os.path.basename(input_file)) worksheet_list.append(worksheet.name) for row_index in range(1, worksheet.nrows): try: total_sales += float(str(worksheet.cell-value\ (row_index, sales_column_index))\ .strip('$').replace(',', '')) number_of_sales += 1 except: total_sales += 0. number_of_sales += 0. average_sales = '%.2f' % (total_sales / number_of_sales) worksheet_list.append(total_sales) worksheet_list.append(average_sales) list_of_totals.append(total_sales) list_of_numbers.append(float(number_of_sales)) workbook_output.append(worksheet_list) workbook_total = sum(list_of_totals) workbook_average = sum(list_of_totals) / sum(list_of_numbers) for list_element in workbook_output: list_element.append(workbook_total) list_element.append(workbook_average) all_data.extend(workbook_output) for list_index, output_list in enumerate(all_data): for element_index, element in enumerate(output_list): output_workbook.write(list_index, element_index, element) output_workbook.save(output_file)
def writeToWorkBook(ws: Workbook, price: str, condition: str, modelName: str, row: int): #strip() is used to remove white spaces so it is formatted better when added to the spreadsheet ws.write(row, 0, price.strip()) ws.write(row, 1, condition.strip()) ws.write(row, 2, modelName.strip())