473,804 Members | 4,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Default location while open an Excel file

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

doc = win32com.client .Dispatch("Exce l.Application")
doc.Workbooks.O pen(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
3 3595
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.abspat h(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


On Oct 20, 11:24 am, Gabriel Genellina <gagsl...@yahoo .com.arwrote:
At Friday 20/10/2006 00:08, Johnny wrote:
doc.Workbooks.O pen(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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6391
by: Lize | last post by:
Hi, I'm writing an ASP application to open an excel workbook, then run a macro stored in the excel file, which produces outputs that will be displayed back onto my ASP application. Now the problem I'm having is whenever I try to open a workbook (of any format, i.e. 97/2000, 95, or xp, and of any size, and with or without macros), excel just hangs forever, and if I killed the excel application in task manager, my asp application will...
4
2176
by: Pieter | last post by:
Hi, From my VB.NET 2005 application I need to be able to open Files an Directory's with their default application: - A word-doc must open in word - A excell-document in Excel etc - in case it's a folder it must open the Folder No problem there, but when I want to open a file without extension, that hasn't offcourse a default application, I'm getting an error. I'd prefer to
13
13259
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel" HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=ABC.xls") HttpContext.Current.Response.Write(strHTML) HttpContext.Current.Response.End() However when the user tries to save it the Default File Type is Web Page(*.htm; *.html)
1
12142
by: himanibhagwat | last post by:
Hi All, In a .NET windows application using C#, I'm opening an existing excel worksheet using office interop, where in I get Excel.Application object, Workbook object etc. I want to set the default orienation to Landscape while this worksheet will be printed by user. I searched around a lot!! But din't find any object with which orientation property can be set to landscape through code. Here is the piece of code used for opening the xls...
2
11002
by: vbaDev | last post by:
Hi. I am using Access 2000 and in my code I'm exporting a table into an Excel file (creating it), then the code needs to export another query into the same file (a new worksheet). So I needed both a "Save As" dialog and the ability to grab the filepath so that the second export appends to it. Anyway, I found Microsofts method and it works, except that I can't figure out how to populate the File Name box in the Dialog with a default name (say,...
8
7849
by: T. Crane | last post by:
Hi, How is the default path chosen in this instance: myFile = file('test.txt','w') Here I'm opening/creating a file but I have not specified the exact path, so how does Python determine where to 'put' this file? More to the point, how do I change what the default path is? Right now it's a networked drive that should not be getting my Python clutter.
22
68852
by: robertgregson | last post by:
Using C#, .NET3.5, Visual Studio 2008 and WCF on Windows VISTA SP1, I have written a service, service host (as a C# console application) and a client. The service uses Microsoft.Office.Interop.Excel.Application to access an Excel file on the local hard drive, opens it (using Application.Workbooks.Open), reads out some data and the provides said data to the client. Everything works perfectly when the Service Host is a C# console...
4
6238
by: David | last post by:
Hi I'm using this code to import data from an excel spreadsheet: DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel9, "tblStudents", _ "\\Egusersrv\Staff - Shared Work\PE Teach & Report\Imported Spreadsheets/ImportStudents.xls", True Which works fine if the spreadsheet is always in the pre-defined location. Ideally what I would prefer to do is have the user locate
0
1420
by: shaif | last post by:
Hello Friends, I am facing a problem to create PDF from excel to specific location by using Adobe PDF Printer ib VB. I used code: Dim xlbook As Excel.Workbook . . . . xlbook.PrintOut , , 1, 0, "Adobe PDF", True, True, "C:\Test.pdf"
0
9710
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9589
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10340
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7626
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5527
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3000
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.