使用Tcl操作Excel文件的方法

Excel提供了通过COM接口进行访问的方法,下面这段Tcl脚本就是演示使用tcom扩展包操作Excel文件,给文件中的一个单元格赋值,并修改背景色,当然还可以进行其他各种复杂操作,使用tcom操作COM接口的关键问题就是如何知道要访问的COM接口都有哪些方法和参数,以及含义,有多种方法可以获取到这些信息[@more@]

,一种方法是到微软的msdn上搜索相关API说明,像office等应该都能查到,另外一种方法是使用VC带的一个工具OLEView,通过这个工具可以查看本机所有注册COM接口的详细信息,但可能没有说明文档,还好很多COM接口的方法、参数的意义都是一目了然的,看方法名基本上也能猜到不少。

package require tcom
# 构造要打开的excel文件名
set filename [file join [file dirname [info script]] test.xls]
puts $filename
# 创建com实例,打开工作表
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"]
# 获取A1单元的范围对象
set range1 [$worksheet Range A1]
# 给A1单元赋值
$range1 Value2 "123"
# 设置单元的背景色
set interior [$range1 Interior]
$interior Color [expr 0x00FFE0]
# 保存文档
$workbook Save
# 显示Excel
$app Visible 1

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/459749/viewspace-1057379/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/459749/viewspace-1057379/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Overview Tcl Windows API extension overview. Installation Installation requirements and instructions. Win32 raw API Direct access to the Win32 API. Window management Commands related to management of windows. Desktops and Window stations Commands related to desktops and window stations. Windows Shell Windows shell commands. Keyboard and mouse input Simulation of user input and support for system-wide hotkeys. Sound Basic sound functions. Clipboard Commands related to accessing the clipboard. System Operating system and machine configuration and control. Processes, threads and DLLs Commands related to processes, threads and dynamic link libraries. Handles Commands for managing operating system handles. Services Commands for configuring and monitoring Windows services. Network configuration Commands related to network configuration. Disks and Volumes Commands related to disks and volumes. Network shares Commands related to management of network shares. Users and Groups Commands related to user and group accounts. Security and access control Commands related to authentication and access control. Event log Commands relating to reading and writing the Windows event log. Windows INI file Commands for accessing Windows INI files. Console Commands related to Windows consoles. Scheduler Commands related to managing scheduled jobs through the task scheduler. Internationalization Commands related to internationalization. Miscellaneous Various TWAPI ancillary commands. Printers Printer management. Examples Tcl Windows API usage examples. Version History Tcl Windows API extension version history.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值