python邮件发送正文-富文本


import xlrd
import datetime

class _WriteExcel(object):
    def __init__(self):
        self.style_0 = xlwt.easyxf('font: bold on, color-index red, height 300;')
        self.style_1 = xlwt.easyxf('pattern: pattern solid, fore_colour green; font: height 300;')
        # 实例化句柄
        self.workbook = xlwt.Workbook(encoding='utf-8')
        self._add_sheet()

    def _add_sheet(self):
        self.sheet = self.workbook.add_sheet('爬虫监控概要', cell_overwrite_ok=True)

        # 列宽

        self.sheet.col(0).width = 256 * 20
        self.sheet.col(1).width = 256 * 20
        self.sheet.col(2).width = 256 * 20
        self.sheet.col(3).width = 256 * 20

    def write_head(self, row, column, value):
        self.sheet.write(row, column, value, self.style_0)

    def write_content(self, row, column, value):
        self.sheet.write(row, column, value, self.style_1)

    def save(self, file_name):
        self.workbook.save(file_name)

    def _make_html(self, file_name):
        """
        以行进行操作
        :param file_name:
        :return:
        """
        now = datetime.datetime.now().strftime('%Y-%m-%d')
        exc_data = xlrd.open_workbook(file_name)
        sheet = exc_data.sheet_by_index(0)
        nrows = sheet.nrows  # 表的行数

        tr = ""
        for i in range(1, nrows):  # 每一行 按单元格处理
            one_row_value = sheet.row_values(i)
            tip = ""
            for index, each_value in enumerate(one_row_value):
                if isinstance(each_value, float):
                    each_value = str(int(each_value))
                if index == 1 or index == 2:  # 第二列 > 0 高亮显示
                    if int(each_value) > 0:
                        tip = tip + "<td bgcolor=#00FF00>" + each_value + "</td>"
                    else:
                        tip += "<td>" + each_value + "</td>"
                else:
                    tip += "<td>" + each_value + "</td>"
            tr += "<tr>" + tip + "</tr>"
        table_header = '<table border="1" cellspacing="0" cellpadding="3" bordercolor="#000000">' \
                       '<caption>' \
                       '%s媒资发布端统计' \
                       '</caption>' % now
        table_part1 = '<tr bgcolor="#FFFF00" align="left">' \
                      '<th>媒资类型</th>' \
                      '<th>今日下载媒资</th>' \
                      '<th>今日发布媒资</th>' \
                      '<th>媒资发布总量</th>' \
                      '</tr>'
        html = "<html><h4>发布端媒资统计!</h4><body>'" + table_header + table_part1 + tr + "</table> </body></html>"

        return html



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值