我编写了这个程序来读取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个字符,但这似乎效率低下。 谢谢你的帮助!
答案 0 :(得分:1)
Also, if you want a way to read entire values of a row in one shot:
You can take first_sheet and do:
first_sheet.row_values(index_of_row)
This will return a list with all the values of the index_of_row.