How to get line number in excel sheet using python?

后端 未结 3 711
日久生厌
日久生厌 2021-01-04 10:37

I have an Excel sheet like this:

  A B C D E F G
1 0 0 0
2   0 0
3 0
4
5 0 0 0 0 0 0 0
6 0 0   0

And every \'0\' represents some data value

相关标签:
3条回答
  • 2021-01-04 11:00

    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.

    0 讨论(0)
  • 2021-01-04 11:06

    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

    0 讨论(0)
  • 2021-01-04 11:11

    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.

    0 讨论(0)
提交回复
热议问题