ooxml

Check-in [ea03e767f5]
Login

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

Overview
Comment:new feature "named formats" for numberformats, fonts, fills, borders and styles
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ea03e767f5ee4e37eca7b8f3d97889314003cbff05fcf5879dc6fd1c7b21aedc
User & Date: alex 2020-03-07 21:37:44
Context
2020-03-08
06:58
short doc update Leaf check-in: 38e545bbb2 user: alex tags: trunk
2020-03-07
21:37
new feature "named formats" for numberformats, fonts, fills, borders and styles check-in: ea03e767f5 user: alex tags: trunk
08:11
bug fix; added test for "named formats" Closed-Leaf check-in: 1fcc546092 user: alex tags: namedfmts
2020-03-05
19:35
ignore "-globalstyle" in versions > 1.5; styles are from now on predefined via method "column" and can be overwritten in method "cell" check-in: 9fc2848c8f user: alex tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ooxml.tcl.

1506
1507
1508
1509
1510
1511
1512

1513
1514
1515
1516
1517
1518
1519
1520


1521
1522
1523
1524
1525
1526
1527
....
1611
1612
1613
1614
1615
1616
1617

1618
1619
1620
1621
1622
1623
1624
....
1629
1630
1631
1632
1633
1634
1635

1636
1637
1638
1639
1640
1641
1642
....
1646
1647
1648
1649
1650
1651
1652













1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667



1668
1669
1670



1671
1672
1673



1674
1675
1676
1677
1678



1679
1680



1681
1682
1683
1684
1685
1686



1687
1688
1689
1690
1691
1692



1693
1694
1695
1696



1697
1698



1699
1700
1701
1702
1703
1704



1705
1706
1707
1708
1709



1710
1711
1712



1713
1714
1715



1716
1717
1718



1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730



1731
1732
1733
1734
1735



1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747



1748
1749
1750
1751
1752

1753



1754
1755
1756
1757
1758
1759

1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772

1773
1774
1775
1776
1777
1778
1779
....
1783
1784
1785
1786
1787
1788
1789













1790
1791
1792
1793
1794
1795
1796
1797
1798
....
1819
1820
1821
1822
1823
1824
1825



1826
1827
1828
1829
1830
1831
1832
1833
1834
1835



1836
1837
1838
1839
1840
1841

1842
1843
1844
1845
1846
1847

1848
1849
1850
1851
1852
1853
1854
....
1858
1859
1860
1861
1862
1863
1864













1865
1866
1867
1868
1869
1870
1871
1872
1873
....
1886
1887
1888
1889
1890
1891
1892



1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903



1904
1905
1906
1907
1908
1909

1910
1911
1912
1913
1914
1915
1916
....
1917
1918
1919
1920
1921
1922
1923

1924
1925
1926
1927
1928
1929
1930
....
1934
1935
1936
1937
1938
1939
1940













1941
1942
1943
1944
1945
1946
1947
1948
1949
....
2004
2005
2006
2007
2008
2009
2010



2011
2012
2013
2014
2015
2016
2017
2018



2019
2020
2021
2022
2023
2024

2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036

2037
2038
2039
2040
2041
2042
2043
....
2047
2048
2049
2050
2051
2052
2053













2054
2055
2056
2057
2058
2059
2060
2061
2062













2063
2064
2065
2066
2067
2068
2069
....
2097
2098
2099
2100
2101
2102
2103



2104
2105
2106
2107
2108
2109
2110
2111
2112
2113



2114
2115
2116
2117
2118
2119
2120
....
2134
2135
2136
2137
2138
2139
2140

2141
2142
2143
2144
2145
2146
2147
....
2167
2168
2169
2170
2171
2172
2173




2174
2175
2176
2177
2178
2179
2180
....
2266
2267
2268
2269
2270
2271
2272

2273
2274
2275
2276
2277
2278
2279
....
2299
2300
2301
2302
2303
2304
2305




2306
2307
2308
2309
2310
2311
2312
    my variable fonts
    my variable numFmts
    my variable styles
    my variable fills
    my variable borders
    my variable cols
    my variable view


    array set opts {
      creator {unknown}
      created {}
      modifiedby {}
      modified {}
      application {}
    }



    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
        -creator - -created - -modifiedby - -modified - -application {
	  incr idx
................................................................................
  destructor {
    return 0
  }

  method numberformat { args } {
    my variable obj
    my variable numFmts


    array set opts {
      list 0
      format {}
      general 0
      date 0
      time 0
................................................................................
      red 0
      separator 0
      fraction 0
      scientific 0
      percent 0
      string 0
      text 0

    }

    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
        -format {
................................................................................
          } else {
            error "option '$opt': missing argument"
          }            
        }
        -list - -general - -date - -time - -datetime - -iso8601 - -number - -decimal - -red - -separator - -fraction - -scientific - -percent - -string - -text {
	  set opts([string range $opt 1 end]) 1
        }













        default {
          error "unknown option \"$opt\", should be: -format, -list, -general, -date, -time, -datetime, -iso8601, -number, -decimal, -red, -separator, -fraction, -scientific, -percent, -string or -text"
        }
      }
    }

    if {$opts(list)} {
      array set tmp [array get ::ooxml::predefNumFmts]
      array set tmp [array get numFmts]
      return [array get tmp]
    }

    set obj(blockPreset) 1

    if {$opts(general)} {



      return 0
    }
    if {$opts(date)} {



      return 14
    }
    if {$opts(time)} {



      return 20
    }
    if {$opts(number)} {
      if {$opts(separator)} {
	if {$opts(red)} {



	  return 38
	} else {



	  return 3
	}
      } else {
	if {$opts(red)} {
	  return -1
	} else {



	  return 1
	}
      }
    }
    if {$opts(decimal)} {
      if {$opts(percent)} {



        return 10
      }
      if {$opts(separator)} {
	if {$opts(red)} {



	  return 40
	} else {



	  return 4
	}
      } else {
	if {$opts(red)} {
	  return -1
	} else {



	  return 2
	}
      }
    }
    if {$opts(fraction)} {



      return 12
    }
    if {$opts(scientific)} {



      return 11
    }
    if {$opts(percent)} {



      return 9
    }
    if {$opts(text) || $opts(string)} {



      return 49
    }

    if {$opts(datetime)} {
      set opts(format) {dd/mm/yyyy\ hh:mm;@}
    }
    if {$opts(iso8601)} {
      set opts(format) {yyyy\-mm\-dd\ hh:mm:ss;@}
    }

    foreach idx [array names ::ooxml::predefNumFmts] {
      if {[dict get $::ooxml::predefNumFmts($idx) fmt] eq $opts(format)} {



        return $idx
      }
    }
    foreach idx [array names numFmts] {
      if {$numFmts($idx) eq $opts(format)} {



        return $idx
      }
    }

    if {$opts(format) eq {}} {
      return -1
    }

    set idx $obj(numFmts)
    set numFmts($idx) $opts(format)
    incr obj(numFmts)




    return $idx
  }

  method defaultdatestyle { style } {
    my variable obj





    set obj(defaultdatestyle) $style
  }

  method font { args } {
    my variable obj
    my variable fonts


    array set a $fonts(0)

    array set opts "
      list 0
      name [list $a(name)]
      family [list $a(family)]
      size [list $a(size)]
      color [list $a(color)]
      scheme [list $a(scheme)]
      bold 0
      italic 0
      underline 0

    "

    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
        -name - -family - -size - -color - -scheme {
................................................................................
          } else {
            error "option '$opt': missing argument"
          }            
        }
        -list - -bold - -italic - -underline {
	  set opts([string range $opt 1 end]) 1
        }













        default {
          error "unknown option \"$opt\", should be: -name, -family, -size, -color, -scheme, -list, -bold, -italic or -underline"
        }
      }
    }

    if {$opts(list)} {
      return [array get fonts]
    }
................................................................................
      foreach name [array names a] {
        if {$a($name) ne $opts($name)} {
	  set found 0
	  break
	}
      }
      if {$found} {



        return $idx
      }
    }

    set fonts($obj(fonts)) {}
    foreach item {name family size bold italic underline color scheme} {
      lappend fonts($obj(fonts)) $item $opts($item)
    }
    set idx $obj(fonts)
    incr obj(fonts)



    return $idx
  }

  method fill { args } {
    my variable obj
    my variable fills


    array set opts {
      list 0
      patterntype none
      fgcolor {}
      bgcolor {}

    }

    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
        -patterntype - -fgcolor - -bgcolor {
................................................................................
          } else {
            error "option '$opt': missing argument"
          }            
        }
        -list {
	  set opts([string range $opt 1 end]) 1
        }













        default {
          error "unknown option \"$opt\", should be: -patterntype, -fgcolor, -bgcolor or -list"
        }
      }
    }

    if {$opts(list)} {
      return [array get fills]
    }
................................................................................
      foreach name [array names a] {
        if {$a($name) ne $opts($name)} {
	  set found 0
	  break
	}
      }
      if {$found} {



        return $idx
      }
    }

    set fills($obj(fills)) {}
    foreach item {patterntype fgcolor bgcolor} {
      lappend fills($obj(fills)) $item $opts($item)
    }
    set idx $obj(fills)
    incr obj(fills)
    



    return $idx
  }

  method border { args } {
    my variable obj
    my variable borders


    array set opts {
      list 0
      leftstyle {}
      leftcolor {}
      rightstyle {}
      rightcolor {}
................................................................................
      topstyle {}
      topcolor {}
      bottomstyle {}
      bottomcolor {}
      diagonalstyle {}
      diagonalcolor {}
      diagonaldirection {}

    }

    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
	-leftstyle - -leftcolor - -rightstyle - -rightcolor - -topstyle - -topcolor - -bottomstyle - -bottomcolor - -diagonalstyle - -diagonalcolor - -diagonaldirection {
................................................................................
          } else {
            error "option '$opt': missing argument"
          }            
        }
        -list {
	  set opts([string range $opt 1 end]) 1
        }













        default {
          error "unknown option \"$opt\", should be: -leftstyle, -leftcolor, -rightstyle, -rightcolor, -topstyle, -topcolor, -bottomstyle, -bottomcolor, -diagonalstyle, -diagonalcolor, -diagonaldirection or -list"
        }
      }
    }

    if {$opts(list)} {
      return [array get borders]
    }
................................................................................
	  if {[dict get $borders($idx) $key $subkey] ne [dict get $tmp $key $subkey]} {
	    set found 0
	    break
	  }
	}
      }
      if {$found} {



        return $idx
      }
    }

    set borders($obj(borders)) $tmp
    set idx $obj(borders)
    incr obj(borders)
    



    return $idx
  }

  method style { args } {
    my variable obj
    my variable styles


    array set opts {
      list 0
      numfmt 0
      font 0
      fill 0
      border 0
      xf 0
      horizontal {}
      vertical {}
      rotate {}
      wrap 0

    }

    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
        -numfmt - -font - -fill - -border - -xf - -horizontal - -vertical - -rotate {
................................................................................
          } else {
            error "option '$opt': missing argument"
          }            
        }
        -list - -wrap {
	  set opts([string range $opt 1 end]) 1
        }













        default {
          error "unknown option \"$opt\", should be: -numfmt, -font, -fill, -border, -xf, -horizontal, -vertical, -rotate, -list or -wrap"
        }
      }
    }

    if {$opts(list)} {
      return [array get styles]
    }














    set obj(blockPreset) 1
    
    if {![string is integer -strict $opts(numfmt)] || $opts(numfmt) < 0} {
      set opts(numfmt) 0
    }
    if {![string is integer -strict $opts(font)] || $opts(font) < 0} {
................................................................................
      foreach name [array names a] {
        if {$a($name) ne $opts($name)} {
	  set found 0
	  break
	}
      }
      if {$found} {



        return $idx
      }
    }

    set styles($obj(styles)) {}
    foreach item {numfmt font fill border xf horizontal vertical rotate wrap} {
      lappend styles($obj(styles)) $item $opts($item)
    }
    set idx $obj(styles)
    incr obj(styles)



    return $idx
  }

  method worksheet { name } {
    my variable obj

    incr obj(sheets)
................................................................................

    return $obj(sheets)
  }

  method column { sheet args } {
    my variable obj
    my variable cols


    array set opts {
      index {}
      to {}
      width {}
      style 0
      bestfit 0
................................................................................
	  set opts([string range $opt 1 end]) 1
        }
        default {
          error "unknown option \"$opt\", should be: -index, -to, -width, -style, -bestfit, -customwidth, -string, -nozero or -calcfit"
        }
      }
    }





    if {[regexp {^\d+$} $opts(index)] && $opts(index) > -1} {
      set obj(gCol,$sheet) $opts(index)
    } elseif {[regexp {^[A-Z]+$} $opts(index)]} {
      set obj(gCol,$sheet) [lindex [split [::ooxml::StringToRowColumn $opts(index)] ,] end]
    } elseif {[string trim $opts(index)] eq {}} {
      incr obj(gCol,$sheet)
................................................................................
    return $row
  }

  method cell { sheet {data {}} args } {
    my variable obj
    my variable cells
    my variable cols


    array set opts {
      index {}
      style -1
      formula {}
      string -1
      nostring -1
................................................................................
	  set opts([string range $opt 1 end]) 1
        }
        default {
          error "unknown option \"$opt\", should be: -index, -style, -formula, -height, -string, nostring, -zero or -nozero"
        }
      }
    }





    if {$opts(nostring) == 1} {
      set opts(string) 0
    }
    if {$opts(zero) == 1} {
      set opts(nozero) 0
    }







>








>
>







 







>







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>

|













>
>
>



>
>
>



>
>
>





>
>
>


>
>
>






>
>
>






>
>
>




>
>
>


>
>
>






>
>
>





>
>
>



>
>
>



>
>
>



>
>
>












>
>
>





>
>
>












>
>
>





>

>
>
>






>













>







 







>
>
>
>
>
>
>
>
>
>
>
>
>

|







 







>
>
>










>
>
>






>






>







 







>
>
>
>
>
>
>
>
>
>
>
>
>

|







 







>
>
>











>
>
>






>







 







>







 







>
>
>
>
>
>
>
>
>
>
>
>
>

|







 







>
>
>








>
>
>






>












>







 







>
>
>
>
>
>
>
>
>
>
>
>
>

|







>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>










>
>
>







 







>







 







>
>
>
>







 







>







 







>
>
>
>







1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
....
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
....
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
....
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
....
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
....
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
....
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
....
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
....
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
....
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
....
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
....
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
....
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
....
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
....
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
....
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
....
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
    my variable fonts
    my variable numFmts
    my variable styles
    my variable fills
    my variable borders
    my variable cols
    my variable view
    my variable tags

    array set opts {
      creator {unknown}
      created {}
      modifiedby {}
      modified {}
      application {}
    }

    array set tags {}

    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
        -creator - -created - -modifiedby - -modified - -application {
	  incr idx
................................................................................
  destructor {
    return 0
  }

  method numberformat { args } {
    my variable obj
    my variable numFmts
    my variable tags

    array set opts {
      list 0
      format {}
      general 0
      date 0
      time 0
................................................................................
      red 0
      separator 0
      fraction 0
      scientific 0
      percent 0
      string 0
      text 0
      tag {}
    }

    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
        -format {
................................................................................
          } else {
            error "option '$opt': missing argument"
          }            
        }
        -list - -general - -date - -time - -datetime - -iso8601 - -number - -decimal - -red - -separator - -fraction - -scientific - -percent - -string - -text {
	  set opts([string range $opt 1 end]) 1
        }
        -tag {
	  incr idx
          if {$idx < $len} {
	    if {[string is integer -strict [set tag [lindex $args $idx]]]} {
	      error "option '$opt': should not be an integer value"
	    } else {
	      set opts([string range $opt 1 end]) $tag
	    } 
	    unset tag
          } else {
            error "option '$opt': missing argument"
          }            
        }
        default {
          error "unknown option \"$opt\", should be: -format, -list, -general, -date, -time, -datetime, -iso8601, -number, -decimal, -red, -separator, -fraction, -scientific, -percent, -string, -text or tag"
        }
      }
    }

    if {$opts(list)} {
      array set tmp [array get ::ooxml::predefNumFmts]
      array set tmp [array get numFmts]
      return [array get tmp]
    }

    set obj(blockPreset) 1

    if {$opts(general)} {
      if {$opts(tag) ne {}} {
	set tags(numFmts,$opts(tag)) 0
      }
      return 0
    }
    if {$opts(date)} {
      if {$opts(tag) ne {}} {
	set tags(numFmts,$opts(tag)) 14
      }
      return 14
    }
    if {$opts(time)} {
      if {$opts(tag) ne {}} {
	set tags(numFmts,$opts(tag)) 20
      }
      return 20
    }
    if {$opts(number)} {
      if {$opts(separator)} {
	if {$opts(red)} {
	  if {$opts(tag) ne {}} {
	    set tags(numFmts,$opts(tag)) 38
	  }
	  return 38
	} else {
	  if {$opts(tag) ne {}} {
	    set tags(numFmts,$opts(tag)) 3
	  }
	  return 3
	}
      } else {
	if {$opts(red)} {
	  return -1
	} else {
	  if {$opts(tag) ne {}} {
	    set tags(numFmts,$opts(tag)) 1
	  }
	  return 1
	}
      }
    }
    if {$opts(decimal)} {
      if {$opts(percent)} {
	if {$opts(tag) ne {}} {
	  set tags(numFmts,$opts(tag)) 10
	}
        return 10
      }
      if {$opts(separator)} {
	if {$opts(red)} {
	  if {$opts(tag) ne {}} {
	    set tags(numFmts,$opts(tag)) 40
	  }
	  return 40
	} else {
	  if {$opts(tag) ne {}} {
	    set tags(numFmts,$opts(tag)) 4
	  }
	  return 4
	}
      } else {
	if {$opts(red)} {
	  return -1
	} else {
	  if {$opts(tag) ne {}} {
	    set tags(numFmts,$opts(tag)) 2
	  }
	  return 2
	}
      }
    }
    if {$opts(fraction)} {
      if {$opts(tag) ne {}} {
	set tags(numFmts,$opts(tag)) 12
      }
      return 12
    }
    if {$opts(scientific)} {
      if {$opts(tag) ne {}} {
	set tags(numFmts,$opts(tag)) 11
      }
      return 11
    }
    if {$opts(percent)} {
      if {$opts(tag) ne {}} {
	set tags(numFmts,$opts(tag)) 9
      }
      return 9
    }
    if {$opts(text) || $opts(string)} {
      if {$opts(tag) ne {}} {
	set tags(numFmts,$opts(tag)) 49
      }
      return 49
    }

    if {$opts(datetime)} {
      set opts(format) {dd/mm/yyyy\ hh:mm;@}
    }
    if {$opts(iso8601)} {
      set opts(format) {yyyy\-mm\-dd\ hh:mm:ss;@}
    }

    foreach idx [array names ::ooxml::predefNumFmts] {
      if {[dict get $::ooxml::predefNumFmts($idx) fmt] eq $opts(format)} {
	if {$opts(tag) ne {}} {
	  set tags(numFmts,$opts(tag)) $idx
	}
        return $idx
      }
    }
    foreach idx [array names numFmts] {
      if {$numFmts($idx) eq $opts(format)} {
	if {$opts(tag) ne {}} {
	  set tags(numFmts,$opts(tag)) $idx
	}
        return $idx
      }
    }

    if {$opts(format) eq {}} {
      return -1
    }

    set idx $obj(numFmts)
    set numFmts($idx) $opts(format)
    incr obj(numFmts)

    if {$opts(tag) ne {}} {
      set tags(numFmts,$opts(tag)) $idx
    }
    return $idx
  }

  method defaultdatestyle { style } {
    my variable obj
    my variable tags

    if {![string is integer -strict $style] && [info exists tags(styles,$style)]} {
      set style $tags(styles,$style)]
    }
    set obj(defaultdatestyle) $style
  }

  method font { args } {
    my variable obj
    my variable fonts
    my variable tags

    array set a $fonts(0)

    array set opts "
      list 0
      name [list $a(name)]
      family [list $a(family)]
      size [list $a(size)]
      color [list $a(color)]
      scheme [list $a(scheme)]
      bold 0
      italic 0
      underline 0
      tag {}
    "

    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
        -name - -family - -size - -color - -scheme {
................................................................................
          } else {
            error "option '$opt': missing argument"
          }            
        }
        -list - -bold - -italic - -underline {
	  set opts([string range $opt 1 end]) 1
        }
        -tag {
	  incr idx
          if {$idx < $len} {
	    if {[string is integer -strict [set tag [lindex $args $idx]]]} {
	      error "option '$opt': should not be an integer value"
	    } else {
	      set opts([string range $opt 1 end]) $tag
	    } 
	    unset tag
          } else {
            error "option '$opt': missing argument"
          }            
        }
        default {
          error "unknown option \"$opt\", should be: -name, -family, -size, -color, -scheme, -list, -bold, -italic, -underline or -tag"
        }
      }
    }

    if {$opts(list)} {
      return [array get fonts]
    }
................................................................................
      foreach name [array names a] {
        if {$a($name) ne $opts($name)} {
	  set found 0
	  break
	}
      }
      if {$found} {
	if {$opts(tag) ne {}} {
	  set tags(fonts,$opts(tag)) $idx
	}
        return $idx
      }
    }

    set fonts($obj(fonts)) {}
    foreach item {name family size bold italic underline color scheme} {
      lappend fonts($obj(fonts)) $item $opts($item)
    }
    set idx $obj(fonts)
    incr obj(fonts)
    if {$opts(tag) ne {}} {
      set tags(fonts,$opts(tag)) $idx
    }
    return $idx
  }

  method fill { args } {
    my variable obj
    my variable fills
    my variable tags

    array set opts {
      list 0
      patterntype none
      fgcolor {}
      bgcolor {}
      tag {}
    }

    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
        -patterntype - -fgcolor - -bgcolor {
................................................................................
          } else {
            error "option '$opt': missing argument"
          }            
        }
        -list {
	  set opts([string range $opt 1 end]) 1
        }
        -tag {
	  incr idx
          if {$idx < $len} {
	    if {[string is integer -strict [set tag [lindex $args $idx]]]} {
	      error "option '$opt': should not be an integer value"
	    } else {
	      set opts([string range $opt 1 end]) $tag
	    } 
	    unset tag
          } else {
            error "option '$opt': missing argument"
          }            
        }
        default {
          error "unknown option \"$opt\", should be: -patterntype, -fgcolor, -bgcolor, -list or -tag"
        }
      }
    }

    if {$opts(list)} {
      return [array get fills]
    }
................................................................................
      foreach name [array names a] {
        if {$a($name) ne $opts($name)} {
	  set found 0
	  break
	}
      }
      if {$found} {
	if {$opts(tag) ne {}} {
	  set tags(fills,$opts(tag)) $idx
	}
        return $idx
      }
    }

    set fills($obj(fills)) {}
    foreach item {patterntype fgcolor bgcolor} {
      lappend fills($obj(fills)) $item $opts($item)
    }
    set idx $obj(fills)
    incr obj(fills)
    
    if {$opts(tag) ne {}} {
      set tags(fills,$opts(tag)) $idx
    }
    return $idx
  }

  method border { args } {
    my variable obj
    my variable borders
    my variable tags

    array set opts {
      list 0
      leftstyle {}
      leftcolor {}
      rightstyle {}
      rightcolor {}
................................................................................
      topstyle {}
      topcolor {}
      bottomstyle {}
      bottomcolor {}
      diagonalstyle {}
      diagonalcolor {}
      diagonaldirection {}
      tag {}
    }

    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
	-leftstyle - -leftcolor - -rightstyle - -rightcolor - -topstyle - -topcolor - -bottomstyle - -bottomcolor - -diagonalstyle - -diagonalcolor - -diagonaldirection {
................................................................................
          } else {
            error "option '$opt': missing argument"
          }            
        }
        -list {
	  set opts([string range $opt 1 end]) 1
        }
        -tag {
	  incr idx
          if {$idx < $len} {
	    if {[string is integer -strict [set tag [lindex $args $idx]]]} {
	      error "option '$opt': should not be an integer value"
	    } else {
	      set opts([string range $opt 1 end]) $tag
	    } 
	    unset tag
          } else {
            error "option '$opt': missing argument"
          }            
        }
        default {
          error "unknown option \"$opt\", should be: -leftstyle, -leftcolor, -rightstyle, -rightcolor, -topstyle, -topcolor, -bottomstyle, -bottomcolor, -diagonalstyle, -diagonalcolor, -diagonaldirection, -list or -tag"
        }
      }
    }

    if {$opts(list)} {
      return [array get borders]
    }
................................................................................
	  if {[dict get $borders($idx) $key $subkey] ne [dict get $tmp $key $subkey]} {
	    set found 0
	    break
	  }
	}
      }
      if {$found} {
	if {$opts(tag) ne {}} {
	  set tags(borders,$opts(tag)) $idx
	}
        return $idx
      }
    }

    set borders($obj(borders)) $tmp
    set idx $obj(borders)
    incr obj(borders)
    
    if {$opts(tag) ne {}} {
      set tags(borders,$opts(tag)) $idx
    }
    return $idx
  }

  method style { args } {
    my variable obj
    my variable styles
    my variable tags

    array set opts {
      list 0
      numfmt 0
      font 0
      fill 0
      border 0
      xf 0
      horizontal {}
      vertical {}
      rotate {}
      wrap 0
      tag {}
    }

    set len [llength $args]
    set idx 0
    for {set idx 0} {$idx < $len} {incr idx} {
      switch -- [set opt [lindex $args $idx]] {
        -numfmt - -font - -fill - -border - -xf - -horizontal - -vertical - -rotate {
................................................................................
          } else {
            error "option '$opt': missing argument"
          }            
        }
        -list - -wrap {
	  set opts([string range $opt 1 end]) 1
        }
        -tag {
	  incr idx
          if {$idx < $len} {
	    if {[string is integer -strict [set tag [lindex $args $idx]]]} {
	      error "option '$opt': should not be an integer value"
	    } else {
	      set opts([string range $opt 1 end]) $tag
	    } 
	    unset tag
          } else {
            error "option '$opt': missing argument"
          }            
        }
        default {
          error "unknown option \"$opt\", should be: -numfmt, -font, -fill, -border, -xf, -horizontal, -vertical, -rotate, -list, -wrap or -tag"
        }
      }
    }

    if {$opts(list)} {
      return [array get styles]
    }

    if {![string is integer -strict $opts(numfmt)] && [info exists tags(numFmts,$opts(numfmt))]} {
      set opts(numfmt) $tags(numFmts,$opts(numfmt))
    }
    if {![string is integer -strict $opts(font)] && [info exists tags(fonts,$opts(font))]} {
      set opts(font) $tags(fonts,$opts(font))
    }
    if {![string is integer -strict $opts(fill)] && [info exists tags(fills,$opts(fill))]} {
      set opts(fill) $tags(fills,$opts(fill))
    }
    if {![string is integer -strict $opts(border)] && [info exists tags(borders,$opts(border))]} {
      set opts(border) $tags(borders,$opts(border))
    }

    set obj(blockPreset) 1
    
    if {![string is integer -strict $opts(numfmt)] || $opts(numfmt) < 0} {
      set opts(numfmt) 0
    }
    if {![string is integer -strict $opts(font)] || $opts(font) < 0} {
................................................................................
      foreach name [array names a] {
        if {$a($name) ne $opts($name)} {
	  set found 0
	  break
	}
      }
      if {$found} {
	if {$opts(tag) ne {}} {
	  set tags(styles,$opts(tag)) $idx
	}
        return $idx
      }
    }

    set styles($obj(styles)) {}
    foreach item {numfmt font fill border xf horizontal vertical rotate wrap} {
      lappend styles($obj(styles)) $item $opts($item)
    }
    set idx $obj(styles)
    incr obj(styles)
    if {$opts(tag) ne {}} {
      set tags(styles,$opts(tag)) $idx
    }
    return $idx
  }

  method worksheet { name } {
    my variable obj

    incr obj(sheets)
................................................................................

    return $obj(sheets)
  }

  method column { sheet args } {
    my variable obj
    my variable cols
    my variable tags

    array set opts {
      index {}
      to {}
      width {}
      style 0
      bestfit 0
................................................................................
	  set opts([string range $opt 1 end]) 1
        }
        default {
          error "unknown option \"$opt\", should be: -index, -to, -width, -style, -bestfit, -customwidth, -string, -nozero or -calcfit"
        }
      }
    }

    if {![string is integer -strict $opts(style)] && [info exists tags(styles,$opts(style))]} {
      set opts(style) $tags(styles,$opts(style))
    }

    if {[regexp {^\d+$} $opts(index)] && $opts(index) > -1} {
      set obj(gCol,$sheet) $opts(index)
    } elseif {[regexp {^[A-Z]+$} $opts(index)]} {
      set obj(gCol,$sheet) [lindex [split [::ooxml::StringToRowColumn $opts(index)] ,] end]
    } elseif {[string trim $opts(index)] eq {}} {
      incr obj(gCol,$sheet)
................................................................................
    return $row
  }

  method cell { sheet {data {}} args } {
    my variable obj
    my variable cells
    my variable cols
    my variable tags

    array set opts {
      index {}
      style -1
      formula {}
      string -1
      nostring -1
................................................................................
	  set opts([string range $opt 1 end]) 1
        }
        default {
          error "unknown option \"$opt\", should be: -index, -style, -formula, -height, -string, nostring, -zero or -nozero"
        }
      }
    }

    if {![string is integer -strict $opts(style)] && [info exists tags(styles,$opts(style))]} {
      set opts(style) $tags(styles,$opts(style))
    }

    if {$opts(nostring) == 1} {
      set opts(string) 0
    }
    if {$opts(zero) == 1} {
      set opts(nozero) 0
    }

Added tests/namedfmts.test.





























































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#
# Commands covered: simple excel sheet
#

#
# (c) 2019 Alexander Schoepe
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

if {[lsearch [namespace children] ::tcltest] == -1} {
  package require tcltest 2
  namespace import -force ::tcltest::*
  loadTestedCommands
}


package require ooxml
package require vfs::zip

test NamedFormats-1.1 {Write a Simple Excel Sheet} {
  set cDT {2020-03-07 07:12:23}
  set mCT $cDT

  set spreadsheet [::ooxml::xl_write new -creator {User A} -created $cDT -modifiedby {User B} -modified $mCT -application {Tcl Test}]
  if {[set sheet [$spreadsheet worksheet {Sheet 1}]] > -1} {
    return 1
  }
  return 0
} 1


test NamedFormats-2.1 {numberformat dec2t} {
  $spreadsheet numberformat -decimal -separator -tag dec2t
} 4

test NamedFormats-2.2 {numberformat dec2t} {
  upvar #0 ${spreadsheet}::tags tags
  info exists tags(numFmts,dec2t)
} 1

test NamedFormats-2.2 {numberformat dec2t} {
  upvar #0 ${spreadsheet}::tags tags
  return $tags(numFmts,dec2t)
} 4

test NamedFormats-2.3 {style numberformat dec2t} {
  $spreadsheet style -numfmt dec2t -tag dec2t
} 1

test NamedFormats-2.4 {style numberformat dec2t} {
  upvar #0 ${spreadsheet}::tags tags
  if {[info exists tags(styles,dec2t)]} {
    return $tags(styles,dec2t)
  }
  return -1
} 1


test NamedFormats-3.1 {numberformat fraction2} {
  $spreadsheet numberformat -format {# ??/??} -tag fraction2
} 166

test NamedFormats-3.2 {numberformat fraction2} {
  upvar #0 ${spreadsheet}::tags tags
  info exists tags(numFmts,fraction2)
} 1

test NamedFormats-3.2 {numberformat fraction2} {
  upvar #0 ${spreadsheet}::tags tags
  return $tags(numFmts,fraction2)
} 166

test NamedFormats-3.3 {style numberformat fraction2} {
  $spreadsheet style -numfmt fraction2 -tag fraction2
} 2

test NamedFormats-3.4 {style numberformat fraction2} {
  upvar #0 ${spreadsheet}::tags tags
  if {[info exists tags(styles,fraction2)]} {
    return $tags(styles,fraction2)
  }
  return -1
} 2


test NamedFormats-4.1 {font font9} {
  $spreadsheet font -size 9 -tag font9
} 1

test NamedFormats-4.2 {font font9} {
  upvar #0 ${spreadsheet}::tags tags
  info exists tags(fonts,font9)
} 1

test NamedFormats-4.2 {font font9} {
  upvar #0 ${spreadsheet}::tags tags
  return $tags(fonts,font9)
} 1

test NamedFormats-4.3 {style font font9} {
  $spreadsheet style -font font9 -tag font9
} 3

test NamedFormats-4.4 {style font font9} {
  upvar #0 ${spreadsheet}::tags tags
  if {[info exists tags(styles,font9)]} {
    return $tags(styles,font9)
  }
  return -1
} 3


test NamedFormats-5.1 {fill yellow} {
  $spreadsheet fill -fgcolor FFFFFF00 -bgcolor 64 -patterntype solid -tag yellow
} 2

test NamedFormats-5.2 {fill yellow} {
  upvar #0 ${spreadsheet}::tags tags
  info exists tags(fills,yellow)
} 1

test NamedFormats-5.2 {fill yellow} {
  upvar #0 ${spreadsheet}::tags tags
  return $tags(fills,yellow)
} 2

test NamedFormats-5.3 {style fill yellow} {
  $spreadsheet style -fill yellow -tag yellow
} 4

test NamedFormats-5.4 {style fill yellow} {
  upvar #0 ${spreadsheet}::tags tags
  if {[info exists tags(styles,yellow)]} {
    return $tags(styles,yellow)
  }
  return -1
} 4


test NamedFormats-6.1 {border bDiagonal} {
  $spreadsheet border -diagonalstyle medium -diagonaldirection up -tag bDiagonal
} 1

test NamedFormats-6.2 {border bDiagonal} {
  upvar #0 ${spreadsheet}::tags tags
  info exists tags(borders,bDiagonal)
} 1

test NamedFormats-6.2 {border bDiagonal} {
  upvar #0 ${spreadsheet}::tags tags
  return $tags(borders,bDiagonal)
} 1

test NamedFormats-6.3 {style border bDiagonal} {
  $spreadsheet style -border bDiagonal -tag bDiagonal
} 5

test NamedFormats-6.4 {style border bDiagonal} {
  upvar #0 ${spreadsheet}::tags tags
  if {[info exists tags(styles,bDiagonal)]} {
    return $tags(styles,bDiagonal)
  }
  return -1
} 5


$spreadsheet destroy

# cleanup
::tcltest::cleanupTests
return