PYTHON + EXCEL

Discussion in 'Python' started by dan84, Nov 14, 2006.

  1. dan84

    dan84 Guest

    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
    dan84, Nov 14, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmltIEhlYXZleQ==?=

    Excel _WorkBook vs. Excel.Workbook

    =?Utf-8?B?SmltIEhlYXZleQ==?=, Sep 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,633
    Steve C. Orr [MVP, MCSD]
    Sep 29, 2004
  2. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,379
    Carl Prothman [MVP]
    Jan 12, 2005
  3. =?Utf-8?B?U3JpZGhhcg==?=

    using Microsoft Excel image for Export to Excel button

    =?Utf-8?B?U3JpZGhhcg==?=, Dec 9, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    3,098
    =?Utf-8?B?U3JpZGhhcg==?=
    Dec 9, 2005
  4. zxo102
    Replies:
    3
    Views:
    3,257
    Stuart Corrie
    Aug 9, 2005
  5. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,495
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
Loading...

Share This Page