Facing issue while saving workbook - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Facing issue while saving workbook (/thread-29102.html) |
Facing issue while saving workbook - Abhisht - Aug-18-2020 Hi all, I am a beginner in Python. I started with using a BarChart and have written below code. While executing, the code is failing with error "AttributeError: 'Cell' object has no attribute 'upper'". The source excel file used to open perfectly fine, however, after the process failure my excel is getting corrupted and couldn't be opened. If I remove and replace another source excel file, it opens fine before execution but gets corrupted post failure. I am keeping the excel in my project location which is "H:\Python\Projects\read_excel" where "read_excel" is my project. While debugging as much I could, the failure is happening while executing "workbook.save(excelname)" statement. Please help. import openpyxl as xl from openpyxl.chart import BarChart, Reference class ProcessExcel: def doexcel(self, excelname): workbook = xl.load_workbook(excelname) sheet = workbook["Sheet1"] max_row = sheet.max_row bar_chart_value_range = Reference(sheet, min_col=1, max_col=1, min_row=1, max_row=max_row) bar_chart = BarChart() bar_chart.add_data(bar_chart_value_range) insert_bar_chart_loc = sheet.cell(max_row + 1, 1) # print("insert_bar_chart_loc : ", insert_bar_chart_loc) sheet.add_chart(bar_chart, insert_bar_chart_loc) workbook.save(excelname) print("Step 8 Saved the BarChart... !") # cell = sheet.cell(max_row + 1, 1) # print(cell.value) excelname = input("Enter the Excel name- ") processexcel = ProcessExcel() processexcel.doexcel(excelname) print("Closing the program...Bye!") RE: Facing issue while saving workbook - Larz60+ - Aug-18-2020 Quote:While executing, the code is failing with error "AttributeError: 'Cell' object has no attribute 'upper'".Please, always post complete, unaltered error message in bbcode error tags. There is valuable information contained therein that usually will immediately explain why the error occurred. RE: Facing issue while saving workbook - Abhisht - Aug-19-2020 Apologies for not submitting the full error message. Below is the same.
RE: Facing issue while saving workbook - Larz60+ - Aug-19-2020 save format is: xl.writer.excel.save_workbook(workbook, filename) see: https://openpyxl.readthedocs.io/en/stable/api/openpyxl.writer.excel.html?highlight=save#openpyxl.writer.excel.save_workbook |