By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,097 Members | 1,529 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,097 IT Pros & Developers. It's quick & easy.

Set Excel cell to a value using Python

Elias Alhanatis
P: 56
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!!!
Mar 18 '08 #1
Share this Question
Share on Google+
3 Replies

P: 75
could you please show us how have you opened this excel form...
Mar 19 '08 #2

P: 43
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.
Mar 19 '08 #3

Elias Alhanatis
P: 56
Hello friends!

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

With that code , i get an error like:
....lines ommited
File "C:\Python25\lib\site-packages\win32com\client\" , 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!
Mar 21 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.