用python读取xlrd

我写了这个程序从Excel文件中读取一列,然后写入一个txt文件:

import xlrd, sys text_file = open("Output.txt", "w") isotope = xlrd.open_workbook(sys.argv[1]) first_sheet=isotope.sheet_by_index(0) x= [] for rownum in range(first_sheet.nrows): x.append(first_sheet.cell(rownum, 1)) for item in x: text_file.write("%s\n" % item) text_file.close() 

它正确地读取列,但像这样写:

 number:517.0 number:531.0 number:517.0 number:520.0 number:513.0 number:514.0 number:522.0 

我可以以只写入数值而不是“数字:”的方式读取数据吗? 我可以删除每一行的前7个字符,但这似乎是低效的。 谢谢您的帮助!

另外,如果你想要一次读取一行中整个值的方法:

你可以拿first_sheet做:

 first_sheet.row_values(index_of_row) 

这将返回一个包含index_of_row所有值的列表。