Question

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
>>>
Was it helpful?

Solution 2

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

OTHER TIPS

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top