By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,551 Members | 1,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,551 IT Pros & Developers. It's quick & easy.

Default location while open an Excel file

P: n/a
Hi,
As you know, I can use this to open an Excel file:
"""
import win32com.client

doc = win32com.client.Dispatch("Excel.Application")
doc.Workbooks.Open(excelFile, ReadOnly=True)
"""

But the problem is when I only pass the filename to the Open()
method, and of course the file is in the current directory, it will
throw an exception that the specified file can't be found. When I use
os.path.abspath(excelFile) instead, it works. But I do know that
somebody can only pass a filename, and no exception is raised. Now I
wonder is that because the "somebody" happen to put the file on the
default location of the Open() method? If so, does any one know the
default location?

Thanks for your consideration.

Regards,
Johnny

Oct 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
At Friday 20/10/2006 00:08, Johnny wrote:
>doc.Workbooks.Open(excelFile, ReadOnly=True)

But the problem is when I only pass the filename to the Open()
method, and of course the file is in the current directory, it will
throw an exception that the specified file can't be found. When I use
os.path.abspath(excelFile) instead, it works. But I do know that
somebody can only pass a filename, and no exception is raised. Now I
wonder is that because the "somebody" happen to put the file on the
default location of the Open() method? If so, does any one know the
default location?
Why don't you want to use an absolute path? It's safe, will always
work... What if Excel, for whatever reason, decides to start the Open
dialog pointing to another location? What if your script does not
have permission to write on such location?
--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ˇgratis!
ˇAbrí tu cuenta ya! - http://correo.yahoo.com.ar
Oct 20 '06 #2

P: n/a


On Oct 20, 11:24 am, Gabriel Genellina <gagsl...@yahoo.com.arwrote:
At Friday 20/10/2006 00:08, Johnny wrote:
doc.Workbooks.Open(excelFile, ReadOnly=True)
But the problem is when I only pass the filename to the Open()
method, and of course the file is in the current directory, it will
throw an exception that the specified file can't be found. When I use
os.path.abspath(excelFile) instead, it works. But I do know that
somebody can only pass a filename, and no exception is raised. Now I
wonder is that because the "somebody" happen to put the file on the
default location of the Open() method? If so, does any one know the
default location?Why don't you want to use an absolute path? It's safe, will always
work... What if Excel, for whatever reason, decides to start the Open
dialog pointing to another location? What if your script does not
have permission to write on such location?
Yes, I agree and willing to use abstract path. I only wonder what's
happending inside this method so that I can get more understanding of
the problem caused by passing an relative path in. :)

Regards,
Johnny

Oct 20 '06 #3

P: n/a
Try this:
>>import os
os.getcwd()
'C:\\Python24'

I ran it from the interpreter. Dunno what it does from a script in an
arbitrary location. YMMV.

Cheers,
Cliff

Oct 24 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.