robocorp / rpaframework

Collection of open-source libraries and tools for Robotic Process Automation (RPA), designed to be used with both Robot Framework and Python
https://www.rpaframework.org/
Apache License 2.0
1.15k stars 222 forks source link

Read Worksheet doesn't return last row value when I send the header flag = True #1197

Closed walaa-akram closed 2 months ago

walaa-akram commented 3 months ago

Hello Dears,

I have the following Excel sheet: image

and I try to read it using the header flag = true ${workSheet}= Read Worksheet ${sheetName} ${True} ${count}= Get Length ${workSheet} ${columnData}= Create List FOR ${index} IN RANGE 1 ${count}+1 ${cellValue} = Get Cell Value ${index} ${columnNo} Append To List ${columnData} ${cellValue} END When I logged the list I found it gets all column data except last row while I was expect to get all column data except first row. Why this happen? List length is 9 and it contains following items: 0: A 1: 1 2: 2 3: 3 4: 4 5: 5 6: 6 7: 7 8: 8

raivolink commented 3 months ago

Hi, It works as documented https://robocorp.com/docs-robot-framework/libraries/rpa-framework/rpa-excel-files/keywords#read-worksheet, returning list of dictionaries of the data. To get all cell values you have to consider that when looping header data becomes element, turning list length to 10 as you excel screenshot is showing.

mikahanninen commented 2 months ago

Yeah like @raivolink said the library works as expected. The difference with header=True to False is that header row is then excluded from the results as header row values are used as dictionary keys (thus it contains actually one row less). In False case the header row is in the results and the dictionary keys are Excel sheet column names A,B,C, etc.

The correct of looping ${worksheet} is this (works in both cases, header True/False

    FOR    ${row}    IN    @{worksheet}
        Log To Console    ${row}
    END