The Artima Developer Community
Sponsored Link

Python Answers Forum
export a python script to a spreadsheet

2 replies on 1 page. Most recent reply: Aug 23, 2006 9:02 AM by Paul McNett

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
James Hansford

Posts: 1
Nickname: pollenpy30
Registered: Jun, 2006

export a python script to a spreadsheet Posted: Jun 30, 2006 2:30 AM
Reply to this message Reply
Advertisement
Hi,

I've written a module that, when run in IDLE, gives a list of numbers, each number being on a new line. I want the numbers to go into a new cell in a spreadsheet everytime. Can I do this?

As you might gather, I'm quite new to programming.

cheers.


Robert Marchetti

Posts: 1
Nickname: pamie
Registered: Jul, 2006

Re: export a python script to a spreadsheet Posted: Jul 10, 2006 7:50 AM
Reply to this message Reply
Here is a simply example to get you going

from win32com.client import DispatchEx

# Create an excel Object
xls = DispatchEx("Excel.Application")

# Make the object visible (launch Excel)
xls.Application.Visible = True

# Add a new workbook and sheet
xls.Workbooks.Add()
xls.Sheets ( "Sheet1" ).Select()

# input the number "20" in row 1 col 1
num = "20"
xls.ActiveSheet.Cells(1,1).value = num

Paul McNett

Posts: 1
Nickname: pmcnett
Registered: Dec, 2005

Re: export a python script to a spreadsheet Posted: Aug 23, 2006 9:02 AM
Reply to this message Reply
Or, if Excel isn't installed, you aren't on Windows, you want to use some other spreadsheet, you don't have win32all installed, etc. etc., you can more simply export your data to CSV format, which all spreadsheet programs on all platforms can certainly import.


[python]
import csv
data = [["name", "favorite_number"], ["paul", 22], ["denise", 17]]
csv.writer(open("temp.csv", "wb"), quoting=csv.QUOTE_ALL).writerows(data)
[/python]

Flat View: This topic has 2 replies on 1 page
Topic: SQLAlchemy problem : / Previous Topic   Next Topic Topic: Multithreaded Service

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use