简体   繁体   English

从.xls文件中获取数据到python列表

[英]taking data from .xls file to python list

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. 当我从excel读取到python列表时,总是在每个数据之前出现“ u”。 How can I get rid of this? 我该如何摆脱呢? Is everything read as string? 一切都读为字符串吗? Do I have to convert every time? 我每次都要转换吗?

The 'u' is not part of the string, it comes before the quotes and indicates a unicode string, which should be fine. 'u'不是字符串的一部分,它在引号之前,表示一个unicode字符串,应该没问题。

Also, you may want to have a look at the more recent openpyxl . 另外,您可能想看看最新的openpyxl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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