我的代码段如下所示:
for current_row in range(worksheet.nrows):
fname_text = worksheet.row(current_row)[0]
lname_text = worksheet.row(current_row)[1]
cmt = worksheet.row(current_row)[2]
print (fname_text, lname_text, cmt)
打印:
text:'firstname' text:'lastname' text'the cmt line'
我希望它只是回归:
firstname lastname the cmt line
我需要改变什么来实现这一目标?
答案 0 :(得分:2)
这就是Cell
个对象的样子:
>>> sheet.row(0)
[text:u'RED', text:u'RED', empty:'']
>>> sheet.row(0)[0]
text:u'RED'
>>> type(sheet.row(0)[0])
<class 'xlrd.sheet.Cell'>
您可以通过以下几种方式获得包装值:
>>> sheet.row(0)[0].value
u'RED'
>>> sheet.row_values(0)
[u'RED', u'RED', '']
并且记住您无需通过row
>>> sheet.cell(0,0).value
u'RED'