How do I read an Excel file in Python?I have found a package to read excel file, which can be used on anyplatform. http://www.lexicon.net/sjmachin/xlrd.htmI installed and working on the examples, I found its printing of cell''scontents in a different manner.print sh.row(rx)[text:u''name'', text:u''address'', text:u''ph''][text:u''sudhir'', text:u''bangalore'', number:1234.0][text:u''vinay'', text:u''bangalore'', number:3264.0]I am bit confused with slicing. help me....Thank you,Regards,Sudhir. 解决方案Hi Sudhir,So far, so good :-)print sh.row(rx)[text:u''name'', text:u''address'', text:u''ph''][text:u''sudhir'', text:u''bangalore'', number:1234.0][text:u''vinay'', text:u''bangalore'', number:3264.0]It helps when asking questions if you copy/paste exactly what is onyour screen;in this caseprint sh.row(rx)would have given an error; you must have typedfor rx in range.....A row is returned as a sequence of Cell objects. What you are seeing isPython automatically doing repr(cell) on each cell in the row. TheCell.__repr__ method formats it that way for debugging. Here are someexamples from a little test file of mine:[text:u''fubar'', number:1.0, number:2.0]<class ''xlrd.sheet.Cell''>1u''fubar''"text:u''fubar''"None of the above is anything to do with slicing; is this a 2ndproblem?Perhaps you are having trouble with this:Help on method row_slice in module xlrd.sheet:row_slice(self, rowx, start_colx=0, end_colx=None) method ofxlrd.sheet.Sheet instance### Returns a slice of the Cell objects in the given row.sh.row_slice(rowx, lo, hi) gives the same result as sh.row(rowx)[lo:hi]-- it is provided because the latter would be inefficient for getting asmall slice from a long row.If you are having trouble with the general concept of slicing, perhapsyou might like to try the Python tutorial. Otherwise, please try to bea bit more specific about what the confusion is.HTH, and e-mail me if you prefer ...Cheers,JohnHi Sudhir,So far, so good :-) print sh.row(rx) [text:u''name'', text:u''address'', text:u''ph''] [text:u''sudhir'', text:u''bangalore'', number:1234.0] [text:u''vinay'', text:u''bangalore'', number:3264.0]It helps when asking questions if you copy/paste exactly what is onyour screen;in this case print sh.row(rx)would have given an error; you must have typed for rx in range.....A row is returned as a sequence of Cell objects. What you are seeing isPython automatically doing repr(cell) on each cell in the row. TheCell.__repr__ method formats it that way for debugging. Here are someexamples from a little test file of mine:[text:u''fubar'', number:1.0, number:2.0]<class ''xlrd.sheet.Cell''>1u''fubar''"text:u''fubar''"None of the above is anything to do with slicing; is this a 2ndproblem?Perhaps you are having trouble with this:Help on method row_slice in module xlrd.sheet:row_slice(self, rowx, start_colx=0, end_colx=None) method ofxlrd.sheet.Sheet instance ## # Returns a slice of the Cell objects in the given row.sh.row_slice(rowx, lo, hi) gives the same result as sh.row(rowx)[lo:hi]-- it is provided because the latter would be inefficient for getting asmall slice from a long row.If you are having trouble with the general concept of slicing, perhapsyou might like to try the Python tutorial. Otherwise, please try to bea bit more specific about what the confusion is.HTH, and e-mail me if you prefer ...Cheers,JohnHi, thanks for the reply. I just took some time reading help file andcame to know to there is nothing do with slicing. But I do have aproblem with date field in the excel file.the date( 8/9/2006 ) in Excel file, i am getting the value as 38938.0,which I get when I convert date values to general format in Excel. Iwant the actual date value. How do get that?Thank you.regards,Sudhir.38938 appears to be the date in days since 1/1/1900. I''m sure someonecan help you figure out how to convert that to a more useful value.-Matt 这篇关于如何在Python中读取Excel文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!