Set Excel cell to a value using Python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Elias Alhanatis
    New Member
    • Aug 2007
    • 56

    Set Excel cell to a value using Python

    Hello everybody!!!

    I have made an application using python and wxpython , and now i want to
    print some statistics through my application. I have prepared an Excel form
    to fill with the statistics , and i have succeded in opening this 'form' from python.
    My problem is that i cannot go on from that point , to set some of the cells in this
    'form' to the values i need.
    I have used some snippets from various sites but they did not work.
    I need help only on this simple point: How to set a cell of an opened excel file to a certain value.

    Any code , or initial 'guidence' will be helpfull!!
    Thank you all in advance!!!
  • dazzler
    New Member
    • Nov 2007
    • 75

    #2
    could you please show us how have you opened this excel form...

    Comment

    • elcron
      New Member
      • Sep 2007
      • 43

      #3
      I believe their is a module to read and write excel files but you could always just save it as a CSV file (comma separated values) and write a quick reader for it.

      Comment

      • Elias Alhanatis
        New Member
        • Aug 2007
        • 56

        #4
        Hello friends!

        One of the scripts i used to do what i want was:
        Code:
        # -*- coding: cp1253 -*-
        
        from win32com.client import Dispatch
        xlApp = Dispatch ("Excel.Application")
        xlWb = xlApp.Workbooks.Open ("C:\\Python25\\Misthos.xlsx")
        xlSht = xlWb.Worksheets (1)
        
        xlSht.Cells(1,2).Value="Elias"
        xlSht.Cells(2,2).Value="Ηλιας"
        ( i Work on Excel 2007 & Vista )

        With that code , i get an error like:
        ....lines ommited
        File "C:\Python25\li b\site-packages\win32c om\client\__ini t__.py" , line 448 in _ApplyTypes
        dispid, 0, wFlags, retType, argType, *args),
        com_error: ( -2147352573, 'Member not found.', None, None)

        I've tried also the same snippet on windows XP with Excel 2007 and it
        actually worked....

        Any suggestions?

        Thank you all in advance!

        Comment

        Working...