473,385 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PythonWin And Excel Problem

Hi All,

I am having some problems in running a very simple python script,
which prints some numbers in an Excel spreadsheet. The numbers are
stored in a list. I know that the numbers are different (random
generated), but when I open the Excel file I get a column of data with
all the numbers equal to the first item in the python list.
I attach a very simple script that reproduces the problem.

I am using Python 2.5, PythonWin build 210, Windows XP. Am I missing
something? Thank you for every hint.

import os
import random

from win32com.client import Dispatch

therand = []
for ii in xrange(10):
therand.append(random.random())

xlsapp = Dispatch("Excel.Application")
wb = xlsapp.Workbooks.Add()

xlsapp.Worksheets.Item(2).Delete()
xlsapp.Worksheets.Item(1).Delete()
sheet = wb.Sheets[0]
sheet.Name = "Data"
sheet.Range("A1:A10").Value = therand

excelfile = "C:/HelloWin32.xls"

wb.SaveAs(excelfile)
wb.Close()
xlsapp.Quit()

os.startfile(excelfile)
Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/
Dec 1 '06 #1
1 2048
"Andrea Gavana" <an***********@gmail.comwrote:
Hi All,

I am having some problems in running a very simple python script,
which prints some numbers in an Excel spreadsheet. The numbers are
stored in a list. I know that the numbers are different (random
generated), but when I open the Excel file I get a column of data with
all the numbers equal to the first item in the python list.
I attach a very simple script that reproduces the problem.

I am using Python 2.5, PythonWin build 210, Windows XP. Am I missing
something? Thank you for every hint.

import os
import random

from win32com.client import Dispatch

therand = []
for ii in xrange(10):
therand.append(random.random())

xlsapp = Dispatch("Excel.Application")
wb = xlsapp.Workbooks.Add()

xlsapp.Worksheets.Item(2).Delete()
xlsapp.Worksheets.Item(1).Delete()
sheet = wb.Sheets[0]
sheet.Name = "Data"
sheet.Range("A1:A10").Value = therand

excelfile = "C:/HelloWin32.xls"

wb.SaveAs(excelfile)
wb.Close()
xlsapp.Quit()

os.startfile(excelfile)
Each row you insert into the Range need to be a
sequence:

therand.append((random.random(),))

Roger


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: stephan | last post by:
Hi, I have python 2.2.3 + pythonwin 156 on win2k. The problem is that german chars like äöüÄÖÜß are not handled correctly. Just create a test.py file with the content äöüÄÖÜß and edit it with...
1
by: R.Marquez | last post by:
I uninstalled my 2.2.2 version of Python and related packages from my XP Professional station and proceeded to upgrade to the latest and greatest: Python2.3, win32all-155.exe, etc. When I try to...
0
by: quadric | last post by:
Hi, I am just getting into PythonWin. I need my application that has Python embedded within it to communicate with an Excel spreadsheet. I have done this manually with PythonWin. All works...
14
by: Jive | last post by:
I've un-installed Python 2.4, re-installed Python 2.3 and PythonWin for 2.3, but it's still broke. When I start PythonWin, sometimes it looks like it is going to be okay. But as soon as I open...
4
by: Chris P. | last post by:
I've been having a problem with PythonWin that seemed to start completely spontaneously and I don't even know where to START to find the answer. The only thing I can think of that marks the point...
2
by: accolades | last post by:
Does anyone else have a problem with Pythonwin crashing after running a python script with graphics libraries? Whenever I use Pythonwin to run a PyGame or PyOgre script, Pythonwin crashes when the...
14
by: Dan | last post by:
Just starting to do some windows Client / Server programming. Which would you recommend? I need to create a server to fire events and communicate with clients over a lan. Thanks
3
by: archaegeo | last post by:
I am getting started in Python, and I have looked on both the stackless page and python.org and cannot find the answer to what I think is a simple problem. If I start the python command line or...
4
by: sterling | last post by:
I'm curious as to why the difference between IDLE and pythonWin when using win32com. opening an excel file, i've attempted to grab the chart information out of the file. commands like co =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.