Mar-03-2024, 12:00 AM
I am at wit's end trying to debug this program. Problem is, it does not update my Excel file.
Its pointing to correct Excel. If my rename Excel, it throws an error.
Same for the sheet. I tried renaming sheet and it throws an error.
I have tried debugging and fetching the data and printing it. It correctly prints the data, so the data is there.
I have tried closing the file and Excel application itself, while python program is running.
I have tried updating Excel to random values and fetching them. It works correctly.
So, I have isolated this problem. I can fetch the values. Write to a cell and fetch it in python. But the value does not reflect when I open the Excel file.
Below is how I have opened the file in a setup function.


def GetExistingOrders(self, list, sheet): # todo define function # load from list to sheet for row_idx, row_data in enumerate(list, start=2): for col_idx, value in enumerate(row_data, start=1): sheet.cell(row=row_idx, column=col_idx, value=value) sheet['A8'] = 'Test3' # self.wb['Extract'] s1 = self.wb.worksheets[0] s1['A11'] = 'Test11' s2 = self.wb['data'] s2.cell(row=6, column=1, value='Test3') print(f"Inside s1.A5 = {s1['A5'].value}") print(f"Inside s1.A6 = {s1['A6'].value}") print(f"Inside sheet.A8 = {sheet['A8'].value}") print(f"Inside s1.A9 = {s1['A9'].value}") # I had entered this cell through Excel which prints correctly in python print(f"Inside s1.A11 = {s1['A11'].value}") print(f"Inside sheet.A2 = {sheet['A2'].value}") # prints correctly from the above loop returnThis is how I am calling the function, and the value is also returned from the function and prints outside.
evar.GetExistingOrders(api.open_orders, sheet) print(f"In main: "+str(sheet['A5'].value)) # This also prints correctly outside the functionSo far, I have ruled out:
Its pointing to correct Excel. If my rename Excel, it throws an error.
Same for the sheet. I tried renaming sheet and it throws an error.
I have tried debugging and fetching the data and printing it. It correctly prints the data, so the data is there.
I have tried closing the file and Excel application itself, while python program is running.
I have tried updating Excel to random values and fetching them. It works correctly.
So, I have isolated this problem. I can fetch the values. Write to a cell and fetch it in python. But the value does not reflect when I open the Excel file.
Below is how I have opened the file in a setup function.
self.wb = openpyxl.load_workbook(self.filepath+self.filename) sheet = self.wb[sheetname]