# Reading values from Excel

**URL:** <https://forum.robotframework.org/t/reading-values-from-excel/6868>\
**Category:** Libraries\
**Created:** [20 February 2024 04:51 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868 "2024-02-20T04:51:15Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javed](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Javed](https://forum.robotframework.org/u/Javed)\
**Post date:** [20 February 2024 04:51 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/1 "2024-02-20T04:51:15Z")

</div>

Hi everyone,

Can anyone help me with how to call values from different sheets in Excel? For example, the username will be in Sheet1 and the password will be in Sheet2. I’ve tried some methods, but it always seems to call the values from the last sheet in the Excel file. Please find the code below for your reference. I would really appreciate your help

Open Excel Document ${file} 0  
Get Sheet ${sheet1}  
${Username} Read Excel Cell 2 1  
Log ${Username}  
Get Sheet ${sheet2}  
${Password} Read Excel Cell 2 1  
Log ${Password}  
Close Current Excel Document

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [20 February 2024 06:05 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/2 "2024-02-20T06:05:23Z")

</div>

Hi,

I assume you’re using ExcelLibrary, and I see the same issue as you do.  
But this seems to be linked to the way the ‘Get Sheet’ keywords returns the value, or a bug :  
Here :

```
${getsheetreturn} Get Sheet Sheet1 

```

returns :

```
${getsheetreturn} = <Worksheet "Sheet1">

```

This can’t be used directly in the keyword Read Excel Cell, and I’m not sure how to pass it nor if it activates really the sheet for reading.

However for your problem I would rather consider to directly pass the sheet’s name or variable to Read keyword :

```
Excel_Test
    Open Excel Document ${file} 0
    ${Username} Read Excel Cell 2 1 ${sheet1}
    Log message=${Username}
    ${Password} Read Excel Cell 2 1 ${sheet2}
    Log ${Password}

```

This works well, and saves lines 🙂

Regards

---

<div class="post-metadata">

**Author:** ![Javed](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Javed](https://forum.robotframework.org/u/Javed)\
**Post date:** [20 February 2024 07:01 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/3 "2024-02-20T07:01:06Z")

</div>

Hi Charlie , Thanks for replying.

But for the Read Excel Cell keyword , we cannot extra keywords where we can only use  
Read Excel Cell row\_num col\_num.

but thanks for letting me know that Get Sheet keywords has some issue 😊

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [20 February 2024 07:33 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/4 "2024-02-20T07:33:37Z")

</div>

Hi,

Here Excellibrary allows the use of the sheet\_name keyword :

[https://rawgit.com/peterservice-rnd/robotframework-excellib/master/docs/ExcelLibrary.html](https://rawgit.com/peterservice-rnd/robotframework-excellib/master/docs/ExcelLibrary.html)

```
 Returns content of a cell.
 **Args:**
 *row_num*: row number, starts with 1.
 *col_num*: column number, starts with 1.
 *sheet_name*: sheet name, where placed cell, that need to be read.

```

I had tested the example I gave above, and it worked fine. The example they gave in documentation part does not show this, but the above args provides it.

Not sure for the rest if it’s an issue, or what the Get Sheet keyword should do (activate the sheet ? )

Regards

---

<div class="post-metadata">

**Author:** ![Javed](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Javed](https://forum.robotframework.org/u/Javed)\
**Post date:** [29 February 2024 17:14 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/5 "2024-02-29T17:14:10Z")

</div>

Thank you for supporting charlie, It is working for me and really appreciate and thank you for your great guidance. 😊  
below mentioned logic is worked fine for me as you said ,  
Excel\_Test  
Open Excel Document ${file} 0  
${Username} Read Excel Cell 2 1 ${sheet1}  
Log message=${Username}  
${Password} Read Excel Cell 2 1 ${sheet2}  
Log ${Password}

---

<div class="post-metadata">

**Author:** ![Sayyed](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@Sayyed](https://forum.robotframework.org/u/Sayyed)\
**Post date:** [14 March 2024 05:00 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/6 "2024-03-14T05:00:18Z")

</div>

i need to have excel value instead of the cell formula

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [16 March 2024 17:03 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/7 "2024-03-16T17:03:14Z")

</div>

Hi,

I checked ExceLibrary, and it doesn’t seem to be implemented…  
Maybe there are some other libraries that provide this, but I was wondering if something not too complicated can be done, so here it is (assuming you mainly read values 🙂 )

```
***Settings***
Library SeleniumLibrary
Library readexcel.py

***Variables***
${file_path} path_to_your_file

***Test Cases***
Excel_Read
    ${value3} ReadExCell ${file_path} Sheet1 2 3 False

```

This is a quick custom .py with keyword that reads from the file. Last argument is _True_ by default (reads values), that can be passed to False to get formulas :

```
from openpyxl import load_workbook
from robot.api.deco import keyword

@keyword("ReadExCell")
 def ReadExcelRow(file_path, sheetname, searchrow, searchcolumn, data_only=True):
    searchrow = int(searchrow)
    searchcolumn = int(searchcolumn)

    # Get workbook and required sheet
    wb = load_workbook(file_path, data_only=data_only)
    sheet = wb[sheetname]

    # Cell read
    cell = sheet.cell(row=searchrow, column=searchcolumn)
    return cell.value

```

Here’s the result :

![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/3/3758d3c7e8afaabfeb46980873faf1a078caecb4.png)

 ![2024-03-16_17h59_44](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/5/5404bb7ff954919d25a52c4c1104875ba57ec763.png)

Regards.  
Charlie

---

<div class="post-metadata">

**Author:** ![Raghuveer-i](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/raghuveer-i/32/3927_2.png) [@Raghuveer-i](https://forum.robotframework.org/u/Raghuveer-i)\
**Post date:** [4 June 2024 10:58 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/8 "2024-06-04T10:58:40Z")

</div>

> [@CharlieScene](#):
>
> `${sheet1}`

Hi @CharlieScene is this --\>${sheet1} a sheet name to be mentioned?

---

<div class="post-metadata">

**Author:** ![Raghuveer-i](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/raghuveer-i/32/3927_2.png) [@Raghuveer-i](https://forum.robotframework.org/u/Raghuveer-i)\
**Post date:** [4 June 2024 11:11 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/9 "2024-06-04T11:11:02Z")

</div>

> [@CharlieScene](#):
>
> `Open Excel Document ${file} 0`

Hi @CharlieScene  
what is this doc\_id in def open\_excel\_document(self, filename: str, doc\_id: str) → str:

what to pass instead of 0 in the keyword: Open Excel Document ${file} 0

---

<div class="post-metadata">

**Author:** ![Raghuveer-i](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/raghuveer-i/32/3927_2.png) [@Raghuveer-i](https://forum.robotframework.org/u/Raghuveer-i)\
**Post date:** [4 June 2024 11:13 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/10 "2024-06-04T11:13:58Z")

</div>

Facing this issue to read data from excel

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/a/a1ea9368ab64ed27f8d7a1cf9dadf614777fe31c.png)

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [4 June 2024 12:17 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/11 "2024-06-04T12:17:31Z")

</div>

Hi,

From the documentation the ‘0’ is an ID identifier you give to the opened document.  
My guess is that if you open several files, you can identify docs in an easier way by recalling by ID with other Excel Library keywords.

So error might not be here, but probably from the path. Verify its consistency upon slash signs /, // or   
You could use ${/} which is an all platform path separator.

Regards  
Charlie

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [4 June 2024 12:18 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/12 "2024-06-04T12:18:20Z")

</div>

Yes, it’s sheet/tab name, but as said above the Get Sheet doesn’t activate the sheet

---

<div class="post-metadata">

**Author:** ![Raghuveer-i](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/raghuveer-i/32/3927_2.png) [@Raghuveer-i](https://forum.robotframework.org/u/Raghuveer-i)\
**Post date:** [4 June 2024 12:28 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/13 "2024-06-04T12:28:52Z")

</div>

Ok Thanks @CharlieScene

---

<div class="post-metadata">

**Author:** ![Darfito](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/darfito/32/4115_2.png) [@Darfito](https://forum.robotframework.org/u/Darfito)\
**Post date:** [5 August 2024 01:30 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/14 "2024-08-05T01:30:16Z")

</div>

hello, Is there a way to search for a specific value in Excel without using a loop? I want to select certain data efficiently. Is there a search value library in Robot Framework for Excel? I’ve been using a loop to find the data, but it’s taking a long time.

thank you for your help

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [31 August 2024 07:50 UTC](https://forum.robotframework.org/t/reading-values-from-excel/6868/15 "2024-08-31T07:50:26Z")

</div>

Hi,

On RF side, I’m not sure if you can do better than a loop.  
But you could either directly use a loop through a python script with excel libraries, or use something like this:

> **[Excel to Python: FIND function - A Complete Guide](https://www.trymito.io/excel-to-python/functions/text/FIND)**
>
> Learn how to convert Excel's FIND function to Python using Pandas. This comprehensive guide provides step-by-step instructions and practical examples.

Regards  
Charlie
