-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_tag_excel.py
44 lines (35 loc) · 1.05 KB
/
generate_tag_excel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# encoding:utf8
import sys
import pymysql
import xlsxwriter
reload(sys)
sys.setdefaultencoding('utf-8')
class DBHandle(object):
def __init__(self,host="localhost",user="root",password="new_password",database="wsalon",debug=0):
db = pymysql.connect(host,user,password,database,charset="utf8")
self.db = db
def execute_sql(self,sql):
cursor = self.db.cursor()
cursor.execute(sql)
results = cursor.fetchall()
return results
def dbclose(self):
self.db.close()
def main():
dbh = DBHandle()
try:
results = dbh.execute_sql("select id,name from app_tag order by id asc")
workbook = xlsxwriter.Workbook('tag.xlsx')
worksheet = workbook.add_worksheet("salon_tag_name")
# Start from the first cell below the headers.
row = 1
col = 0
for item in results:
name = item[1]
worksheet.write(row,col,name);
row += 1
workbook.close()
finally:
dbh.dbclose()
if __name__ == '__main__':
main()