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
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 :
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 ? )
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}
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 )
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 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.
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.
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: