Artifact
08100118488d4bf3153890f322a05e5fa6f8d35971c126ab947a4a3a28103125 :
Executable file
examples/sample1.tcl
— part of check-in
[6f81c53af7]
at
2018-08-17 11:23:41
on branch trunk
— added examples 1-3
(user:
alex
size: 1187)
0000: 23 21 2f 62 69 6e 2f 73 68 0a 23 5c 0a 65 78 65 #!/bin/sh.#\.exe
0010: 63 20 74 63 6c 73 68 38 2e 36 20 22 24 30 22 20 c tclsh8.6 "$0"
0020: 22 24 40 22 0a 0a 23 70 61 63 6b 61 67 65 20 72 "$@"..#package r
0030: 65 71 75 69 72 65 20 6f 6f 78 6d 6c 0a 73 6f 75 equire ooxml.sou
0040: 72 63 65 20 2e 2e 2f 6f 6f 78 6d 6c 2e 74 63 6c rce ../ooxml.tcl
0050: 0a 0a 73 6f 75 72 63 65 20 61 72 72 61 79 2e 74 ..source array.t
0060: 63 6c 0a 0a 73 65 74 20 73 70 72 65 61 64 73 68 cl..set spreadsh
0070: 65 65 74 20 5b 3a 3a 6f 6f 78 6d 6c 3a 3a 78 6c eet [::ooxml::xl
0080: 5f 77 72 69 74 65 20 6e 65 77 20 2d 63 72 65 61 _write new -crea
0090: 74 6f 72 20 7b 41 6c 65 78 61 6e 64 65 72 20 53 tor {Alexander S
00a0: 63 68 c3 b6 70 65 7d 5d 0a 69 66 20 7b 5b 73 65 chöpe}].if {[se
00b0: 74 20 73 68 65 65 74 20 5b 24 73 70 72 65 61 64 t sheet [$spread
00c0: 73 68 65 65 74 20 77 6f 72 6b 73 68 65 65 74 20 sheet worksheet
00d0: 7b 54 61 62 65 6c 6c 65 20 31 7d 5d 5d 20 3e 20 {Tabelle 1}]] >
00e0: 2d 31 7d 20 7b 0a 20 20 73 65 74 20 63 65 6e 74 -1} {. set cent
00f0: 65 72 20 5b 24 73 70 72 65 61 64 73 68 65 65 74 er [$spreadsheet
0100: 20 73 74 79 6c 65 20 2d 68 6f 72 69 7a 6f 6e 74 style -horizont
0110: 61 6c 20 63 65 6e 74 65 72 5d 0a 20 20 73 65 74 al center]. set
0120: 20 64 61 74 65 20 5b 24 73 70 72 65 61 64 73 68 date [$spreadsh
0130: 65 65 74 20 73 74 79 6c 65 20 2d 6e 75 6d 66 6d eet style -numfm
0140: 74 20 5b 24 73 70 72 65 61 64 73 68 65 65 74 20 t [$spreadsheet
0150: 6e 75 6d 62 65 72 66 6f 72 6d 61 74 20 2d 64 61 numberformat -da
0160: 74 65 74 69 6d 65 5d 5d 0a 20 20 73 65 74 20 64 tetime]]. set d
0170: 65 63 69 6d 61 6c 20 5b 24 73 70 72 65 61 64 73 ecimal [$spreads
0180: 68 65 65 74 20 73 74 79 6c 65 20 2d 6e 75 6d 66 heet style -numf
0190: 6d 74 20 5b 24 73 70 72 65 61 64 73 68 65 65 74 mt [$spreadsheet
01a0: 20 6e 75 6d 62 65 72 66 6f 72 6d 61 74 20 2d 64 numberformat -d
01b0: 65 63 69 6d 61 6c 20 2d 72 65 64 5d 5d 0a 20 20 ecimal -red]].
01c0: 73 65 74 20 74 65 78 74 20 5b 24 73 70 72 65 61 set text [$sprea
01d0: 64 73 68 65 65 74 20 73 74 79 6c 65 20 2d 6e 75 dsheet style -nu
01e0: 6d 66 6d 74 20 5b 24 73 70 72 65 61 64 73 68 65 mfmt [$spreadshe
01f0: 65 74 20 6e 75 6d 62 65 72 66 6f 72 6d 61 74 20 et numberformat
0200: 2d 73 74 72 69 6e 67 5d 5d 0a 0a 20 20 24 73 70 -string]].. $sp
0210: 72 65 61 64 73 68 65 65 74 20 63 6f 6c 75 6d 6e readsheet column
0220: 20 24 73 68 65 65 74 0a 20 20 24 73 70 72 65 61 $sheet. $sprea
0230: 64 73 68 65 65 74 20 63 6f 6c 75 6d 6e 20 24 73 dsheet column $s
0240: 68 65 65 74 20 2d 77 69 64 74 68 20 33 30 0a 20 heet -width 30.
0250: 20 24 73 70 72 65 61 64 73 68 65 65 74 20 63 6f $spreadsheet co
0260: 6c 75 6d 6e 20 24 73 68 65 65 74 0a 20 20 24 73 lumn $sheet. $s
0270: 70 72 65 61 64 73 68 65 65 74 20 63 6f 6c 75 6d preadsheet colum
0280: 6e 20 24 73 68 65 65 74 0a 20 20 24 73 70 72 65 n $sheet. $spre
0290: 61 64 73 68 65 65 74 20 63 6f 6c 75 6d 6e 20 24 adsheet column $
02a0: 73 68 65 65 74 20 2d 73 74 79 6c 65 20 24 64 65 sheet -style $de
02b0: 63 69 6d 61 6c 0a 20 20 24 73 70 72 65 61 64 73 cimal. $spreads
02c0: 68 65 65 74 20 63 6f 6c 75 6d 6e 20 24 73 68 65 heet column $she
02d0: 65 74 20 2d 73 74 79 6c 65 20 24 64 61 74 65 20 et -style $date
02e0: 2d 77 69 64 74 68 20 5b 3a 3a 6f 6f 78 6d 6c 3a -width [::ooxml:
02f0: 3a 43 61 6c 63 43 6f 6c 75 6d 6e 57 69 64 74 68 :CalcColumnWidth
0300: 20 31 36 5d 0a 20 20 24 73 70 72 65 61 64 73 68 16]. $spreadsh
0310: 65 65 74 20 63 6f 6c 75 6d 6e 20 24 73 68 65 65 eet column $shee
0320: 74 0a 0a 20 20 24 73 70 72 65 61 64 73 68 65 65 t.. $spreadshee
0330: 74 20 61 75 74 6f 66 69 6c 74 65 72 20 24 73 68 t autofilter $sh
0340: 65 65 74 20 30 2c 30 20 30 2c 36 0a 20 20 24 73 eet 0,0 0,6. $s
0350: 70 72 65 61 64 73 68 65 65 74 20 66 72 65 65 7a preadsheet freez
0360: 65 20 24 73 68 65 65 74 20 31 2c 32 0a 0a 20 20 e $sheet 1,2..
0370: 66 6f 72 65 61 63 68 20 7b 6e 61 6d 65 20 76 61 foreach {name va
0380: 6c 75 65 7d 20 5b 61 72 72 61 79 20 67 65 74 20 lue} [array get
0390: 64 61 74 61 5d 20 7b 0a 20 20 20 20 6c 61 73 73 data] {. lass
03a0: 69 67 6e 20 5b 73 70 6c 69 74 20 24 6e 61 6d 65 ign [split $name
03b0: 20 2c 5d 20 72 6f 77 20 63 6f 6c 0a 20 20 20 20 ,] row col.
03c0: 73 77 69 74 63 68 20 2d 2d 20 24 63 6f 6c 20 7b switch -- $col {
03d0: 0a 20 20 20 20 20 20 32 20 7b 0a 09 24 73 70 72 . 2 {..$spr
03e0: 65 61 64 73 68 65 65 74 20 63 65 6c 6c 20 24 73 eadsheet cell $s
03f0: 68 65 65 74 20 24 76 61 6c 75 65 20 2d 69 6e 64 heet $value -ind
0400: 65 78 20 24 6e 61 6d 65 20 2d 73 74 72 69 6e 67 ex $name -string
0410: 0a 20 20 20 20 20 20 7d 0a 20 20 20 20 20 20 64 . }. d
0420: 65 66 61 75 6c 74 20 7b 0a 09 24 73 70 72 65 61 efault {..$sprea
0430: 64 73 68 65 65 74 20 63 65 6c 6c 20 24 73 68 65 dsheet cell $she
0440: 65 74 20 24 76 61 6c 75 65 20 2d 69 6e 64 65 78 et $value -index
0450: 20 24 6e 61 6d 65 0a 20 20 20 20 20 20 7d 0a 20 $name. }.
0460: 20 20 20 7d 0a 20 20 7d 0a 0a 20 20 24 73 70 72 }. }.. $spr
0470: 65 61 64 73 68 65 65 74 20 77 72 69 74 65 20 65 eadsheet write e
0480: 78 70 6f 72 74 31 2e 78 6c 73 78 0a 7d 0a 24 73 xport1.xlsx.}.$s
0490: 70 72 65 61 64 73 68 65 65 74 20 64 65 73 74 72 preadsheet destr
04a0: 6f 79 0a oy.