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
|
def extraire_siteclicked(self):
db = mysql.connector.connect(user='root', password='',
host='localhost',
database='bde01')
cur = db.cursor()
requete = ("SELECT * FROM site")
cur.execute(requete)
desc = cur.description
book = xlwt.Workbook(encoding="utf-8")
sheet1 = book.add_sheet("Python Sheet 1")
sheet1.write(0, 0, desc[0][0])
sheet1.write(0, 1, desc[1][0])
sheet1.write(0, 2, desc[2][0])
sheet1.write(0, 3, desc[3][0])
sheet1.write(0, 4, desc[4][0])
sheet1.write(0, 5, desc[5][0])
sheet1.write(0, 6, desc[6][0])
r =1
for i in range(cur.rowcount):
row = cursor.fetchone()
sheet1.write(r,0, row[0])
sheet1.write(r,1, row[1])
sheet1.write(r,2, row[2])
sheet1.write(r,3, row[3])
sheet1.write(r,4, row[4])
sheet1.write(r,5, row[5])
sheet1.write(r,6, row[6])
r +=1
fileName = QtGui.QFileDialog.getSaveFileName(self,"","",filter ="Excel (*.xls )")
book.save(fileName) |
Partager