Tcl - 如何使用 tcom 对 excel 进行排序

Tcl - How to sort excel using tcom

Excel 排序需要以以下格式指定值:

Columns("A:C").Sort key1:=Range("C2"), order1:=xlAscending, header:=xlYes

如何通过tcom发送?我尝试了以下未成功

 (Users) 14 % set sort [$worksheet Sort]
 ::tcom::handle0x0201DD00
 (Users) 15 % $sort Header xlYes
 0x80020005 {Type mismatch.}
 (Users) 16 % $sort Header 1
 (Users) 18 % set sfs [$sort SortFields]
 ::tcom::handle0x0201DD60
 (Users) 21 % $sfs Add Key:=[$worksheet Range "B2:B7"]
 0x80020005 {Type mismatch.}
 (Users) 22 % $sfs Add [$worksheet Range "B2:B7"]
 ::tcom::handle0x0201DDA0
 (Users) 24 % $sort Apply
 0x800a03ec {Unknown error}
 (Users) 25 % $sfs Add [$application Range "B2:B7"]
 ::tcom::handle0x0201DDC0
 (Users) 26 % $sort Apply
 0x800a03ec {Unknown error}

您需要替换 Excel 常量的整数值而不是它的名称。

您可以在 https://msdn.microsoft.com/en-us/library/office/ff838815.aspx 仔细阅读常量和枚举列表并执行 set xlYes [expr 1] 以确保它是一个整数,然后在您的脚本中使用变量 $xlYes。

如果您的计算机上有 Excel typelib 文件,您可以 tcom::import 它来创建一个包含这些常量的 tcl 数组。

更多信息: 如何使用注册表查找 tcom 的 com 对象枚举:http://wiki.tcl.tk/19932 如何发现 COM-exporting 应用程序的 API:http://wiki.tcl.tk/4472