如何使用 TCL/tcom 在 Excel Sheet 单元格中存储数组元素 [英] How to store array elements in an Excel Sheet cells with TCL/tcom
问题描述
我想在 Excel 工作表中存储数组元素.我怎样才能做到这一点?这是数组的示例代码:
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
}
现在如何在不同的单元格中存储颜色(0)、颜色(1)、颜色(2)?
Now how can I store color(0), color(1), color(2) in different cells?
基于这个 tcom 示例,我一直在尝试将数组元素存储在 Excel 中表.
Based on this tcom example I have been trying to store array elements in an Excel Sheet.
推荐答案
for {set i 0} { $i < 3} {incr i} {
set color($i) $i
}
set nvList [array get color]
变量 nvList
现在具有值 0 0 1 1 2 2
(注意注释).使用 array get
可以获得数组的名称-值表示.如果你调用 array set
你可以再次将 nvList
转换成数组.
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.
这是你需要的吗?
另一个基于您评论的示例:
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)
}
}
基于您的评论的另一个(第二个)示例:
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)
}
这篇关于如何使用 TCL/tcom 在 Excel Sheet 单元格中存储数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!