Use Tcl operatie Excel file

Discuss about TCL

Use Tcl operatie Excel file

Postby scriptdev » Sat Aug 07, 2010 1:20 pm

Excel provided by the COM interface access method, below the script is used tcom Tcl demonstration expansion pack, operation of the documents, to Excel file a cell assignment, and modify the background color, of course, also can undertake various complex operation, use tcom operation COM interface problem is how to know the key to access the COM interface have what method and parameters, and the meaning, there are various ways you can access to this information, a kind of method is to Microsoft search relevant API on MSDN, such as office should is to be found, additionally one kind is to use a tool with VC++ OLEView, through this tool can view all registered COM interface of detailed information, but may not documentation, many methods of COM interface, the significance of parameters is clear, basically can guess method name.

The sample script to operate Excel:
Code: Select all
package require tcom
# the file name of excel
set filename [file join [file dirname [info script]] test.xls]
puts $filename
# create com instance, open workbook
set app [::tcom::ref createobject "Excel.Application"]
set workbooks [$app Workbooks]
set workbook [$workbooks Open $filename]
set worksheets [$workbook Worksheets]
set worksheet [$worksheets Item "Sheet1"]
# get the range object of A1
set range1 [$worksheet Range A1]
# set the value of A1
$range1 Value2 "123"
# set background color of A1
set interior [$range1 Interior]
$interior Color [expr 0x00FFE0]
# save Excel file
$workbook Save
# show Excel
$app Visible 1
Site Admin
Posts: 5
Joined: Fri Aug 06, 2010 2:37 pm

Return to TCL

Who is online

Users browsing this forum: No registered users and 1 guest