37,721
社区成员
发帖
与我相关
我的任务
分享
#!phthon
#-*- coding:GBK -*-
# filename:HtmlFunctions.py
def _attr(attr = {}):
return ''.join([' %s="%s"' % (k,v) for k,v in attr.items()])
def _th(content, attr={}):
return "<TH%s>%s</TH>" % (_attr(attr),content)
def _td(content, attr={}):
return "<TD%s>%s</TD>" % (_attr(attr),content)
def _td_c(content, attr={}):
attr['align']='center'
return _td(content, attr)
def _td_l(content, attr={}):
attr['align']='left'
return _td(content, attr)
def _td_r(content, attr={}):
attr['align']='right'
return _td(content, attr)
def _td_money(mny, attr={}):
attr['align']='right'
return _td("%.2f" % mny, attr)
def _tr(cells=[], attr={}):
return "<TR%s>%s</TR>" % (
_attr(attr),
''.join(cells)
)
def _tb(rows=[]):
return "<TBODY>%s</TBODY>" % '\n'.join(rows)
def _table(tableInfos={}):
if tableInfos.has_key('attrib') and tableInfos['attrib'] > '':
attrib = tableInfos['attrib']
else:
attrib = ''
if tableInfos.has_key('caption') and tableInfos['caption'] > '':
caption = "<CAPTION>%s</CAPTION>" %s (tableInfos['caption'])
else:
caption = ''
if tableInfos.has_key('rows') and tableInfos['rows'] > '':
rows = tableInfos['rows']
else:
rows = ''
return "<TABLE%s>%s%s</TABLE>" % (attrib, caption, rows)
class Table:
def __init__(self, attrib={}):
self.headColumns = []
self.caption = ''
self.attrib = attrib
pass
def bind(self, data=[]):
self.data = data
pass
def toString(self):
caption = self.caption == '' and '' or '<CAPTION>%s</CAPTION>' % self.caption
if len(self.headColumns) == 0:
headers = ''
else:
headers = "<THEAD>%s</THEAD>" % _tr(
''.join([_th(cell) for cell in self.headColumns]))
tbody = _tb([
( _tr(''.join([_td(cell) for cell in row])) )
for row in self.data
])
return "<TABLE%s>%s\n%s</TABLE>" % (_attr(self.attrib),headers,tbody)
def setHeader(self, headColumns=[]):
self.headColumns = headColumns
def setCaption(self, caption):
self.caption = caption
def setColumnAttr(self, columnAttribs=[]):
self.columnAttribs = columnAttribs
pass
import sys
sys.path.append("D:\\Workspace\\Python\\Lib")
import HtmlFunctions as Html
tb = Html.Table({'class':'sheetStyle'})
tb.bind(collectionsFee)
tb.setHeader([
'部门'
,'区域'
,'业务类型'
,'客户'
,'收费组'
,'联系人 | 电话'
,'Email'
,'地址'
,'合计金额'
,'备注' ])
tb.setCaption('-- 收费安排表 -- ')
print tb.toString()
#!phthon
#-*- coding:GBK -*-
# filename:HtmlFunctions.py
def _attr(attr = {}):
return ''.join([' %s="%s"' % (k,v) for k,v in attr.items()])
def _th(content, attr={}):
return "<TH%s>%s</TH>" % (_attr(attr),content)
def _td(content, attr={}):
return "<TD%s>%s</TD>" % (_attr(attr),content)
def _td_c(content, attr={}):
attr['align']='center'
return _td(content, attr)
def _td_l(content, attr={}):
attr['align']='left'
return _td(content, attr)
def _td_r(content, attr={}):
attr['align']='right'
return _td(content, attr)
def _td_money(mny, attr={}):
attr['align']='right'
return _td("%.2f" % mny, attr)
def _tr(cells=[], attr={}):
return "<TR%s>%s</TR>" % (
_attr(attr),
''.join(cells)
)
def _tb(rows=[]):
return "<TBODY>%s</TBODY>" % '\n'.join(rows)
def _table(tableInfos={}):
if tableInfos.has_key('attrib') and tableInfos['attrib'] > '':
attrib = tableInfos['attrib']
else:
attrib = ''
if tableInfos.has_key('caption') and tableInfos['caption'] > '':
caption = "<CAPTION>%s</CAPTION>" %s (tableInfos['caption'])
else:
caption = ''
if tableInfos.has_key('rows') and tableInfos['rows'] > '':
rows = tableInfos['rows']
else:
rows = ''
return "<TABLE%s>%s%s</TABLE>" % (attrib, caption, rows)
class Table:
def __init__(self, attrib={}):
self.headColumns = []
self.caption = ''
self.attrib = {}
self.data = []
pass
def toString(self):
caption = (self.caption == '') \
and '' \
or ('<CAPTION>%s</CAPTION>' % self.caption)
if len(self.headColumns) == 0:
headers = ''
else:
headers = "<THEAD>%s</THEAD>" % _tr(
''.join([_th(cell) for cell in self.headColumns]))
tbody = _tb([
( _tr(''.join([_td(cell) for cell in row])) )
for row in self.data
])
return "<TABLE%s>%s\n%s\n%s</TABLE>" % (
_attr(self.attrib),
caption,
headers,
tbody)
import sys
sys.path.append("D:\\Workspace\\Python\\Lib")
import HtmlFunctions as Html
tb = Html.Table()
tb.attrib = {'class':'sheetStyle'}
tb.caption = "-- 收费安排表 (Summit)--"
tb.headColumns = [
'部门'
,'区域'
,'业务类型'
,'客户'
,'收费组'
,'联系人 | 电话'
,'Email'
,'地址'
,'合计金额'
,'备注' ]
tb.data = collectionsFee
print tb.toString()