InvalidFileException: openpyxl does not support .xlsx

606 views
Skip to first unread message

Prashant Patel

unread,
Mar 19, 2020, 7:39:06 PM3/19/20
to robotframework-users
Friends,

While running robot TC1.robot from PyCharm I get below error message. Here is my set up. I have MS Office Professional Plus 2016. Can someone please help?

Error: InvalidFileException: openpyxl does not support .xlsx" file format, please check you can open it with Excel first. Supported formats are: .xlsx,.xlsm,.xltx,.xltm


Package              Version
---------------------- --------
openpyxl              3.0.3
robotframework   3.1.2
python     3.8


ReadExcel.py

import  openpyxl
def get_excel_row_index(filename, worksheetname, stringtosearch):
wb = openpyxl.load_workbook(filename)
ws = wb[worksheetname]
total_row = ws.max_row
total_col = ws.max_column
for index, row in enumerate(ws.iter_rows()):
for cell in row:
if ws.cell(row=index + 1, column=1).value == stringtosearch:
return index + 1
break

DataManager.robot

*** Settings ***
Library ../CustomLibs/ReadExcel.py
${INPUT_DATA_EXCEL_FILE} =  "C:\\Users\\Resources\\Order.xlsx"

*** Keywords ***
Get Excel Data
[Arguments] ${INPUT_DATA_EXCEL_FILE} ${WORK_SHEET_NAME} ${STRING_TO_SEARCH}
${Data} get_excel_row_index ${INPUT_DATA_EXCEL_FILE} ${WORK_SHEET_NAME} ${STRING_TO_SEARCH}
[Return] ${Data}

TC1.robot

*** Settings ***
Library ../CustomLibs/ReadExcel.py
Resource ../CustomLibs/DataManager.robot

*** Test Cases ***
My First Tc To Get Data From Excel
${s1} = DataManager.Get Excel Data ${INPUT_DATA_EXCEL_FILE} "test6" "ABC"
Log To Console ${s1}

Mahad Ali Khan

unread,
Mar 19, 2020, 9:21:43 PM3/19/20
to prashant....@gmail.com, robotframework-users
Install openpyxl1 and test.

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/robotframework-users/31f0c300-e6cf-4b78-82aa-c7154d08f057%40googlegroups.com.

Prashant Patel

unread,
Mar 20, 2020, 1:49:51 PM3/20/20
to robotframework-users
I was able to resolve this issue with below solution.

Root Cause: Input data file path was hard coded like: ${INPUT_DATA_EXCEL_FILE} = "C:\\Users\\Resources\\Order.xlsx"

Solution: Input data file path was generated dynamically using ${CURDIR} built-in variable.
Reply all
Reply to author
Forward
0 new messages