In my case, I couldn't remove filters from the project. Instead of manually removing filters from files, I was expecting a "valueError"
exception, then opening the file with xlrd
and writing to a temporary directory in .csv
format, then opening with pandas as csv
try:
excel_data_df = pd.read_excel()
except ValueError:
with tempfile.TemporaryDirectory() as tmpdir:
workbook = xlrd.open_workbook(f"../registry_dir/{file_name}")
worksheet = workbook.sheet_by_index(0)
with open(f'{tmpdir}/{file_name}.csv', 'w', newline='') as file:
writer = csv.writer(file)
for row_num in range(worksheet.nrows):
writer.writerow([data for data in worksheet.row_values(row_num)])
excel_data_df = pd.read_csv(f'{tmpdir}/{file_name}.csv')
...file processing code
To use xlrd
to open .xlsx
files I used version 1.2.0
xrld == 1.2.0