将输出写入不同列的excel

您好我正在使用tcl写输出xls文件。 不过,我成功地将输出写入一列中的xls文件,但是我想要在合理的时间分割并写入两个不同的列。 我只写一列的代码工作正常:

set fh [open $ew] while {[llength $c]} { set name [lindex $c 0] set c [concat [glob -nocomplain -directory [lindex $c 0] -type d *] [lrange $c 1 end]] set filesofDirectory [glob -nocomplain -directory $name -type f *] if { [llength $filesofDirectory] > 0 && $d == "fftc"} { set x "number of files in $name is [llength $filesofDirectory]" puts $fh [join $x ] } } close $fh 

但是,当我修改相同的代码来获得输出:

  set fh [open $ew] while {[llength $c]} { set name [lindex $c 0] set c [concat [glob -nocomplain -directory [lindex $c 0] -type d *] [lrange $c 1 end]] set filesofDirectory [glob -nocomplain -directory $name -type f *] if { [llength $filesofDirectory] > 0 && $d == "fftc"} { set x "number of files in $name" set y [llength $filesofDirectory] puts $fh [join $x "," $y] } } close $fh 

请build议解决方法

要将目录分解转储到可以在Excel中使用的CSV文件,此代码应该可以工作:

 package require csv set c . set d fftc set e foo.csv proc glob2csv {cd fh} { foreach name $c { if {[file isdirectory $name]} { set n [llength [glob -nocomplain -directory $name -type f *]] if {$n > 0 && $d eq "fftc"} { chan puts $fh [csv::join [list "number of files in $name is" $n]] } glob2csv [glob -nocomplain -directory $name -type d *] $d $fh } } } try { open $ew } on ok fh { glob2csv $c $d $fh } finally { catch {chan close $fh} } 

我在这里做了很多不舒服的假设,因为我不知道你的代码是关于什么的。 您可能希望使用csv::join的可选参数来调整CSV文件的格式。 在我的语言环境中,例如,我需要将分隔符设置为制表符( \t ),以避免Excel将每行视为单个string。

Tcllib CSV模块的文档

文档: catch , chan , file , foreach , glob , if , list , llength , open , package , proc , set , try