0

Open the workbook

import xlrd
wb = xlrd.open_workbook('/home/AlAhAb65/Desktop/Parameter.xls')

Check the sheet names

wb.sheet_names()

Get the first sheet either by name

sh = wb.sheet_by_name('QA_TEST')
l = []

Iterate through rows, returning each as a list that you can index:

for rownum in range(sh.nrows):
    l.append(sh.row_values(rownum))
print l

When I am reading from excel to python list there always come ‘u’ before every data. How can I get rid of this? Is everything read as string? Do I have to convert every time?

4
  • It means they're unicode (as they should be stored in excel) - why does this bother you? (eg: does it cause encoding issues later/etc...) Commented May 14, 2013 at 14:20
  • And just an aside, instead of your loop, in Python 2.x you can use - map(ws.row_values, xrange(sh.nrows)) instead Commented May 14, 2013 at 14:26
  • Yes, Encoding issue occurs. I need to get rid of this because I need to send this value (as float or integer) to another program. That 'u' makes problem for this Commented May 14, 2013 at 15:41
  • You'll get unicode when the entries are strings in the sheet, if they're numeric, you'll get them as floats... so could you elaborate on the exact problem you're having? Commented May 14, 2013 at 15:55

1 Answer 1

1

The 'u' is not part of the string, it comes before the quotes and indicates a unicode string, which should be fine.

Also, you may want to have a look at the more recent openpyxl.

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.