How to store array elements in an Excel Sheet cells with TCL/tcom

北慕城南 提交于 2019-12-25 06:47:49

问题


I want to store array elements in an Excel Sheet. How can I do that? Here is the sample code for an array:

for {set i 0} { $i < 3} {incr i} {
    set color($i) $i    
}

Now how can I store color(0), color(1), color(2) in different cells?

Edit: Based on this tcom example I have been trying to store array elements in an Excel Sheet.


回答1:


Have a look at the commands array set and array get.

for {set i 0} { $i < 3} {incr i} {
    set color($i) $i    
}

set nvList [array get color]

Variable nvList has now the value 0 0 1 1 2 2 (mind the comments). With array get you get the Name-Value representation of an array. If you call array set you can convert nvList to an array again.

It this what you need?

Edit: Another example based on your comment:

# building example array with 100 elements
for {set r 1} {$r <= 100} {incr r} {
    set color($r) $r
}

set rows [array size color]
set columns {A B C}

for {set row 1} {$row <= $rows} {incr row} {
    foreach column $columns {
        $cells Item $row $column $color($row)
    }
}

Edit: Another (second) example based on your comment:

array set atten {...}
array set transmit {...}

set rows [array size atten]
for {set row 1} {$row <= $rows} {incr row} {
    $cells Item $row "B" $atten($row)
} 

set rows [array size transmit]
for {set row 1} {$row <= $rows} {incr row} {
    $cells Item $row "C" $transmit($row)
}


来源:https://stackoverflow.com/questions/9575299/how-to-store-array-elements-in-an-excel-sheet-cells-with-tcl-tcom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!