2016-06-13 68 views

回答

-1

請導入xlrd並運行此代碼,並修改爲您

import xlrd 
workbook = xlrd.open_workbook('file.xls') 
for s in workbook.sheets(): 
for r in range(s.nrows): 
    for c in range(s.ncols): 
     print "row::::: ", r 
     print "column:: ", c 
     print "value::: ", s.cell(r,c).value 
+0

可以使用一些關於這個for循環如何工作的解釋。 – mrscbw

0

最簡單的事情是通過工作表中的所有行簡單地循環,檢查單元格在相關列中並在您獲取該值時中斷。

from openpyxl import load_workbook 
wb = load_workbook(filename) 
ws = wb[sheetname] 
for row in ws: 
    cell = row[0] # for column 'A' 
    if cell.value == sentinel: 
     break 

# do what you want with the row