0

I was trying to open xlsx file using openpyxl version 3.10. Here's my code:

path = (r'C:\Users\karol\OneDrive\Pulpit\OASIS\*.xlsx')
list_of_files = glob.glob(path)
latest_file = max(list_of_files, key=os.path.getctime)
excel = openpyxl.load_workbook(latest_file)

I got TypeError: expected <class 'openpyxl.worksheet.cell_range.MultiCellRange'>
because of conditional formatting.

I did some digging and found this: Can't load workbook with openpyxl: during handling of the above exception, another exception occurred So, I downgraded openpyxl to version 2.4.11 and now I get ValueError: {0} is not a valid coordinate or range ... but I did not specify any coordinates or range? I'm confused, just want to open xlsx file HELP

  • It appears there is some issue with the setup of the conditional formatting in the earliest xlsx file in the directory. How was the CF applied to the sheet? If CF is removed does the file load? – moken Jan 21 '23 at 23:02
  • I removed CF from the excel file and still get this ValueError: {0} is not a valid coordinate or range :( – Karolina Lęcznar Jan 23 '23 at 12:05
  • I checked different xlsx file and it loads so it is the other xlsx file issue... – Karolina Lęcznar Jan 23 '23 at 12:16
  • After upgrading openpyxl I get TypeError: expected – Karolina Lęcznar Jan 23 '23 at 12:18
  • So you have updated Openpyxl back to the latest release and removed the Conditional formatting on the sheet, but the error still occurs because of conditional formatting? – moken Jan 23 '23 at 12:35
  • Yes, there are no rules on the sheet. I have removed CF, saved the file, closed it, ran the program and still get this error. – Karolina Lęcznar Jan 23 '23 at 12:42
  • As you've seen your code is fine and would work OK. I've seen issues where using LibreOffice has messed up CF and caused this error, however if the workbook no longer has any CF applied to sheets then seems it may be something else. Might need to raise an issue with devs since obviously we cannot debug your Excel file – moken Jan 23 '23 at 12:54
  • Ok, thank you. I will try on different computer. – Karolina Lęcznar Jan 23 '23 at 12:57
  • Just to confirm the file opens up on a different computer. There must have been an issue with my Office package. – Karolina Lęcznar Jan 23 '23 at 18:27
  • 1
    If you thing there is a problem with the library then you should submit a bug report together with a sample file. – Charlie Clark Jan 24 '23 at 09:54

0 Answers0