2

In Robot Framework, I'm trying to get values from excel sheet using excel library. I've observed below issue for the "Get Row values" keyword

Open Excel    E:/Robot/excel/Test.xls
@{Datas}=    Get Row Values    Sheet1    0    includeEmptyCells=False
Log to console    ${Datas}

If the datas in the column are from A1 to Z1, the values are updated in the ${Datas} properly, I'm using these values ${Datas} again to convert it into List and get the exact value from the sheet.

But now when it exceeds Z1, i.e A1,B1,...,Z1,AA1,AB1,AC1.. ${Datas} is not generated as same in the sheet. Its stored as something as below

    [('A1', u'Valli'), ('AA1', u'sdffgdg'), ('AB1', u'k'), ('AC1', u'h'),('AD1', u'jk'), ('AE1', u'j'), ('AF1', u";\\'"), ('AG1', u'jk'), ('AH1', u'j'), ('AI1', u'Kasthurikala')........]

I want the values as same as in the excel rather than alphabetical order [('A1','Value1'),('B1','value1'), ('Z1','ValueZ'),('AA1','ValueAA1')

Is there any solution?

2
  • Are you saying you want the values in the order of the sheet rather than in alphabetical order? Commented Apr 9, 2015 at 16:37
  • @Bryan: Yes, I want values in the order as same as in the sheet. Commented Apr 9, 2015 at 16:46

1 Answer 1

3

You can sort by the length of the second element and breaking ties with the first elemnt:

a = [('B1','value1'), ('Z1','ValueZ'),('AA1','ValueAA1'),('A1','Value1')]
a.sort(key=lambda x: (len(x[1]),x[0]))
print(a)
[('A1', 'Value1'), ('B1', 'value1'), ('Z1', 'ValueZ'), ('AA1', 'ValueAA1')]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.