Html Table class in Python...simple example

Start with a 2 by 2 table

    
    t  = PyHtmlTable.PyHtmlTable(2,2, {'width':'400','border':2,'bgcolor':'white'})

    t.setCellcontents(0,0,"T1 Cell 00")
    t.setCellcontents(0,1,"T1 Cell 01")
    t.setCellcontents(1,0,"T1 Cell 01")
    t.setCellcontents(1,1,"T1 Cell 11")

    t.setCellattrs(0,0,{'bgcolor':'red','width':100})
    t.setCellattrs(1,1,{'bgcolor':'red'})
    t.display()
    
T1 Cell 00 T1 Cell 01
T1 Cell 01 T1 Cell 11

Dynamically grow outside initial table boundaries by setting cells outside current boundaries
    t.setCellcontents(2,0,"T1 Cell 20")  # Grow outside initial bounds
    t.setCellcontents(2,1,"T1 Cell 21")
    t.display()
    
T1 Cell 00 T1 Cell 01
T1 Cell 01 T1 Cell 11
T1 Cell 20 T1 Cell 21

Explicitly add row after row index 1


    t.add_row(1)   #Add a row after row index 1
    t.display()

    
T1 Cell 00 T1 Cell 01
T1 Cell 01 T1 Cell 11
   
T1 Cell 20 T1 Cell 21

Explicitly adding col after column index 1


    t.add_col(1)   #Add a col after col index 1
    t.display()
    
T1 Cell 00 T1 Cell 01  
T1 Cell 01 T1 Cell 11  
     
T1 Cell 20 T1 Cell 21  

AFTER row and col SPANNING
     t.setCellRowSpan(1,0,2) # Span cell at index row 1,col 0, make 2 high
     t.setCellColSpan(1,1,2) # colSpan cell at index row 1, col 1, make 2 wide

     t.display()
    
T1 Cell 00 T1 Cell 01  
T1 Cell 01 T1 Cell 11
   
T1 Cell 20 T1 Cell 21  

Embed in new table

    htmlstr = t.return_html()                                          # Return table as a string

    tabledict = {'width':'800','border':2,'bgcolor':'green'}

    nt = PyHtmlTable.PyHtmlTable(1,4, tabledict)                       # New table object with tabledict attributes

    nt.setCellcontents(0,0,"Cell TH....text left")
    nt.setCellcontents(0,1,"Text right")
    nt.setCellcontents(0,2,htmlstr)                                    # Embed previous table into new table

    nt.setCellattrs(0,0,{'bgcolor':'blue','width':200,'align':'left'}) # Set cell attributes

    nt.setCellattrs(0,1,{'width':200,'align':'right'})                 # Set text to the right, and set width

    nt.setCelltype(0,0,"TH")                                           # Make a 'TH' cell instead of the default  'TD'

    nt.display()

    
Cell TH....text left Text right
T1 Cell 00T1 Cell 01 
T1 Cell 01T1 Cell 11
  
T1 Cell 20T1 Cell 21