Robot Framework Excel Library
Robot Framework library for working with Excel documents, based on `openpyxl`. It provides keywords to allow opening, reading, writing, and saving Excel files within Robot Framework test automation. The current version is 2.0.1, with the latest release on June 18, 2020. The project appears to be in maintenance mode, with no recent development activity beyond the 2020 release.
Common errors
-
Importing test library 'ExcelLibrary' failed: ModuleNotFoundError: No module named 'ExcelLibrary'
cause The `robotframework-excellib` Python package is not installed or not discoverable by Robot Framework.fixInstall the library via pip: `pip install robotframework-excellib`. -
SuchIdIsExistException: Document with such id 'my_doc_id' is created.
cause You are trying to create a new Excel document with a `doc_id` that is already in use by another open document in the library's cache.fixClose the existing document first using `Close Current Excel Document` or `Close All Excel Documents`, or use a unique `doc_id` for the new document. -
IOError: [Errno 13] Permission denied: '/path/to/your/file.xlsx'
cause The Excel file you are trying to save or modify is currently open by another application (e.g., Microsoft Excel, LibreOffice Calc) or your user account lacks write permissions to the file or directory.fixClose the Excel file in any other application before executing the Robot Framework test. Verify and adjust file system permissions if necessary. -
XLRDError: No sheet named '<sheet_name>' in robotframework-excellib
cause You are attempting to access an Excel sheet by a name that does not exist in the currently opened workbook, or the workbook might be empty/corrupted.fixDouble-check the exact spelling and case of the sheet name. Ensure the Excel document you are working with actually contains the specified sheet. Use keywords like `Get Sheet Names` to list available sheets.
Warnings
- breaking The `Open Excel Document` keyword had a breaking change in an unspecified version, adding a new `keep_vba` argument. Scripts using older keyword signatures without this argument may fail after upgrading.
- gotcha There are multiple Robot Framework Excel libraries with similar names (`robotframework-excellib` and `robotframework-excellibrary`). `robotframework-excellib` is based on `openpyxl` and supports Python 3 and `.xlsx` files. The older `robotframework-excellibrary` is typically for Python 2 and `xls` files (via `xlutils` and `xlrd`). Ensure you are installing and using the correct library for your Python version and file type.
- gotcha Attempting to create or open an Excel document using an identifier (`doc_id`) that already exists in the library's internal cache will raise a `SuchIdIsExistException`. This often happens when re-running tests or not properly closing documents.
Install
-
pip install robotframework-excellib
Imports
- ExcelLibrary
import ExcelLibrary Library robotframework-excellib
*** Settings *** Library ExcelLibrary
Quickstart
*** Settings ***
Library ExcelLibrary
*** Test Cases ***
Create And Write Excel Document
${doc_id}= Create Excel Document doc_id=MyNewExcel
Write Excel Cell row_num=1 col_num=1 value=Hello
Write Excel Cell row_num=1 col_num=2 value=World
Save Excel Document filename=output.xlsx
Close Current Excel Document
Read From Excel Document
${doc_id}= Open Excel Document filename=output.xlsx doc_id=ExistingExcel
${cell_value}= Read Excel Cell row_num=1 col_num=1
Should Be Equal As Strings ${cell_value} Hello
Close Current Excel Document