Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pathname fails in twapi+Excel

89 views
Skip to first unread message

elsup...@gmail.com

unread,
Sep 28, 2017, 1:05:53 PM9/28/17
to
I have a TCL script which reads a CSV file containing temperature and humidity data, uses TWAPI to open an Excel file, write the data into a new sheet, create a plot of the data and then save it all.
The script worked yesterday morning and for months before that but this morning, with no change in the script, TWAPI (or whatever) can't find the .xlsx file because somehow it has mangled the name by removing the last / in the pathname.
The script should open the file "C:/Users/Peter/Documents/CPAP/CPAP_plots.xlsx" but I get this error message:

Exception occurred. Sorry, we couldn't find C:\//Users/Peter/Documents/CPAPCPAP_plots.xlsx. Is it possible it was moved, renamed or deleted?

As you can see from the CPAPCPAP, it has lost the intervening /. The TCL "open" command has no problem opening the .xlsx file with the same pathname so it appears to be something in TWAPI.
I copied the .xlsx file up one directory level and changed the path name to "C:/Users/Peter/Documents/CPAP_plots.xlsx" but it still fails in a similar way.
The script below demos the problem.
I have a workaround for it which involves doing "cd" to the parent directory "C:/Users/Peter/Documents/CPAP/", open CPAP_plots.xlsx and then cd back to where the script was started.
Has anyone seen this and, better yet, got a fix for it?
I'm using twapi 4.1.27 and TCL 8.6 on Windows 10 Pro x64 (It doesn't look like it was a windows update - last one was 2017-09-13)

Thanks
Pete

package require twapi

# Set this to the path to a .xlsx file.
# This test script does not modify the .xlsx - just opens and closes it
set temp_book "C:/Users/Peter/Documents/CPAP/CPAP_plots.xlsx"

set excel [::twapi::comobj Excel.Application]

$excel DisplayAlerts [expr 0]
set workbooks [$excel Workbooks]
# This prints the correct path but "workbooks Open" dies (170928)
puts $temp_book
$workbooks Open $temp_book
# It doesn't print this
puts "A"
$workbooks -destroy

$excel -destroy
unset excel

Jarek Lewandowski

unread,
Sep 28, 2017, 2:41:25 PM9/28/17
to
Probably you should try this:

set temp_book [file join C:/ Users Peter Documents CPAP CPAP_plots.xlsx]

elsup...@gmail.com

unread,
Sep 28, 2017, 8:04:16 PM9/28/17
to
On Thursday, 28 September 2017 12:41:25 UTC-6, mrjl wrote:
> Probably you should try this:
>
> set temp_book [file join C:/ Users Peter Documents CPAP CPAP_plots.xlsx]

I don't see why that would work. It sets temp_book to exactly the same string as I use in my script.
I tried it anyway and it doesn't make any difference.
Thanks

Pete

undro...@gmail.com

unread,
Sep 29, 2017, 4:39:39 AM9/29/17
to
then let's see if

set temp_book [file nativename [file join C:/ Users Peter Documents CPAP CPAP_plots.xlsx]]

does The Right Thing(tm)

elsup...@gmail.com

unread,
Sep 29, 2017, 4:23:36 PM9/29/17
to
Thanks.
I also received an email suggesting using nativename like this:
$workbooks open [file nativename $temp_book]
and it works.
It would be nice to know why this pathname:
set temp_book "C:/Users/Peter/Documents/CPAP/CPAP_plots.xlsx"
has been working every day for the last two or months but failed two days ago and hasn't worked since? :)
Note that if I just open the file with:

Pete

elsup...@gmail.com

unread,
Sep 29, 2017, 4:27:07 PM9/29/17
to
Argghh. I hit TAB and then it posted the message early. What I was going to say was Note that if I just open the file with:
set fi [open "C:/Users/Peter/Documents/CPAP/CPAP_plots.xlsx" "r"]
it works but
$workbooks Open "C:/Users/Peter/Documents/CPAP/CPAP_plots.xlsx"
fails.

Thanks
Pete

brian_...@mentor.com

unread,
Sep 29, 2017, 4:45:50 PM9/29/17
to
In the first case, Tcl is opening the file, and Tcl knows how to decode that path.
In the second case, the path string is passed to an external program, a Windows program that does not know how to interpret that path, it only understand native paths, i.e., paths using backslash (\) separators.
This is a very common scenario, and why [file nativename] exists.

-Brian

elsup...@gmail.com

unread,
Sep 29, 2017, 5:40:11 PM9/29/17
to
But up until 2 or 3 days ago, the path with / was working, and had been working for a couple of months.

Pete
0 new messages