set application [::tcom::ref createobject "Excel.Application"]
$application Visible 1
set workbooks [$application Workbooks]
set workbook [$workbooks Add]
set worksheets [$workbook Worksheets]
set worksheet [$worksheets Item [expr 1]]
set cells [$worksheet Cells]
set rows [array size atten]
for {set row 1} {$row <= $rows} {incr row} {
$cells Item $row "B" $atten($row)
}
$workbook SaveAs Filename {c:\tst.csv}
$application Quit
嗨。我能够以CSV格式写入数据。但数据全部损坏。例如,当我用记事本打开它时,数据已损坏,我的意思是我看不到用逗号分隔的数据。我用来将数据写入CSV格式的方法有问题吗?
答案 0 :(得分:2)
文件名以.csv
结尾不足以告诉Excel保存为CSV。您必须将文件类型常量传递给SaveAs
方法。不确定Tcl语法,但我猜测SaveAs
的正确调用将是
$workbook SaveAs Filename {c:\tst.csv} FileFormat xlCSV