Subject: Re: DDE and tcl - DN [1]


cthuang@interlog.com (Chin Huang) - 09 Jul 1999 - comp.lang.tcl

 In article <7m5ila$ir2$1@nnrp1.deja.com>,
 Rajkumar Madhuram  <madhurrc@my-deja.com> wrote:
 >I was recently looking at the DDE extension shipped with tcl8.1. I don't
 >have any experience with DDE, but would like to communicate with
 >packages like Excel and Program Manager. Can anyone give me hints on
 >where to find the commands (say in Excel, to put a value in a cell) that
 >will be recognized by the DDE services. Is there any sample code that I
 >could refer to? Any help would be appreciated.

 An alternative to DDE is to use COM automation to control Excel.  This
 sample Tcl script is reproduced from the tcom 1.5 distribution
 (available from http://www.vex.net/~cthuang/tcom/).

 # This example controls Excel.  It performs the following steps.
 #       - Start Excel application.
 #       - Create a new workbook.
 #       - Put values into some cells.
 #       - Save the workbook to a file.
 #       - Exit Excel application.

 package require tcom

 set application [::tcom::bind "Excel.Application"]
 $application Visible 1

 set workbooks [$application Workbooks]
 $workbooks Add [::tcom::na]
 set workbook [$workbooks Item "Book1"]
 set worksheets [$workbook Worksheets]
 set worksheet [$worksheets Item "Sheet1"]

 set cells [$worksheet Cells]
 set i 0
 foreach row {1 2 3} {
     foreach column {A B C} {
         $cells Item $row $column [incr i]
     }
 }

 ::tcom::dispatch $workbook SaveAs Filename {c:\tst.xls}
 $application Quit

 ::tcom::release $cells $worksheet $worksheets $workbook $workbooks
 ::tcom::release $application

Last modified
1999-09-27

(195.108.246.50)

Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated