tags:

views:

300

answers:

1

Hello:

I am having problems opening an existing Excel file with Tcl Tk. I am able to open an existing MS Word file with no problems. The code that I am using is as follows, also my test application has "package require tcom" included:

proc OpenFile {} {
#Path to file
set app [::tcom::ref getobject "C:\\Users\\Me\\Desktop\\Test.doc"] 
#Change path to application
set this [$app Application]
#Open application
$this Visible 1
}

This code is executed by a button. Basically, Test.doc gets opened after the button is pressed.

I tried changing the file to an existing Excel file, and when I press the button the file opens for a split second, and then closes. This also happens with MS Access files, as well.

Does anyone know how to open an existing Excel file with Tcl Tk, and make it stay open? Additionally, for PDFs and text files, I understand that I cannot use Tcom to open these files. Does anyone know how to open PDFs, text, and other non-MS files with Tcl Tk?

I really appreciate your help!

Thank you,

DFM

A: 

Assuming you're on Windows and you just want to open a file (.xls, .pdf, ...) with its usual application (ie. not modifying the file from your script) you can just use "start" like this:

set TestDoc "My Test.xls"
eval exec [auto_execok start \"\" [list $TestDoc]
Colin Macleod
As originally written, because of the eval your answer will fail if the filename has spaces in it. You might want to revise your answer to take this into consideration.
Bryan Oakley
Thanks Colin - I tried to vote you up, but I do not have enough rep points. After eliminating the path from Test.xls, I was able to use your suggestion perfectly.
Hello Bryan - Thank for the suggestion. I was able to find a resource (http://wiki.tcl.tk/765) that explained the syntax for files that have spaces in their names:set TestDoc "My Test.xls"eval exec [auto_execok start \"\" [list $TestDoc]Thank you Colin and Bryan for your help!DFM
Thanks for the correction Bryan. DMullins - glad you got it working, if you're happy with the answer you can accept it - see http://meta.stackoverflow.com/questions/5234/accepting-answers-what-is-it-all-about
Colin Macleod