-2

I have a requirement where using Python I need to write into excel cell , the data which i will be collecting from web page.

But not getting an option how to do that.

any idea from you people?

As per @Marcin comments here is the more clear requirement I am looking for

Why is python a requirement? -> Yes I am using Python with Beautiful Soup module to fetch data from web page.

Where is excel running, or is it running at all? -> Excel is needed when a script would complete its data collection from the web page,and will take an attempt to the next page to do the same tasks,I want the current data to be saved into an excel format.

How is this related to the web? What exactly are you trying to achieve? Hope this answer is given to the above question of your.

Could you just work with a CSV file? Yes,I can work with it,but my final goal is to push the data back to an database,which could be an Oracle or Access database.

Architecture

                 ------------------
                |       web        |
                |       page       |
                 ------------------
                          |
                          |
                          |
            Python and BS4(Data Extraction)
                          |
                          |
                          |
                 ------------------                               
                |       Excel      |
                |       data       |
                 ------------------
                          |
                          |
                          |
             Python to Push Data(Oracle/Access)
                          |
                          |
                          |
                 ------------------
                |       Any        |
                |       DB         |
                 ------------------

EDIT

As per @Thang

I have tried but getting the error:

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Happy>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32com.client
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named win32com.client
>>>
Zero Piraeus
  • 56,143
  • 27
  • 150
  • 160
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
  • 3
    Yes? Have you come across: http://www.python-excel.org/ (look at the `xlwt` module) – Jon Clements Jan 05 '13 at 18:53
  • http://stackoverflow.com/questions/441758/driving-excel-from-python-in-windows duplicate – Paul Collingwood Jan 05 '13 at 18:53
  • @JonClements i did, but all are written as `NC`. so confused I am! – Arup Rakshit Jan 05 '13 at 18:57
  • This is far too broad. Why is python a requirement? Where is excel running, or is it running at all? How is this related to the web? What exactly are you trying to achieve? Could you just work with a CSV file? I will vote to close, and strongly recommend that you write a clearer and more focused question. – Marcin Jan 05 '13 at 19:16
  • @Marcin Yes,I am doing web scraping with python tool. so what the data I am going to read by my scripts, finally I would like to save them into a excel sheet. Thus I post here. If you have any idea please share. please don't vote for close it. It is needed. – Arup Rakshit Jan 05 '13 at 19:39
  • 1
    @PythonLikeYOU Please put the requested information in your question. – Marcin Jan 05 '13 at 19:41
  • 3
    If your final requirement is to put an RDMS/Access then errr, why Excel in an interim? – Jon Clements Jan 05 '13 at 20:10
  • @JonClements this is a temporary data container,while my script would collect data from multiple pages from business websites, and that data is huge, for the scripts one run.once all the data collections will be completed then final push to any database will be completed! – Arup Rakshit Jan 05 '13 at 20:14
  • 1
    It's still too vague to given any reasonable advice - but that sounds like a very bad idea - even just store to a sqlite3 database and then bulk upload that via a pipeline of some sorts... But sorry, I'll bow out here for this question as it stands – Jon Clements Jan 05 '13 at 20:39
  • I just updated the description – Arup Rakshit Jan 06 '13 at 11:14
  • 1
    @PythonLikeYOU: Seconding the most recent comment by Jon Clements: Using an Excel spreadsheet as a temporary container for a "huge" amount of data is NOT a very good idea at all. Use an sqlite3 database instead. Nothing extra to download -- see http://docs.python.org/2/library/sqlite3.html – John Machin Jan 07 '13 at 21:10

4 Answers4

3

You have a few options, actually, depending on what exactly you're trying to do.

xlwt - I think this is great for manipulating Excel files from Python. I've linked you to the documentation. DataNitro - for Python scripting from within Excel. It's a little slow, but I've used it plenty. You are able to (with VBA in general) have Excel make a web request and pull in a table. Before I knew how to program, that was how I did all of my web scraping.

jdotjdot
  • 16,134
  • 13
  • 66
  • 118
1

For Office 2007 and up the APIs are .Net, so you could use either Python for .Net or IronPython.

Thang mentioned pywin32, and that will work for Office 2007 and up and older versions as well.

Josh Heitzman
  • 1,816
  • 1
  • 14
  • 26
1

Give OpenPyXL a try if you are doing Office 2007 excel (aka xlsx files)

kostia
  • 6,161
  • 3
  • 19
  • 23
  • I am not getting an installable files to download,like `xlread` other python packages. So please guide me here! – Arup Rakshit Jan 05 '13 at 19:57
  • Can you help me by saying from where to download the package with python2.7. As I am not finding any downloadable package from the lin you have provided. – Arup Rakshit Jan 06 '13 at 05:31
1

If you merely need to be able to use the data in Excel, save it in csv format, using the csv module.

If you need to directly produce an Excel format file (and I can think of no reason you should, as you have not said that you are receiving excel files), you can use one of the third party modules mentioned in other answers.

Update: Using CSV will not prevent you from putting the data in a database; likewise, if you want to put the data in a database, Excel will not especially assist you. A much better approach would be to simply keep your data in memory, and write it to the database once complete. If you need intermediate storage, use another database.

Marcin
  • 48,559
  • 18
  • 128
  • 201
  • I just updated my description, Please have a look into it. If any more you want , I will share you! but please not down vote. – Arup Rakshit Jan 05 '13 at 19:54