Excel Library for Robot Framework Changed

DATE: 6/25/2021

 
 

*** This change discovered on 6/25/2021.

Introduction

 

In Robot Framework script code when hovering over Open Excel Document keyword in the EXCELLIBRARY.PY class, there is information displayed. Some of the information are arguments required, what the keyword does, and what it returns. There may be some examples shown too. If it were not for that information, I would not know what three arguments were required.

It used to be only two arguments required. Now there are three.

Unfortunately, whoever made some recent changes to the excel library code did not update the keyword list accordingly. This is critical for those who have existing Robot Framework scripts. It helps to know what change impacts exist to the scripts.

  • ExcelLibrary def open_excel_document(self,
    • filename: str,
    • doc_id: str,
    • keep_vba: bool) -> str
  • Opens xlsx document file.
  • Args:
    • Filenameà document name.
    • doc_idà the identifier for the document that will be opened.
    • keep_vbaà save vba macros for xlsm document.
  • Returns:
  • Document identifier from the cache.
  • Example:
    • Open Excel Document | filename=file.xlsx | doc_id=docid | keep_vba=false |
    • Close All Excel Documents |

 

Installation Changes

OLD method for Excel Library installs – pip install robotframework-excellibrary

NEW method for doing an Excel Library installs – pip install robotframework-excellib-xlsm==2.0.3

 

 

 

Other Install Requirements

 

If you are creating a new virtual environment in your IDE, there might be the following PIP installs required:

  • pip install xlutils
  • pip install natsort
  • pip install robotframework-excellib-xlsm==2.0.3
  • pip install robotframework-requests==0.9.1

Excellibrary.py Class Changes

The class is in the virtual environment site-packages folder. The version is 2.0.3. It contains the new keyword functions as follows:

 

Keyword

Details

Create Excel Document

DESCRIPTION: Creates new excel document.

ARGUMENTS:

doc_id= doc reference alphanumeric value

 

Open Excel Document

DESCRIPTION: Opens xlsx document file.

ARGUMENTS:

 

Filename= document name.

doc_id= the identifier for the document that will be opened.

keep_vba= save vba macros for xlsm document (true/false).

Open Excel Document From Stream

DESCRIPTION: Opens xlsx document from stream.

ARGUMENTS:

 

Stream= file-like byte stream object {e.g. from any http request).

doc_id= the identifier for the document that will be opened.

keep_vba= save vba macros for xlsm document (true/false).

Returns:

 Document identifier from the cache.

Make List From Excel Sheet

DESCRIPTION: Making list from Excel sheet.

ARGUMENTS:

Sheet= Excel file sheet.

Returns:

 _data_: a list of tuples corresponding to the values of each line of an Excel file.

Switch Current Excel Document

DESCRIPTION: Switches current excel document.

ARGUMENTS:

doc_id= identifier of the document to switch.

Returns:

 Identifier of previous document.

Close Current Excel Document

DESCRIPTION: Closes current document.

ARGUMENTS:

none

Returns:

 Closed document identifier.

Close All Excel Documents

DESCRIPTION: Closes all opened documents.

ARGUMENTS:

none

 

Example:

${doc1}=  Create All Excel Documents

${doc2}= | Create Excel Document | docname2 |

Close All Excel Document

Save Excel Document

DESCRIPTION: Saves the current document to disk.

ARGUMENTS:

Filename= file name to save.

Example:

Save Excel Document   filename=file1.xlsx

Get List Sheet Names

DESCRIPTION: Returns a list of sheet names in the current document.

Returns:

 List of page names.

 

Example:

${sheets}=    Get List Sheet Names

Get Sheet

DESCRIPTION: Returns a page from the current document.

ARGUMENTS:

sheet_name= sheet name.

Returns:

 Document’s sheet.

Read Excel Cell

DESCRIPTION: Returns content of a cell.

ARGUMENTS:

row_num=  row number, starts with 1.

col_num=  column number, starts with 1.

sheet_nam=  sheet name, where placed cell, that need to be read.

Returns:

 Content of the cell in the specified column and row.

Read Excel Row

DESCRIPTION: Returns content of a row from the current sheet of the document.

ARGUMENTS:  

row_num=  row number, starts with 1.

col_offset=  column indent.

max_num=  maximum number of columns to read.

sheet_name=  sheet name, where placed row, that need to be read.

Returns:

 List, that stores the contents of a row.

Read Excel Column

DESCRIPTION: Returns content of a column from the current sheet of the document.

ARGUMENTS:   

col_num=   column number, starts with 1.

row_offset=  row indent.

max_num=  maximum number of rows to read.

sheet_name=  sheet name, where placed column, that need to be read.

Returns:

 List, that stores the contents of a row.

Write Excel Cell

DESCRIPTION: Writes value to the cell.

ARGUMENTS:    

row_num=  row number, starts with 1.

col_num=  column number, starts with 1.

Value=  value for writing to a cell.

sheet_name=  sheet name for write.

Write Excel Row

DESCRIPTION: Writes a row to the document.

ARGUMENTS:  

row_num=  row number, starts with 1.

row_data=  list of values for writing.

col_offset=  number of indent columns from start.

sheet_name=  sheet name for write.

Write Excel Rows

DESCRIPTION: Writes a list of rows to the document.

ARGUMENTS:   

rows_data=  list of rows for writing.

rows_offset=  number of indent rows from start.

col_offset=  number of indent columns from start.

sheet_name=  sheet name for write.

Write Excel Column

DESCRIPTION: Writes the data to a column.

ARGUMENTS:  

col_num=  column number, starts with 1.

col_data=  list of values for writing.

row_offset=  number of indent rows from start.

sheet_name=  sheet name for write.