python读取MySQL数据存到一个Excel的多个sheet表里,并通过邮件发送

需求:
python读取MySQL数据存到一个Excel的多个sheet表里,并通过邮件发送
代码:

import pymysql
import xlwt
import datetime
from email.mime.multipart import MIMEMultipart
from email.header import Header
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
import smtplib

# 连接数据库
def conn_db():
	# 服务器ip
    host = '*.*.*.*'
    # 数据库端口号
    port = 3306
	# MySQL用户名
    user = 'root'
    # MySQL密码
    passwd = '密码'
    # 数据库名
    db = '数据库名'
    charset = 'utf8'
    conn = pymysql.connect(host=host, port=port, user=user, passwd=passwd, db=db, charset=charset)
    return conn

# 使用cursor()方法获取操作游标
def cursor_db():
    conn = conn_db()
    cursor = conn.cursor()
    return cursor

# 创建Excel
def create_excel():
    workbook = xlwt.Workbook(encoding='utf-8')
    return workbook

# 在Excel里创建第一张sheet表
def save_data1_to_excel(cursor,workbook):
    # 使用execute方法执行SQL语句,并将统计结果存储在effect_row变量中
    effect_row = cursor
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值