简体   繁体   中英

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.?

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:
        ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM