PYTHON + EXCEL

D

dan84

I write my code :
#inizializzazioni varie che tralascio


#mi connetto al mio db mysql e recupero i dati che volgio inserire
nel file excel
conn = MySQLdb.connect(host = "XXX", port = XXX, user = "XXX",
passwd = "XXX", db= "XXX")
cursor = conn.cursor()
cursor.execute("SELECT * FROM XXX")
allFields = cursor.description
allRecords = cursor.fetchall()
cursor.close()
conn.close()


#inizializzo gli strumenti per lavorare in python con excel
xlApp = Dispatch("Excel.Application")
#xlApp.Visible = 1
xlApp.Workbooks.Add()


#specifico che file utilizzare
xlbook = xlApp.Workbooks.Open('C:/view.xls')
i = 1
j = 1


#popolo il mio file excel
for field in allFields :
xlApp.ActiveSheet.Cells(i, j).Value = field[0]
j = j + 1
for records in allRecords :
i = i + 1
j = 1
for item in records :
xlApp.ActiveSheet.Cells(i, j).Value = item
j = j + 1
#salvo le modifiche effettuate
xlbook.SaveAs('C:/view.xls')


#scrivo le istruzioni che mi permettereanno di aprirlo in una
pagina html
size = os.path.getsize('C:/view.xls')
of = open("C:/view.xls","rb")
content = of.read()
of.close()


print"Content-Type:application7vnd.ms-excel"
print"content-disposition:inline;filename=view.xls"
print"Content-length:%d \r\n"%size
print content







I want open an excel document in an apache page.
I want write in excel document the information of a database mySQL and
after open the excel documen in a broswer page
Where is the problem?
Sorry for my english but I'm not speak english very well, I write in
this group because I think that in this forum there are very very good
programmer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top