Jason Rome
Jason Rome

Reputation: 29

reading excel data from python

I know that when Python reads from .txt files there can be issues with it reading numbers. Does this also occur when reading from cells in excel or does the xlrd module implicitly know whether it is reading integers, floats, strings, etc.?

Upvotes: 0

Views: 912

Answers (1)

Joshua Nelson
Joshua Nelson

Reputation: 581

According to the documentation on the site (https://secure.simplistix.co.uk/svn/xlrd/trunk/xlrd/doc/xlrd.html?p=4966#sheet.Cell-class)

Cell objects have three attributes: ctype is an int, value (which depends on ctype) and xf_index.

And the possible values for ctype are:

  • XL_CELL_EMPTY
  • XL_CELL_TEXT
  • XL_CELL_NUMBER
  • XL_CELL_DATE
  • XL_CELL_BOOLEAN
  • XL_CELL_ERROR
  • XL_CELL_BLANK

Which correspond to different types (listed in the documentation)

However, I've got to say, I'd recommend interacting with data from excel in .csv format. You can easily read csv files in python with

with open(fileName, 'rb') as csvfile:
    resultReader = csv.reader(csvfile, delimiter=',', quotechar='|')
    for row in resultReader:
        ...

Upvotes: 0

Related Questions