473,545 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Embedding objects( txt, doc) into excel using python

Hi,

I want to embed a txt document into an excel using python.

Here is my code, but i get an error message
=============== =============== =============== ======
Traceback (most recent call last):
File "C:\Documen ts and Settings\kusuma p\Desktop\Giris h.py", line 7,
in ?
worksheet.OLEOb jects.Add(Filen ame="C:\Documen ts and Settings
\kusumap\My Documents\deskt op.ini", Link=False,Disp layAsIcon=True,
IconFileName="p ackager.exe", IconIndex=0, IconLabel="C:\D ocuments and
Settings\kusuma p\My Documents\deskt op.ini").Select
AttributeError: 'function' object has no attribute 'Add'
=============== =============== =============== ======

import win32com.client
ExcelApp = win32com.client .Dispatch("Exce l.Application")
ExcelApp.visibl e = 1
workbook = ExcelApp.Workbo oks.open("C:\So ftware\New Microsoft Excel
Worksheet.xls")
worksheet = workbook.Active sheet
#worksheet.OLEO bjects.Add(File name="C:\Docume nts and Settings\p\My
Documents\desk. txt", Link=False,Disp layAsIcon=True,
IconFileName="p ackager.exe", IconIndex=0, IconLabel="C:\D ocuments and
Settings\p\My Documents\desk. txt").Select

Can anyone please whtz the problem with the code and how to overcome
the same.

Thanks
Girish S

May 31 '07 #1
1 4749
Girish wrote:
I want to embed a txt document into an excel using python.
I didn't know people still did that! Still, each to
his own ;)
Here is my code, but i get an error message
=============== =============== =============== ======
Traceback (most recent call last):
File "C:\Documen ts and Settings\kusuma p\Desktop\Giris h.py", line 7,
in ?
worksheet.OLEOb jects.Add(Filen ame="C:\Documen ts and Settings
\kusumap\My Documents\deskt op.ini", Link=False,Disp layAsIcon=True,
IconFileName="p ackager.exe", IconIndex=0, IconLabel="C:\D ocuments and
Settings\kusuma p\My Documents\deskt op.ini").Select
AttributeError: 'function' object has no attribute 'Add'
=============== =============== =============== ======
Well done for providing reproducible code, by the way.
It's amazing how many people expect us to deduce code
from tracebacks! Two things:

1) You need to use raw strings for your path names
or to double-up the slashes. By good fortune, you
don't seem to be using any actual special characters
(\n, \r, \t etc.) but you won't always be so lucky!

2) As the error suggests, OLEObjects is in fact a method,
not an container. Slightly more concise screen dump:

<dump>
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright" , "credits" or "license" for more
information.
>>import win32com.client
xl = win32com.client .Dispatch ("Excel.Applica tion")
ws = xl.Workbooks.Ad d ().ActiveSheet
print repr (ws.OLEObjects)
<bound method _Worksheet.OLEO bjects of
<win32com.gen_p y.Microsoft Excel 11.0 Object
Library._Worksh eet instance at 0x24646440>>
>>>
o = ws.OLEObjects ()
o
<win32com.gen_p y.Microsoft Excel 11.0 Object
Library.OLEObje cts instance at 0x24648240>
>>o.Add
<bound method OLEObjects.Add of <win32com.gen_p y.Microsoft
Excel 11.0 Object Library.OLEObje cts instance at 0x24648240>>
>>>
</dump>

As you can see, the ws.OLEObjects is a bound method,
ie a function within the _Worksheet class. It seems
to return a value which is an OLEObjects instance,
which itself seems to have an .Add method. Although
I could forage in the docs, I just tried it out at
the interpreter. You can do the same if you want!

TJG
May 31 '07 #2

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

Similar topics

3
6289
by: Luke | last post by:
does anybody know anything about pythons ability to act as a wrapper for C#? I'm having a hard time finding out about this. Any clues are appreciated.
4
2764
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been working with Python for a year or more now, but only doing simple extending in C/C++. I'm now attempting some embedding and several questions have come...
0
1110
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded application running on Solaris. Python will enable end users to customize and re-program many aspects of the application. I expect that the C++ application will be natively multi-threaded and will embed multiple Python sub-interpreters. Called Python scripts may in turn call back into the...
0
1318
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application runnig on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird behaviors). Can anyone clarify: - if Python correctly supports multiple sub-interpreters (Py_NewInterpreter) ?
0
1415
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application runnig on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird behaviors). Can anyone clarify:
1
1899
by: amit | last post by:
Hello, I am currently studying how to embedd python. I am developing a graphical C++ application. My goal is to embedd python script that will control some kind of animation. I have some questions about python embedding: 1) Is there a good text book or other resource on embedding/extending? (I find it hard to learn only by the tutorial...
1
1815
by: Tommy Nordgren | last post by:
I want to write an application that embeds and extends (at least) the Python and Perl interpreters. Now i want to find as much as possible about the Python tools used for extending and embedding Python. To be more specific: My app should: 1. Parse an input file. 2. Call a script in some scripting language, to generate an output file, for...
8
1810
by: Thomas Bartkus | last post by:
Name: lib64python2.4-devel Summary: The libraries and header files needed for Python development Description: The Python programming language's interpreter can be extended with dynamically loaded extensions and can be embedded in other programs. This package contains the header files and libraries needed to do these types of tasks....
1
1832
by: Kakacek | last post by:
Hello All, Let's say I have a following python code: class hw_class: def __init__(self): pass def hello_world(self): print 'Hello World!' create_instance('hw_class', 'hw')
1
2114
by: Johannes Zellner | last post by:
Hello, when embedding python: how can I create a type which simulates item getters and setters? Something like this: void setter(PyObject* self, int i, PyObject new_value) { // do something }
0
7406
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7813
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7761
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5976
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5337
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3457
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1888
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
709
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.