下面是我为获得结果的html str而编写的代码。需要加粗的html头

2024-06-26 08:21:07 发布

您现在位置:Python中文网/ 问答频道 /正文

def gen_table(Header,Tuple,HeaderColor='#c8f98e',WeekendColor='#e9fcd0',Weekendflag=1,bcolor=[],opt="center"):
        html_str=''
        found_list = []
        color1 = "white"
        if Tuple:
                if Header:
                        html_str+='\n<table border=1>\n'
                        if type(Header)==list:
                                html_str+='<tr bgcolor="'+str(HeaderColor)+'">\n'
                                for value in Header:
                                        html_str+='<th align="'+opt+'">'+str(value)+'</th>\n'
                                html_str+='</tr>\n'
                        else:
                                for value in Header:
                                        html_str+='<tr bgcolor="'+str(HeaderColor)+'" align="'+opt+'">\n'
                                        for col in value:
                                                html_str+=tbody(col,b='True')
                                        html_str+='</tr>\n'
                dic = find(Tuple)
                for rows in Tuple:
                        if Weekendflag:
                                if type(rows[0])==datetime.date and rows[0].weekday() in (6,5,) :
                                        html_str+="<tr bgcolor='"+str(WeekendColor)+"' align='"+opt+"'>\n"
                                else:
                                        html_str+='\n<tr bgcolor="'+str(color1)+'" align="'+opt+'">\n'
                        else:
                                html_str+='\n<tr bgcolor="'+str(color1)+'" align="'+opt+'">\n'
                        for i in range(len(rows)):

                                if len(rows)<=1:
                                        html_str+="<b><td colspan=11 rowspan=1 bgcolor='"+str(WeekendColor)+"'>%s</td></b>\n"%rows[i]
                                elif dic.has_key(rows[i]) and rows[i] not in found_list:
                                        found_list.append(rows[i])
                                        html_str+="<td colspan=1 rowspan=%s>%s</td>\n" %(dic[rows[i]],rows[i])
                                elif rows[i] not in found_list:
                                        html_str+=tbody(rows[i],HeaderColor,bcolor,i)
                        html_str+='</tr>\n'
                html_str+='</table>'

        else:
                html_str+='---NO DATA---'

在这里,我需要得到标题单独在粗体。我在那部分加了<b> </b>,但是我不能。。有人能帮我吗?你知道吗


Tags: inforifhtmltrlistrowsheader