# -*- coding: utf-8 -*-
from openpyxl import load_workbook
filename = 'test.xlsx'
wb = load_workbook(filename= filename)
sheetnames = wb.get_sheet_names()
ws = wb.get_sheet_by_name(sheetnames[3])
first_column = ws['A']
print("len(first_column)",len(first_column))
count = 0
start = False
end = False
for x in range(len(first_column)):
if first_column[x].value != None:
if start == True:
end = True
start = True
x = x + 1
pos = 'B' + str(x)
count = 1
else:
count = count + 1
if start == True and end == True:
ws[pos] = count
wb.save(filename)