Sep-17-2019, 05:04 PM
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.
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 Pyhtontry: corrected_price = cell.value * float(input("Enter Value: " +"")) except ValueError: print("Enter 0 before decimal") breakbut was not working..