[英]How to read a cell in excel using a python for loop?
我正在 python 中制作 excel 文件讀取程序。 我希望它讀取特定列中的每個單元格。 我為此使用了一個 for 循環。 這是我的代碼:
location = "C:\\Users\\user2\\Desktop\\Python\\Other\\blah.xls"
workbook = xlrd.open_workbook(location)
sheet = workbook.sheet_by_index(0)
rownum = 1
for word in (sheet.cell_value(rownum,2)):
print(word)
rownum += 1
我得到了結果:
R
E
S
T
A
R
T
I
S
S
U
E
/
R
A
M
P
R
O
B
L
E
M
相反,我希望結果逐字顯示,而不是逐字顯示。
代替
for word in (sheet.cell_value(rownum,2)):
利用
for word in (sheet.cell_value(rownum,2).split(' ')):
如果在字符串上使用for
,它將遍歷單個字符
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.