Excel 使用TCOM/TCL和函数调用设置单元值
我试图使用函数调用在TCOM中分配单元值。但是我看到确切的函数名被打印出来了Excel 使用TCOM/TCL和函数调用设置单元值,excel,tcl,tdom,Excel,Tcl,Tdom,我试图使用函数调用在TCOM中分配单元值。但是我看到确切的函数名被打印出来了 set application [::tcom::ref createobject "Excel.Application"] set workbooks [$application Workbooks] $application DisplayAlerts False set workbook [$workbooks Open "\\$filename.csv"] set worksheets [$workbook W
set application [::tcom::ref createobject "Excel.Application"]
set workbooks [$application Workbooks]
$application DisplayAlerts False
set workbook [$workbooks Open "\\$filename.csv"]
set worksheets [$workbook Worksheets]
set worksheet [$worksheets Item [expr 1]]
set cells_worksheet1 [$worksheet Cells]
$cells_worksheet1 Item 27 B $Attribute
我想将
$cells\u工作表1项27 B$Attribute
替换为$cells\u工作表1项27 B{[getAttribute]}
,其中getAttribute
函数返回$Attribute
。你知道怎么做吗?据我从Excel API所见,你可以从单元格
属性中得到一个back,从它的项
成员中得到一个进一步的范围
back。然后,可以使用属性访问器访问单个项的属性
# Assuming your largely-perfect code from your question...
set cell [$cells_worksheet1 Item 27 B]
set orientation [$cell Orientation] ;# Arbitrary example of getting a property
$cell Orientation 42 ;# Setting the property
可以从文字以外的源获取要操作的属性的名称:
proc getAttribute {} {
return "Orientation"
}
puts "orientation is [$cell [getAttribute]]" ;# Note, *no* {braces} involved!
但这并不一定适用于所有酒店;问题不在于你不能要求它们,而是有些人希望在你获取它们时传递额外的信息,而有些人则需要额外的工作来提取,因为它们本身就是复合对象。如果你不知道自己打算怎么做,就很难给出更好的建议
大括号的问题是Tcl将它们视为完全不需要替换的文本。当您声明一个过程时,这很好,但当您想调用该过程并使用结果时,这就没那么有用了。据我从Excel API中看到的,您可以从
Cells
属性中得到一个back,从它的Item
成员中得到另一个Range
返回。然后,可以使用属性访问器访问单个项的属性
# Assuming your largely-perfect code from your question...
set cell [$cells_worksheet1 Item 27 B]
set orientation [$cell Orientation] ;# Arbitrary example of getting a property
$cell Orientation 42 ;# Setting the property
可以从文字以外的源获取要操作的属性的名称:
proc getAttribute {} {
return "Orientation"
}
puts "orientation is [$cell [getAttribute]]" ;# Note, *no* {braces} involved!
但这并不一定适用于所有酒店;问题不在于你不能要求它们,而是有些人希望在你获取它们时传递额外的信息,而有些人则需要额外的工作来提取,因为它们本身就是复合对象。如果你不知道自己打算怎么做,就很难给出更好的建议
大括号的问题是Tcl将它们视为完全不需要替换的文本。当您声明一个过程时,这很好,但当您想调用该过程并使用结果时,这就没那么有用了。我会在
文件nativename[file normalize$filename.csv]
的帮助下生成与Open
一起使用的名称;Tcl有很好的工具来做这类事情。我会在文件nativename[file normalize$filename.csv]
的帮助下,生成与打开
一起使用的名称;Tcl为这类事情提供了很好的工具。