I have a html table generated in controller. This table gets rendered. Now 
if the user wants more number of rows added to the table, I give a AddRows 
button. On the click of AddRows I would like to add rows to the existing 
table in the controller with empty cells and render it with the additional 
rows. How to achieve that? I have done this project in .NET. I am now 
migrating that to web2py. Pl. help. My code in controller is
def generate_table_from_excel(num_rows):
    
    up = os.path.join(request.folder,'uploads')
    workbook = xlrd.open_workbook(os.path.join(request.folder,'uploads',
'meas.xls'))
    worksheet = workbook.sheet_by_name('Sheet1')
    num_rows = worksheet.nrows - 1
    num_cells = worksheet.ncols - 1
    curr_row = -1
    while curr_row < num_rows:
        d = {}
        curr_row += 1
        row = worksheet.row(curr_row)
        #print 'Row:', curr_row
        curr_cell = -1
        while curr_cell < num_cells:
            curr_cell += 1
            # Cell Types: 0=Empty, 1=Text, 2=Number, 3=Date, 4=Boolean, 
5=Error, 6=Blank
            cell_type = worksheet.cell_type(curr_row, curr_cell)
            cell_value = worksheet.cell_value(curr_row, curr_cell)
            #print '    ', cell_type, ':', cell_value
            if curr_cell == 0:
                d['loc_of_work'] = cell_value
            if curr_cell == 1:
                d['n'] = cell_value
            if curr_cell == 2:
                d['t'] = cell_value
            if curr_cell == 3:
                d['l'] = cell_value
            if curr_cell == 4:
                d['b'] = cell_value
            if curr_cell == 5:
                d['d'] = cell_value
       
    
    i = 1
    form = FORM( TABLE(
                      TR( TD('AgtNo:'),   TD(session.agt_no)    ),
                      TR( TD('Jcod:'),    TD(session.jcod)     ),
                      TR( TD('MeasDate:'),TD(session.meas_date) ),
                      TR( TD('Shift:'),   TD(session.shift)    ),
                      TR( TD( INPUT(_type='submit',_value='Save') ), TD( 
INPUT(_type='submit',_value='AddRows',_id='AddRows') ))
                      ),
                 INPUT(_id='txtNoOfRows',_type='hidden',_value=len(l)),
                 TABLE(
                    THEAD(TR(
                    TH('Loc'),
                    TH('n'),
                    TH('t'),
                    TH('l'),
                    TH('b'),
                    TH('d'),
                    TH('Mat'),
                    TH('UWt'),
                    TH('Content'),
                    TH('Remarks'),
                    _style='halign:center'   )),

                    TBODY([TR(
                             TD(TEXTAREA(_name='txt' + str(i+1) + '1',_id=
'txt'+str(i+1) +'1',value = r['loc_of_work'],_style=
'width:200px;height:50px;')),
                             TD(INPUT(_name='txt' + str(i+1) + '2',_id='txt'
+str(i+1) + '2',value=r['n'],_style='width:50px',_onblur=
'calculate_content()')),
                             TD(INPUT(_name='txt' + str(i+1) + '3',_id='txt'
+str(i+1) + '3' ,value=r['t'],_style='width:50px',_onblur=
'calculate_content()')),
                             TD(INPUT(_name='txt' + str(i+1) + '4',_id='txt'
+str(i+1) + '4',value=r['l'],_style='width:50px',_onblur=
'calculate_content()')),
                             TD(INPUT(_name='txt' + str(i+1) + '5',_id='txt'
+str(i+1) + '5',value=r['b'],_style='width:50px',_onblur=
'calculate_content()')),
                             TD(INPUT(_name='txt' + str(i+1) + '6',_id='txt'
+str(i+1) + '6',value=r['d'],_style='width:50px',_onblur=
'calculate_content()')),
                             TD(SELECT(_name='cmbMat' + str(i+1) + '7',_id=
'cmbMat'+str(i+1) + '7',_onchange='get_unit_weight('+ str(i+1) +',7)',*[
OPTION(str(x.unit_weight) + '|' + x.material_descr,_value=x.id) for x in 
mats])),
                             TD(INPUT(_name='txt' + str(i+1) + '8',_id='txt'
+str(i+1) + '8',_style='width:50px',_readonly='readonly')),
                             TD(INPUT(_name='txt' + str(i+1) + '9',_id='txt'
+str(i+1) + '9',_style='width:60px',_readonly='readonly')),
                             TD(TEXTAREA(_name='txt' + str(i+1) + '10',_id=
'txt'+str(i+1) + '10',_style='width:200px;height:50px;')),
                        )for i,r in enumerate(l)], _style=
'border=0;margin=0;padding=0;')

              ,_id='tblMeas')) 
#http://nedbatchelder.com/text/iter/iter.html#13
    return formEnter code here...


-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to