Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91521 > unrolled thread

Python write to spreadsheet?

Started byJustin Thyme <JustinThyme@nowhere.com>
First post2015-05-30 10:30 +0100
Last post2015-05-30 09:11 -0400
Articles 6 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  Python write to spreadsheet? Justin Thyme <JustinThyme@nowhere.com> - 2015-05-30 10:30 +0100
    Re: Python write to spreadsheet? Tim Golden <mail@timgolden.me.uk> - 2015-05-30 10:40 +0100
    Re: Python write to spreadsheet? Joel Goldstick <joel.goldstick@gmail.com> - 2015-05-30 07:03 -0400
    Re: Python write to spreadsheet? Laura Creighton <lac@openend.se> - 2015-05-30 13:15 +0200
    Re: Python write to spreadsheet? Tim Chase <python.list@tim.thechases.com> - 2015-05-30 07:24 -0500
    Re: Python write to spreadsheet? Pablo Lucena <plucena24@gmail.com> - 2015-05-30 09:11 -0400

#91521 — Python write to spreadsheet?

FromJustin Thyme <JustinThyme@nowhere.com>
Date2015-05-30 10:30 +0100
SubjectPython write to spreadsheet?
Message-ID<mkbvuu$udo$1@news.albasani.net>
Is it possible to write a Python program that will start MS Excel, 
create a spreadsheet and fill cells A1 to A10 (say) with the data in a 
Python array?  The answer is surely yes, but is there an outline of how 
to do it somewhere?
-- 
Shall we only threaten and be angry for an hour?
   When the storm is ended shall we find
How softly but how swiftly they have sidled back to power
   By the favour and contrivance of their kind?

 From /Mesopotamia/ by Rudyard Kipling

[toc] | [next] | [standalone]


#91523

FromTim Golden <mail@timgolden.me.uk>
Date2015-05-30 10:40 +0100
Message-ID<mailman.220.1432978847.5151.python-list@python.org>
In reply to#91521
On 30/05/2015 10:30, Justin Thyme wrote:
> Is it possible to write a Python program that will start MS Excel,
> create a spreadsheet and fill cells A1 to A10 (say) with the data in a
> Python array?  The answer is surely yes, but is there an outline of how
> to do it somewhere?


This is still a good place to start:

   http://www.python-excel.org/

but I know I've seen several other packages not mentioned there which 
either call Excel from Python or vice versa. xlwings (not sure?)

TJG

[toc] | [prev] | [next] | [standalone]


#91524

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2015-05-30 07:03 -0400
Message-ID<mailman.221.1432983782.5151.python-list@python.org>
In reply to#91521
On Sat, May 30, 2015 at 5:40 AM, Tim Golden <mail@timgolden.me.uk> wrote:
> On 30/05/2015 10:30, Justin Thyme wrote:
>>
>> Is it possible to write a Python program that will start MS Excel,
>> create a spreadsheet and fill cells A1 to A10 (say) with the data in a
>> Python array?  The answer is surely yes, but is there an outline of how
>> to do it somewhere?
>
>
>
> This is still a good place to start:
>
>   http://www.python-excel.org/
>
> but I know I've seen several other packages not mentioned there which either
> call Excel from Python or vice versa. xlwings (not sure?)
>
> TJG
> --
> https://mail.python.org/mailman/listinfo/python-list

This looks promising:
http://www.dev-explorer.com/articles/excel-spreadsheets-and-python


-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#91525

FromLaura Creighton <lac@openend.se>
Date2015-05-30 13:15 +0200
Message-ID<mailman.222.1432984537.5151.python-list@python.org>
In reply to#91521
I use this:
https://pypi.python.org/pypi/xlutils

Documentation here:
http://pythonhosted.org/xlutils/

website full of advice here:
http://www.python-excel.org/

Tutorial I took at Europython where I learned a lot of stuff
http://www.simplistix.co.uk/presentations/python-excel.pdf

Laura

[toc] | [prev] | [next] | [standalone]


#91531

FromTim Chase <python.list@tim.thechases.com>
Date2015-05-30 07:24 -0500
Message-ID<mailman.226.1432990967.5151.python-list@python.org>
In reply to#91521
On 2015-05-30 10:30, Justin Thyme wrote:
> Is it possible to write a Python program that will start MS Excel, 
> create a spreadsheet and fill cells A1 to A10 (say) with the data
> in a Python array?  The answer is surely yes, but is there an
> outline of how to do it somewhere?

it depends on how strictly you want to keep your order of operations.

You *can* use Windows API calls to automate Excel, instructing it to
create a new sheet, then populate the various cells with data.
However, this is fragile, Windows-specific, and requires the target
to have Excel on their machine.

If you're willing to forego your specified ordering and create a
file, then open it in Excel, you can use the add-on xlrd/xlwt packages
(the former reads, the latter writes) to write XLS files that you can
then open in Excel.

Finally, if you're going down that route, the *easiest* way is to
simply use Python's csv module from the standard library.

  import csv
  FILENAME = "out.csv"
  with open(FILENAME, 'wb') as f:
    w = csv.writer(f)
    for item in data:
      w.writerow([
        item,
        #, ""  # optionally add a blank column because
               # some parsers like csv.Sniffer will notice
               # the lack of commas and try to find the most
               # common repeated string
        ])

You can then launch that file in Excel, or even better, whatever the
registered program is:

  import os, sys, subprocess
  def open_file(filename):
    if sys.platform == "win32":
      os.startfile(filename)
    else:
      if sys.platform == "darwin":
        program = "open"
      else:
        program = "xdg-open"
      subprocess.call([program, filename])
  open_file(FILENAME)

-tkc


[toc] | [prev] | [next] | [standalone]


#91535

FromPablo Lucena <plucena24@gmail.com>
Date2015-05-30 09:11 -0400
Message-ID<mailman.227.1432994435.5151.python-list@python.org>
In reply to#91521

[Multipart message — attachments visible in raw view] — view raw

Try openpyxl - I've found this to be a really nice library for interacting
with MS Excel.

On Sat, May 30, 2015 at 5:30 AM, Justin Thyme <JustinThyme@nowhere.com>
wrote:

> Is it possible to write a Python program that will start MS Excel, create
> a spreadsheet and fill cells A1 to A10 (say) with the data in a Python
> array?  The answer is surely yes, but is there an outline of how to do it
> somewhere?
> --
> Shall we only threaten and be angry for an hour?
>   When the storm is ended shall we find
> How softly but how swiftly they have sidled back to power
>   By the favour and contrivance of their kind?
>
> From /Mesopotamia/ by Rudyard Kipling
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
*Pablo Lucena*

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web