Html Table class in Python..more examples
initial table
tabledict = {'width':'800','border':2,'bgcolor':'white'}
t = PyHtmlTable.PyHtmlTable( 2, 2, tabledict )
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.display()
| T1 Cell 00 |
T1 Cell 01 |
| T1 Cell 01 |
T1 Cell 11 |
Adding a column in bulk, passing in attributes
Note: The table auto expands as the array being passed
in is bigger
a = ["one", "two", "three" ]
t.add_array_to_col( 0, 0, a, {'bgcolor':'green'} )
t.display()
| one |
T1 Cell 01 |
| two |
T1 Cell 11 |
| three |
|
Adding a row in bulk is similar...adding
to last row of table
b = ["rone", "rtwo", "rthree" ]
t.add_array_to_row( t.getmaxRow()+1, 0, b, {'bgcolor':'grey'} )
t.display()
| one |
T1 Cell 01 |
|
| two |
T1 Cell 11 |
|
| three |
|
|
| rone |
rtwo |
rthree |
Set default attributes for cells in table...setting
bgcolor to red
Note: these will be overridden by explict attribute
settings for a given cell, hence the green and grey cells
t.setCellDefattrs({'bgcolor':'red'})
t.display()
| one |
T1 Cell 01 |
|
| two |
T1 Cell 11 |
|
| three |
|
|
| rone |
rtwo |
rthree |
Updating Cell attributes are additive by default
but can be overridden by setting a toggle with the
t.setReplaceCellattrs()
and reset to the default append mode with with the:
t.setAppendCellattrs()
method
You can also explicitly clear cells/row/table
attributes with calls to
clearCellattrs( row, col)
clearRowattrs( row )
clearTableattrs()
t.setCellattrs( 0,0, {'bgcolor':'red'})
yields a cell that looks like
TD bcolor="RED"
Subsequent calls to t.setCellattrs(0,0, {'width':100})
yields a cell that looks like
TD bcolor="RED" WIDTH="100"
You can use clearCellattrs( row, col ) to explicitly delete a
cell's attributes
OR
Set the global toggle
t.setReplaceCellattrs()
The second call to
t.setCellattrs(0,0, {'width':100})
above yieds a cell that looks like
TD WIDTH="100"
Clear tables attributes, set 0 border and redisplay
t.clearTableattrs()
t.setTableattrs({'border':0})
t.display()
| one |
T1 Cell 01 |
|
| two |
T1 Cell 11 |
|
| three |
|
|
| rone |
rtwo |
rthree |