0

I currently use this code which I think takes longer the more the sheet grows:

def findLastRow():
    global spreadsheet
    global datastartrow

    print 'rows: ', worksheet.row_count

    lastrow = datastartrow

    while(True):
        val = worksheet.cell(lastrow, datastartrow).value

        if val == '':
            lastrow -= 1

            break

        lastrow += 1

    return lastrow

Is there a more efficient way like getLastRow from GAS?

ebswift
  • 11
  • 3

1 Answers1

1

I think I found a roundabout way that still isn't efficient, but is somewhat faster, here's my new count test vs the old captured from the console:

trying to login to google sheets
logged in
sync time
starting count 1
colvals:  1001
count 1 took:  3.41200017929 seconds

starting count 2
lastrow:  1001
count 2 took:  531.482000113 seconds

This is new vs old:

def findLastRow():
    global spreadsheet
    global datastartrow
    global datastartcolumn

    t0 = time.time()

    print 'starting count 1'
    colvals = worksheet.col_values(1)
    t1 = time.time()

    print 'colvals: ', len(colvals)

    print 'count 1 took: ', str(t1 - t0) + ' seconds'

    # return len(colvals)

    t0 = time.time()

    print 'starting count 2'

    lastrow = datastartrow

    while(True):
        val = worksheet.cell(lastrow, datastartrow).value

        if val == '':
            lastrow -= 1

            break

        lastrow += 1

    print 'lastrow: ', lastrow

    t1 = time.time()

    print 'count 2 took: ', str(t1 - t0) + ' seconds'

    return lastrow
ebswift
  • 11
  • 3