Python Forum
Openpyxl.InvalidfileException
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Openpyxl.InvalidfileException
#1
Hi,

I am fairly new, one day old and working on Excel files. I have played around with input functions in console and trying to have users input their file names for selection and saving. It all works well when the name is spelled correctly but I want to catch the exception for wrong name. I have tried reading through openpyxl but the syntax and formatting is eluding me.

wb = xl.load_workbook(input("Select File: "))
sheet = wb["Sheet1"]
if the wrong name is typed at input screen like xxx.xlcfs (not .xlsx as required) the following error comes up

Error:
raise InvalidFileException(msg) openpyxl.utils.exceptions.InvalidFileException: openpyxl does not support file format, please check you can open it with Excel first. Supported formats are: .xlsx,.xlsm,.xltx,.xltm
I have tried it like normal Pyhton
    try:
        corrected_price = cell.value * float(input("Enter Value: " +""))
    except ValueError:
        print("Enter 0 before decimal")
    break
but was not working..
Reply
#2
Where it says ValueError, you would want InvalidFileException instead.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020