Tcl - How to sort excel using tcom

0

Excel sorting requires specifying values in the format:

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

How Do I send it via tcom? I have tried the following unsuccessfully

 (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}
tcl
asked on Stack Overflow Jan 8, 2016 by zip_lock_throw • edited Jan 8, 2016 by zip_lock_throw

1 Answer

2

You'll need to substitute the integer value of the Excel constant rather than its name.

You can peruse the list of constants and enums at https://msdn.microsoft.com/en-us/library/office/ff838815.aspx and do set xlYes [expr 1] to ensure it's an integer, then use the variable $xlYes in your script.

If you have the Excel typelib file on your computer, you can tcom::import it to create a tcl array containing these constants.

more info: How to find com object enums for tcom using registry: http://wiki.tcl.tk/19932 How one discovers the API for a COM-exporting application: http://wiki.tcl.tk/4472

answered on Stack Overflow Jan 9, 2016 by ggarrett

User contributions licensed under CC BY-SA 3.0