I am currently have a workbook with 5 worksheets. there is data in columns a - e, while each worksheet may have data in the same columns, each worksheet has different different amount rows though. I am entering a formula in column f that will go from cell F4 to whatever the last row is in that worksheet. I am able to loop through sheets and am able to create a formula that goes from F4 to the last row, however I am unable get the two to work together.
Code
import os
import os.path
import urllib
import xlrd
import xlwt
from xlutils.copy import copy
fname = "test.xls"
destination = 'C:\Users\Raj Saha\Google Drive\Python\Excel-Integration'
rb = xlrd.open_workbook(fname,formatting_info=True) #original workbook
r_sheet = rb.sheet_by_index(1) #origianl worksheet
style = xlwt.easyxf('font: bold 1')
wb = copy(rb) #virtual workbook
#sheet = wb.get_sheet(1)
shxrange = range(rb.nsheets)
sh = rb.sheet_by_name("Data 1")
#print "total rows: %d, rows less headers: %d" % (nrows, rows)
for sheet in shxrange:
nrows = sheet.nrows
rows = nrows - 4
for i in range(rows):
sheet.write(i+3, 5, xlwt.Formula("B%d-C%d" % (i+4, i+4)))
sheet.write(2,5,"CL1-CL2",style)
wb.save(fname)
I get the following error message:
File "C:/formulas_multi_sheets.py", line 31, in nrows = sheet.nrows
AttributeError: 'int' object has no attribute 'nrows'
I assume the error in line 31 would apply to line 32. I am using python 2.7.