How to get line number in excel sheet using python?

眉间皱痕 提交于 2019-11-30 18:56:17
arulmr

Try this:

import xlrd
workbook = xlrd.open_workbook('book.xls')
for sheet in workbook.sheets():
    for row in range(sheet.nrows):
        for column in range(sheet.ncols):
            print "row::::: ", row
            print "column:: ", column
            print "value::: ", sheet.cell(row,column).value

It will give you exact row, column numbers and cell value

Keep track of the column and row while iterating over the worksheet. An xlrd Cell does not keep track of where they 'live' in the sheet.

if you are comparing cell values then you have their index which is line number and column number, otherwise you can start counter on row and column loop with increment on every iteration, this will tell you exact column number and row number.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!