package require csv package require tdom package require struct::queue set ssns urn:schemas-microsoft-com:office:spreadsheet set xns urn:schemas-microsoft-com:office:excel dom createDocumentNS $ssns Workbook ss set de [$ss documentElement] $de setAttributeNS "" xmlns:o urn:schemas-microsoft-com:office:office $de setAttributeNS "" xmlns:x $xns $de setAttributeNS "" xmlns:ss $ssns $de setAttributeNS "" xmlns:html http://www.w3.org/TR/REC-html40 $ss createElementNS $ssns Worksheet ws $ws setAttributeNS $ssns ss:Name Sheet1 $de appendChild $ws $ss createElementNS $ssns Table tbl $ws appendChild $tbl set q [struct::queue] csv::read2queue stdin $q set cols 0 set rows [$q size] while {[$q size] > 0} { $ss createElementNS $ssns Row row $tbl appendChild $row set line [$q get] if {[llength $line] > $cols} {set cols [llength $line]} foreach datum $line { $ss createElementNS $ssns Cell cell $row appendChild $cell $ss createElementNS $ssns Data data $cell appendChild $data $data setAttributeNS $ssns ss:Type String $ss createTextNode $datum content $data appendChild $content } } $tbl setAttributeNS $ssns ss:ExpandedColumnCount $cols $tbl setAttributeNS $ssns ss:ExpandedRowCount $rows puts "" puts "" puts [$ss asXML -indent 2 ]