Hi,
Thanks for your great work!
My website allows the user to upload CSV files. I would like to add the possibility, using the same widget, to upload Excel files. It does not work I think for an issue of encoding that I was unable to solve.
At the moment I upload csv files like so:
try:
bytesData = uploadedFile.getvalue()
encoding = encodingUTF8
s=str(bytesData,encoding)
result = StringIO(s)
except:
bytesData = uploadedFile.getvalue()
encoding = encodingISO
s=str(bytesData,encoding)
result = StringIO(s)
This works fine. I wanted to add the possibility for the user also to upload xlsx files, so I changed the file uploaded code to
uploadedFile = st.file_uploader(fileUploadLabel, type=['csv','xlsx'],accept_multiple_files=False,key="fileUploader")
and added a “read excel” bit
try:
df=pd.read_csv(dataUploaded, error_bad_lines=True, warn_bad_lines=False,sep=chosenFileSeparator)
except:
try:
df = pd.read_excel(dataUploaded)
except:
df=pd.DataFrame()
I get this error (if I take out the “try” or course)
The identical file just in CSV instead of Excel gets read with not problem.
Thanks so much for your help!
Fabio

not just the file name ?