**Presentation** [SRIV] '''Sept 18,2010''' This is a quick port of the php example at http://www.ibm.com/developerworks/web/library/wa-odf/ . It's not a generic file writing library, but instead just a script that creates a spreadsheet, that you can modify and enhance to your liking. Feel free to add enhancements and break out the functionality, perhaps using TclOO. ====== #!/usr/bin/env tclsh ########################################### # application name: odswriter.tcl # author: Steve Redler IV, SR Technology # date: Sept 18, 2010 # function: Create an OpenOffice Spreadsheet in pure tcl # set XML_START { } set XML_AUTOMATIC_STYLES { } set XML_BODY_START { } set MIMETYPE "application/vnd.oasis.opendocument.spreadsheet" set XML_MANIFEST { } set XML_ROW_START "" set XML_CELL_START "" set XML_CELL_END "" set XML_ROW_END "" set XML_END "" set XML_BBB_CELL_START "" set XML_BLD_CELL_START "" # Create the content.xml file set contents $XML_START append contents $XML_AUTOMATIC_STYLES append contents $XML_BODY_START # Add a big, bold, blue, title, and an empty line: append contents $XML_ROW_START append contents $XML_BBB_CELL_START append contents "Cities whose name starts with 'Darwin'" append contents $XML_CELL_END append contents $XML_ROW_END append contents $XML_ROW_START append contents $XML_ROW_END # Add some titles, in bold: append contents $XML_ROW_START foreach title {"Country" "" "Region" "" "City" "Pop" "Lat" "Long"} { append contents $XML_BLD_CELL_START append contents $title append contents $XML_CELL_END } append contents $XML_ROW_END # ...get the data... set data {{AR Argentina 16 {Rio Negro} darwin {} -39.200000008 -65.7666702} \ {AU Australia 03 {Nothern Territory} darwin 93081 -12.4666672 130.8333282} \ {IQ Iraq 05 {As Sulaymaniya} darwina {} 36.126667 45.2377777}} foreach row $data { append contents $XML_ROW_START foreach value $row { append contents $XML_CELL_START append contents $value append contents $XML_CELL_END } append contents $XML_ROW_END } append contents $XML_END # let tempzip be the name of a temporary file file mkdir tempzip file mkdir tempzip/META-INF set fh [open tempzip/META-INF/manifest.xml "CREAT WRONLY TRUNC"] puts -nonewline $fh $XML_MANIFEST close $fh set fh [open tempzip/content.xml "CREAT WRONLY TRUNC"] puts -nonewline $fh $contents close $fh set fh [open tempzip/mimetype "CREAT WRONLY TRUNC"] puts -nonewline $fh $MIMETYPE close $fh cd tempzip # zip creation was only tested in Linux and WinXP #get zip.exe from http://stahlworks.com/dev/zip.exe exec {*}{zip -mr ../tempzip.ods mimetype META-INF/manifest.xml content.xml} cd .. file delete -force tempzip ====== ----- <> Spreadsheet