ooxml

Check-in [0c057761f8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merged from trunk
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | populationspeed
Files: files | file ages | folders
SHA3-256: 0c057761f8caa3e4cca4a3ecb2bdd31013194c4ff1905228696e9cb08a4d13b6
User & Date: rolf 2019-08-15 13:09:26
Original Comment: Merged from trunk.
Context
2019-08-16
03:33
minimum version Tcl 8.6.7 required check-in: 32eaa74737 user: alex tags: populationspeed
2019-08-15
13:09
Merged from trunk check-in: 0c057761f8 user: rolf tags: populationspeed
06:42
move package require vfs::zip to procs xl_sheets and xl_read because it is only needed to read data check-in: 0ebe84a691 user: alex tags: populationspeed
2019-08-10
09:33
added sample9.tcl and timestamp correction doc core check-in: 4a610b3601 user: alex tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to examples/sample1.tcl.

1
2
3
4

5
6

7
8
9
10
11
12
13
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"


#package require ooxml
source ../ooxml.tcl


source array.tcl

set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
if {[set sheet [$spreadsheet worksheet {Tabelle 1}]] > -1} {
  set center [$spreadsheet style -horizontal center]
  set date [$spreadsheet style -numfmt [$spreadsheet numberformat -datetime]]




>
|
|
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"

set auto_path [linsert $auto_path 0 ..]
if {[catch {package require ooxml}]} {
  source ../ooxml.tcl
}

source array.tcl

set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
if {[set sheet [$spreadsheet worksheet {Tabelle 1}]] > -1} {
  set center [$spreadsheet style -horizontal center]
  set date [$spreadsheet style -numfmt [$spreadsheet numberformat -datetime]]

Changes to examples/sample2.tcl.

1
2
3
4

5
6

7
8
9
10
11
12
13
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"


#package require ooxml
source ../ooxml.tcl


source array.tcl

set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
if {[set sheet [$spreadsheet worksheet {Tabelle 1}]] > -1} {
  set center [$spreadsheet style -horizontal center]
  set date [$spreadsheet style -numfmt [$spreadsheet numberformat -datetime]]




>
|
|
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"

set auto_path [linsert $auto_path 0 ..]
if {[catch {package require ooxml}]} {
  source ../ooxml.tcl
}

source array.tcl

set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
if {[set sheet [$spreadsheet worksheet {Tabelle 1}]] > -1} {
  set center [$spreadsheet style -horizontal center]
  set date [$spreadsheet style -numfmt [$spreadsheet numberformat -datetime]]

Changes to examples/sample3.tcl.

1
2
3
4
5
6
7

8
9

10
11
12
13
14
15
16
#!/bin/sh
#\
exec wish8.6 "$0" "$@"

package require Tk
package require tablelist


#package require ooxml
source ../ooxml.tcl


source array.tcl

# build Tablelist from array

set lb .lb
tablelist::tablelist $lb -height 16 -width 100 -showseparators 1 -titlecolumns 3 -labelcommand tablelist::sortByColumn







>
|
|
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh
#\
exec wish8.6 "$0" "$@"

package require Tk
package require tablelist

set auto_path [linsert $auto_path 0 ..]
if {[catch {package require ooxml}]} {
  source ../ooxml.tcl
}

source array.tcl

# build Tablelist from array

set lb .lb
tablelist::tablelist $lb -height 16 -width 100 -showseparators 1 -titlecolumns 3 -labelcommand tablelist::sortByColumn

Changes to examples/sample4.tcl.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"

lappend auto_path .
if {[catch {package require ooxml}]} {
    source ../ooxml.tcl
}

source array.tcl

set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
if {[set sheet [$spreadsheet worksheet {Tabelle 1}]] > -1} {
  $spreadsheet row $sheet




|

|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"

set auto_path [linsert $auto_path 0 ..]
if {[catch {package require ooxml}]} {
  source ../ooxml.tcl
}

source array.tcl

set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
if {[set sheet [$spreadsheet worksheet {Tabelle 1}]] > -1} {
  $spreadsheet row $sheet

Changes to examples/sample5.tcl.

1
2
3
4

5
6

7
8
9
10
11
12
13
14
15
16
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"


#package require ooxml
source ../ooxml.tcl


set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
if {[set sheet [$spreadsheet worksheet {Tabelle 1}]] > -1} {
  set date [$spreadsheet style -numfmt [$spreadsheet numberformat -datetime]]
  $spreadsheet defaultdatestyle $date
  # 2018-03-02 17:39 -> 43161.73542
  $spreadsheet cell $sheet "2018-03-02 17:39" -index 0,0
  $spreadsheet write export5.xlsx
}
$spreadsheet destroy




>
|
|
>










1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"

set auto_path [linsert $auto_path 0 ..]
if {[catch {package require ooxml}]} {
  source ../ooxml.tcl
}

set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
if {[set sheet [$spreadsheet worksheet {Tabelle 1}]] > -1} {
  set date [$spreadsheet style -numfmt [$spreadsheet numberformat -datetime]]
  $spreadsheet defaultdatestyle $date
  # 2018-03-02 17:39 -> 43161.73542
  $spreadsheet cell $sheet "2018-03-02 17:39" -index 0,0
  $spreadsheet write export5.xlsx
}
$spreadsheet destroy

Changes to examples/sample6.tcl.

1
2
3
4

5
6

7
8
9
10
11
12
13
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"


#package require ooxml
source ../ooxml.tcl


set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
if {[set sheet [$spreadsheet worksheet {Blatt 1}]] > -1} {
  set bold [$spreadsheet style -font [$spreadsheet font -bold]]
  set italic [$spreadsheet style -font [$spreadsheet font -italic]]
  set underline [$spreadsheet style -font [$spreadsheet font -underline]]





>
|
|
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"

set auto_path [linsert $auto_path 0 ..]
if {[catch {package require ooxml}]} {
  source ../ooxml.tcl
}

set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
if {[set sheet [$spreadsheet worksheet {Blatt 1}]] > -1} {
  set bold [$spreadsheet style -font [$spreadsheet font -bold]]
  set italic [$spreadsheet style -font [$spreadsheet font -italic]]
  set underline [$spreadsheet style -font [$spreadsheet font -underline]]

Changes to examples/sample7.tcl.

1
2
3
4

5
6

7
8
9
10
11
12
13
14
15
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"


#package require ooxml
source ../ooxml.tcl


array set workbook [ooxml::xl_read original_excel.xlsx]

set spreadsheet [::ooxml::xl_write new]
$spreadsheet presetstyles workbook
$spreadsheet presetsheets workbook
$spreadsheet write export7.xlsx
$spreadsheet destroy





>
|
|
>









1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"

set auto_path [linsert $auto_path 0 ..]
if {[catch {package require ooxml}]} {
  source ../ooxml.tcl
}

array set workbook [ooxml::xl_read original_excel.xlsx]

set spreadsheet [::ooxml::xl_write new]
$spreadsheet presetstyles workbook
$spreadsheet presetsheets workbook
$spreadsheet write export7.xlsx
$spreadsheet destroy

Changes to examples/sample8.tcl.

1
2
3
4

5
6

7
8
9
10
11
12
13
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"


#package require ooxml
source ../ooxml.tcl


array set workbook [ooxml::xl_read form8.xlsx]

set data(NAME) {Erika Mustermann}
set data(ANSCHRIFT) {Heidestrasse 17}
set data(PLZORT) {51147 Köln}
set data(positionen) 3




>
|
|
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"

set auto_path [linsert $auto_path 0 ..]
if {[catch {package require ooxml}]} {
  source ../ooxml.tcl
}

array set workbook [ooxml::xl_read form8.xlsx]

set data(NAME) {Erika Mustermann}
set data(ANSCHRIFT) {Heidestrasse 17}
set data(PLZORT) {51147 Köln}
set data(positionen) 3

Added examples/sample9.tcl.



































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
#\
exec tclsh8.6 "$0" "$@"

set auto_path [linsert $auto_path 0 ..]
if {[catch {package require ooxml}]} {
  source ../ooxml.tcl
}

set spreadsheet [::ooxml::xl_write new -creator {User A} -created {2019-08-10 10:01:30} -modifiedby {User B} -modified {2019-08-10 12:30:01} -application {Tcl Example Script 9}]
set wrap [$spreadsheet style -wrap]

if {[set sheet [$spreadsheet worksheet {Sheet 1}]] > -1} {
  $spreadsheet cell $sheet {my text the will be automatically wrapped by excel} -index A1 -style $wrap
  $spreadsheet write export9.xlsx
}
$spreadsheet destroy

Changes to ooxml.tcl.

94
95
96
97
98
99
100




101
102
103
104
105
106
107
....
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421



1422


1423


















1424
1425
1426
1427
1428
1429
1430
....
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
....
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
#   return workbookData
# 
# 
# ::ooxml::xl_write
# 
#   constructor args
#     -creator CREATOR




#     return class
# 
#   method numberformat args
#     -format FORMAT -general -date -time -datetime -iso8601 -number -decimal -red -separator -fraction -scientific -percent -text -string
#     return NUMFMTID
#
#   method defaultdatestyle STYLEID
................................................................................
    my variable fonts
    my variable numFmts
    my variable styles
    my variable fills
    my variable borders
    my variable cols

    if {[::ooxml::Getopt opts {creator.arg {unknown}} $args]} {
      error $opts(-errmsg)
    }

    set obj(blockPreset) 0

    set obj(encoding) utf-8
    set obj(indent) none




    set obj(creator) $opts(creator)


    set obj(created) [clock format [clock seconds] -format %Y-%m-%dT%H:%M:%SZ -gmt 1]



















    set obj(sheets) 0
    array set sheets {}

    set obj(sharedStrings) 0
    set sharedStrings {}

................................................................................
      dom createNodeCmd -tagName $tag elementNode Tag_$tag
    }

    $root setAttribute xmlns http://schemas.openxmlformats.org/officeDocument/2006/extended-properties
    $root setAttribute xmlns:vt http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes

    $root appendFromScript {
      Tag_Application { Text {Tcl - Office Open XML - Spreadsheet} }
      Tag_DocSecurity { Text 0 }
      Tag_ScaleCrop { Text false }
      Tag_HeadingPairs {
	Tag_vt:vector size 2 baseType variant {
	  Tag_vt:variant {
	    Tag_vt:lpstr { Text [msgcat::mc Worksheets] }
	  }
................................................................................
    $root setAttribute xmlns:dc http://purl.org/dc/elements/1.1/
    $root setAttribute xmlns:dcterms http://purl.org/dc/terms/
    $root setAttribute xmlns:dcmitype http://purl.org/dc/dcmitype/
    $root setAttribute xmlns:xsi http://www.w3.org/2001/XMLSchema-instance

    $root appendFromScript {
      Tag_dc:creator { Text $obj(creator) }
      Tag_cp:lastModifiedBy { Text $obj(creator) }
      Tag_dcterms:created xsi:type dcterms:W3CDTF { Text $obj(created) }
      Tag_dcterms:modified xsi:type dcterms:W3CDTF { Text $obj(created) }
    }


    # xl/_rels/workbook.xml.rels
    set doc [set obj(doc,xl/_rels/workbook.xml.rels) [dom createDocument Relationships]]
    set root [$doc documentElement]








>
>
>
>







 







|








>
>
>
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|







 







|

|







94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
....
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
....
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
....
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
#   return workbookData
# 
# 
# ::ooxml::xl_write
# 
#   constructor args
#     -creator CREATOR
#     -created UTC-TIMESTAMP
#     -modifiedby NAME
#     -modified UTC-TIMESTAMP
#     -application NAME
#     return class
# 
#   method numberformat args
#     -format FORMAT -general -date -time -datetime -iso8601 -number -decimal -red -separator -fraction -scientific -percent -text -string
#     return NUMFMTID
#
#   method defaultdatestyle STYLEID
................................................................................
    my variable fonts
    my variable numFmts
    my variable styles
    my variable fills
    my variable borders
    my variable cols

    if {[::ooxml::Getopt opts {creator.arg {unknown} created.arg {} modifiedby.arg {} modified.arg {} application.arg {}} $args]} {
      error $opts(-errmsg)
    }

    set obj(blockPreset) 0

    set obj(encoding) utf-8
    set obj(indent) none

    if {[string trim $opts(creator)] eq {}} {
      set obj(creator) {unknown}
    } else {
      set obj(creator) $opts(creator)
    }
    if {[string trim $opts(created)] eq {} || [catch {clock scan $opts(created)}]} {
      set obj(created) [clock format [clock seconds] -format %Y-%m-%dT%H:%M:%SZ -gmt 1]
    } else {
      set obj(created) [clock format [clock scan $opts(created) -gmt 1] -format %Y-%m-%dT%H:%M:%SZ -gmt 1]
    }
    if {[string trim $opts(modifiedby)] eq {}} {
      set obj(lastModifiedBy) $opts(creator)
    } else {
      set obj(lastModifiedBy) $opts(modifiedby)
    }
    if {[string trim $opts(modified)] eq {} || [catch {clock scan $opts(modified)}]} {
      set obj(modified) [clock format [clock seconds] -format %Y-%m-%dT%H:%M:%SZ -gmt 1]
    } else {
      set obj(modified) [clock format [clock scan $opts(modified) -gmt 1] -format %Y-%m-%dT%H:%M:%SZ -gmt 1]
    }
    if {[string trim $opts(application)] eq {}} {
      set obj(application) {Tcl - Office Open XML - Spreadsheet}
    } else {
      set obj(application) $opts(application)
    }

    set obj(sheets) 0
    array set sheets {}

    set obj(sharedStrings) 0
    set sharedStrings {}

................................................................................
      dom createNodeCmd -tagName $tag elementNode Tag_$tag
    }

    $root setAttribute xmlns http://schemas.openxmlformats.org/officeDocument/2006/extended-properties
    $root setAttribute xmlns:vt http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes

    $root appendFromScript {
      Tag_Application { Text $obj(application) }
      Tag_DocSecurity { Text 0 }
      Tag_ScaleCrop { Text false }
      Tag_HeadingPairs {
	Tag_vt:vector size 2 baseType variant {
	  Tag_vt:variant {
	    Tag_vt:lpstr { Text [msgcat::mc Worksheets] }
	  }
................................................................................
    $root setAttribute xmlns:dc http://purl.org/dc/elements/1.1/
    $root setAttribute xmlns:dcterms http://purl.org/dc/terms/
    $root setAttribute xmlns:dcmitype http://purl.org/dc/dcmitype/
    $root setAttribute xmlns:xsi http://www.w3.org/2001/XMLSchema-instance

    $root appendFromScript {
      Tag_dc:creator { Text $obj(creator) }
      Tag_cp:lastModifiedBy { Text $obj(lastModifiedBy) }
      Tag_dcterms:created xsi:type dcterms:W3CDTF { Text $obj(created) }
      Tag_dcterms:modified xsi:type dcterms:W3CDTF { Text $obj(modified) }
    }


    # xl/_rels/workbook.xml.rels
    set doc [set obj(doc,xl/_rels/workbook.xml.rels) [dom createDocument Relationships]]
    set root [$doc documentElement]