直接访问fzdxwz
#! /usr/bin/python
#-* -编码: utf-8-* -
import mysql.connector
来自文档导入文档
db='targetDB '
host='localhost '
user='username '
password='password '
端口=3306
conn=MySQL.connector.connect (host=host,user=user,passwd=password,db=db,port=port ) ) ) ) )
sql='select table_name,table _ commentfrominformation _ schema.tableswheretable _ schema=' { } '.format (
文档=文档(
for(table_name,table_comment ) in cursor.fetchall ) ) :
document.add _ heading (table _ name,level=1) )。
document.add _ paragraph (table _ comment )
table=document.add _ table (rows=1,cols=3,style='Table Grid ' ) ) ) ) ) ) ) ) ) ) ) )
hdr_cells=table.rows[0].cells
hdr_cells[0].text=u '字段'
hdr_cells[1].text=u '类型'
hdr_cells[2].text=u '说明'
for(field,type,_,_,_,_,_,_,_,_,_,comment ) in cursor.fetchall ) :
row_cells=table.add_row ().cells
row_cells[0].text=field
row_cells[1].text=type
row_cells[2].text=comment
document.save(db.docx ) )。