Parsing Excel File Raises "No such keys(s): 'io.excel.zip.reader'" Error

I'm attempting to parse an file type 'docx' in my Django application using pandas, but I'm encountering the error "No such keys(s): 'io.excel.zip.reader'". It seems like there's an issue with how the file is being read or with the file format itself. I've checked that the file is indeed an Excel file with the .xlsx extension then its working fine but when i m adding elif statement for file type 'docx' then i got that error. Can someone help me understand what might be causing this error and how to resolve it? Below is a snippet of the code I'm using:


import pandas as pd
import json
from docx import Document

if request.method == 'POST':
        form = UserPermissionForm(request.POST, request.FILES)
        if form.is_valid():
            upload_template_instance = form.save()
            template_file = upload_template_instance.template_master

            # Check file extension to determine its type
            if template_file.name.endswith('.xlsx'):
                # Parse the Excel file using Pandas
                df = pd.read_excel(template_file)
                df.fillna('', inplace=True)
                df.columns = ["" if 'Unnamed' in str(col) else col for col in df.columns]
                columns = df.columns.tolist()
                data = df.values.tolist()
            elif template_file.name.endswith('.docx'):
                # Parse the Word document using python-docx
                doc = Document(template_file)
                data = []

                for paragraph in doc.paragraphs:
                    # Extract text from each paragraph
                    text = paragraph.text
                    # Split text into a list based on some delimiter, like tab or comma
                    row = text.split('\t')  # You might need to adjust this based on your document structure
                    data.append(row)

                # Remove empty rows
                data = [row for row in data if any(cell.strip() for cell in row)]
                columns = None  # No columns in Word document

            # Convert data to JSON
            data_json = json.dumps(data)

            return render(request, 'your_template.html', {'form': form, 'columns': columns, 'data': data})

first i tried only for excel reading then it worked , but when i added elif statement for another file type as word doc then its not letting me read and converting my word data into table.

Back to Top