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 3 3560
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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"...
|
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...
|
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...
|
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...
|
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...
|
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 &...
|
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 , ,...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |