| PyHtmlTable | index /home/pasko/python/PyHtmlTable/PyHtmlTable.py |
-----------------------------------------
Class PyHtmlTable
What:
Html Table generation on the fly.
Why:
Couldn't find an equivalent to Table.pm or Table.php
Features:
Allows setting of individual row and cell attributes via arbitrary
dictionaries
Allows spanning of rows and columns
Autogrows table if cells set outside initial
Range.
Allows dynamic insertion of new rows and columns anywhere in the table
Allows bulk population of table data via arrays to arbitrary locations
in the table.
Provides default cell attributes for tablewide uniformity
and the ability to override these on a cell by cell basis.
NOTE: Row indexes start at 0 like God and Kernighan demand!
Influenced heavily by Table.pm and Table.php
Example
print "<b> 2 by 2 table </b> "
t = PyHtmlTable(2,2, {'width':'400','border':2,'bgcolor':'white'})
t.setCellcontents(0,0,"T1 Cell 00")
t.setCellcontents(0,1,"T1 Cell 01")
t.setc(1,0,"T1 Cell 01") # New shorthand: setc == setCellcontents
t.setc(1,1,"T1 Cell 11") # Most of the main functions now have horthand equivalents
t.setCellattrs(0,0,{'bgcolor':'red','width':100})
t.setca(1,1,{'bgcolor':'red'}) # New shorthand: setca == setCellattrs
t.display()
t.setCellcontents(2,0,"T1 Cell 20") # Grow outside initial bounds
t.setCellcontents(2,1,"T1 Cell 21")
t.display()
print "<p><b> adding row </b>"
t.add_row(1) #Add a row after row index 1
t.display()
print "<p><b> adding col </b>"
t.add_col(1) #Add a col after col index 1
t.display()
print "<HR><b> AFTER row and col SPANNING </b>"
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()
print "<HR><b> Embed in new table </b>"
htmlstr = t.return_html()
nt = PyHtmlTable(1,4, {'width':'800','border':2,'bgcolor':'green'})
nt.setCellcontents(0,0,"Cell TH....text left")
nt.setCellcontents(0,1,"Text right")
nt.setCellcontents(0,2,htmlstr)
nt.setCellattrs(0,0,{'bgcolor':'blue','width':200,'align':'left'})
nt.setCellattrs(0,1,{'width':200,'align':'right'})
nt.setCelltype(0,0,"TH")
nt.display()
Current-Version: $Revision: 1.13 $
Last update: $Date: 2003/07/24 14:21:21 $
Home-Page: http://pasko.net/PyHtmlTable
Primary-Site: http://pasko.net/PyHtmlTable
Software-requirements: twodarr.py
Written and debugged under Python 2.2.2 by Joe Pasko
| Modules | ||||||
| ||||||
| Classes | ||||||||||
| ||||||||||
| Functions | ||
| ||
| Data | ||
| __file__ = './PyHtmlTable.pyc' __name__ = 'PyHtmlTable' | ||