ooxml

Changes On Branch idomidioms
Login

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

Changes In Branch idomidioms Excluding Merge-Ins

This is equivalent to a diff from 01bd44f007 to 0c42ce5e46

2019-08-08
13:32
merged idomidioms check-in: 07a138a2f1 user: alex tags: trunk
2019-08-07
20:00
Fixed two places with potential dangerous usage of tcl variable references within XPath expressions. Leaf check-in: 0c42ce5e46 user: rolf tags: idomidioms
19:37
Replaced all the "-namespaces [list X ...]" options on selectNodes method calls by using the doc global prefix namespace mapping. check-in: a29e597dac user: rolf tags: idomidioms
19:30
merged idomidioms check-in: fd20448a1d user: alex tags: trunk
18:32
Use the short-cut syntax @attname instead of the getAttribute method. check-in: 0d90d32d80 user: rolf tags: idomidioms
09:16
code cleanup check-in: 01bd44f007 user: alex tags: trunk
2019-07-15
20:40
style -wrap (wrapText) check-in: 6be30c4acc user: alex tags: trunk

Changes to examples/sample4.tcl.

1
2
3
4
5
6


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

lappend auto_path .
package require ooxml



source array.tcl

set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
if {[set sheet [$spreadsheet worksheet {Tabelle 1}]] > -1} {
  $spreadsheet row $sheet
  $spreadsheet cell $sheet 3
  $spreadsheet cell $sheet 5
  $spreadsheet cell $sheet {} -formula A1+B1

  $spreadsheet write export4.xlsx
}
$spreadsheet destroy





|
>
>













1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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
  $spreadsheet cell $sheet 3
  $spreadsheet cell $sheet 5
  $spreadsheet cell $sheet {} -formula A1+B1

  $spreadsheet write export4.xlsx
}
$spreadsheet destroy

Changes to ooxml.tcl.

906
907
908
909
910
911
912

913
914
915
916
917
918
919
920

921
922
923
924
925
926
927
928
929
930
931
932
933
934

  set rels 0
  if {![catch {open xlsx/xl/_rels/workbook.xml.rels r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} rdoc]} {
      set rels 1
      set relsroot [$rdoc documentElement]

    }
    close $fd
  }

  if {![catch {open xlsx/xl/workbook.xml r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} doc]} {
      set root [$doc documentElement]

      set idx -1
      foreach node [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:workbook/X:sheets/X:sheet}] {
	if {[$node hasAttribute sheetId] && [$node hasAttribute name]} {
	  set sheetId [$node getAttribute sheetId]
	  set name [$node getAttribute name]
	  set rid [$node getAttribute r:id]
	  foreach node [$relsroot selectNodes -namespaces [list X [$relsroot namespaceURI]] [subst -nobackslashes -nocommands {/X:Relationships/X:Relationship[@Id="$rid"]}]] {
	    if {[$node hasAttribute Target]} {
	      lappend sheets [incr idx] [list sheetId $sheetId name $name rId $rid]
	    }
	  }
	}
      }
      $doc delete







>








>

|

|
|
|
|







906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936

  set rels 0
  if {![catch {open xlsx/xl/_rels/workbook.xml.rels r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} rdoc]} {
      set rels 1
      set relsroot [$rdoc documentElement]
      $rdoc selectNodesNamespaces [list X [$relsroot namespaceURI]]
    }
    close $fd
  }

  if {![catch {open xlsx/xl/workbook.xml r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} doc]} {
      set root [$doc documentElement]
      $doc selectNodesNamespaces [list X [$root namespaceURI]]
      set idx -1
      foreach node [$root selectNodes /X:workbook/X:sheets/X:sheet] {
	if {[$node hasAttribute sheetId] && [$node hasAttribute name]} {
	  set sheetId [$node @sheetId]
	  set name [$node @name]
	  set rid [$node @r:id]
	  foreach node [$relsroot selectNodes {/X:Relationships/X:Relationship[@Id=$rid]}] {
	    if {[$node hasAttribute Target]} {
	      lappend sheets [incr idx] [list sheetId $sheetId name $name rId $rid]
	    }
	  }
	}
      }
      $doc delete
970
971
972
973
974
975
976

977
978
979
980
981
982
983
984

985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010

1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030

1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197

  set rels 0
  if {![catch {open xlsx/xl/_rels/workbook.xml.rels r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} rdoc]} {
      set rels 1
      set relsroot [$rdoc documentElement]

    }
    close $fd
  }

  if {![catch {open xlsx/xl/workbook.xml r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} doc]} {
      set root [$doc documentElement]

      set idx -1
      foreach node [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:workbook/X:sheets/X:sheet}] {
	if {[$node hasAttribute sheetId] && [$node hasAttribute name]} {
	  set sheetId [$node getAttribute sheetId]
	  set name [$node getAttribute name]
	  set rid [$node getAttribute r:id]
	  foreach node [$relsroot selectNodes -namespaces [list X [$relsroot namespaceURI]] [subst -nobackslashes -nocommands {/X:Relationships/X:Relationship[@Id="$rid"]}]] {
	    if {[$node hasAttribute Target]} {
	      lappend sheets [incr idx] $sheetId $name $rid [$node getAttribute Target]
	    }
	  }
	}
      }
      $doc delete
    }
    close $fd
  }

  if {$rels} {
    $rdoc delete
  }

  if {![catch {open xlsx/xl/sharedStrings.xml r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} doc]} {
      set root [$doc documentElement]

      set idx -1
      foreach shared [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:sst/X:si}] {
	incr idx
	foreach node [$shared selectNodes -namespaces [list X [$shared namespaceURI]] {X:t/text()}] {
	  append sharedStrings($idx) [$node nodeValue]
	}
	foreach node [$shared selectNodes -namespaces [list X [$shared namespaceURI]] {*/X:t/text()}] {
	  append sharedStrings($idx) [$node nodeValue]
	}
      }
      $doc delete
    }
    close $fd
  }


  if {![catch {open xlsx/xl/styles.xml r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} doc]} {
      set root [$doc documentElement]

      set idx -1
      foreach node [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:styleSheet/X:numFmts/X:numFmt}] {
        incr idx
	if {[$node hasAttribute numFmtId] && [$node hasAttribute formatCode]} {
	  set numFmtId [$node getAttribute numFmtId]
	  set formatCode [$node getAttribute formatCode]
	  set datetime 0
	  foreach tag {*y* *m* *d* *h* *s*} {
	    if {[string match -nocase $tag [string map {Black {} Blue {} Cyan {} Green {} Magenta {} Red {} White {} Yellow {}} $formatCode]]} {
	      set datetime 1
	      break
	    }
	  }
	  set numFmts($numFmtId) [list dt $datetime fmt $formatCode]
	}
      }
      set idx -1
      foreach node [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:styleSheet/X:cellXfs/X:xf}] {
        incr idx
	if {[$node hasAttribute numFmtId]} {
	  set numFmtId [$node getAttribute numFmtId]
	  if {[$node hasAttribute applyNumberFormat]} {
	    set applyNumberFormat [$node getAttribute applyNumberFormat]
	  } else {
	    set applyNumberFormat 0
	  }
	  set cellXfs($idx) [list nfi $numFmtId anf $applyNumberFormat]
	}
      }

      ### READING KNOWN FORMATS AND STYLES ###

      set wb(s,@) {}

      array unset a *
      set a(max) 0
      set wb(s,numFmtsIds) {}
      foreach node [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:styleSheet/X:numFmts/X:numFmt}] {
        if {[$node hasAttribute numFmtId] && [$node hasAttribute formatCode]} {
	  set wb(s,numFmts,[set idx [$node getAttribute numFmtId]]) [$node getAttribute formatCode]
	  lappend wb(s,numFmtsIds) $idx
	  if {$idx > $a(max)} {
	    set a(max) $idx
	  }
	}
      }
      if {$a(max) < $::ooxml::defaults(numFmts,start)} {
        set a(max) $::ooxml::defaults(numFmts,start)
      }
      lappend wb(s,@) numFmtId [incr a(max)]


      set idx -1
      array unset a *
      foreach node [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:styleSheet/X:fonts/X:font}] {
	incr idx
	array set a {name {} family {} size {} color {} scheme {} bold 0 italic 0 underline 0 color {}}
	foreach node1 [$node childNodes] {
	  switch -- [$node1 nodeName] {
	    b {
	      set a(bold) 1
	    }
	    i {
	      set a(italic) 1
	    }
	    u {
	      set a(underline) 1
	    }
	    sz {
	      if {[$node1 hasAttribute val]} {
		set a(size) [$node1 getAttribute val]
	      }
	    }
	    color {
	      if {[$node1 hasAttribute auto]} {
		set a(color) [list auto [$node1 getAttribute auto]]
	      } elseif {[$node1 hasAttribute rgb]} {
		set a(color) [list rgb [$node1 getAttribute rgb]]
	      } elseif {[$node1 hasAttribute indexed]} {
		set a(color) [list indexed [$node1 getAttribute indexed]]
	      } elseif {[$node1 hasAttribute theme]} {
		set a(color) [list theme [$node1 getAttribute theme]]
	      }
	    }
	    name {
	      if {[$node1 hasAttribute val]} {
		set a(name) [$node1 getAttribute val]
	      }
	    }
	    family {
	      if {[$node1 hasAttribute val]} {
		set a(family) [$node1 getAttribute val]
	      }
	    }
	    scheme {
	      if {[$node1 hasAttribute val]} {
		set a(scheme) [$node1 getAttribute val]
	      }
	    }
	  }
	}
	set wb(s,fonts,$idx) [array get a]
      }
      lappend wb(s,@) fonts [incr idx]


      set idx -1
      array unset a *
      foreach node [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:styleSheet/X:fills/X:fill}] {
	incr idx
	array set a {patterntype {} fgcolor {} bgcolor {}}
	foreach node1 [$node childNodes] {
	  switch -- [$node1 nodeName] {
	    patternFill {
	      if {[$node1 hasAttribute patternType]} {
		set a(patterntype) [$node1 getAttribute patternType]
	      }
	      foreach node2 [$node1 childNodes] {
		if {[$node2 nodeName] in { fgColor bgColor}} {
		  if {[$node2 hasAttribute auto]} {
		    set a([string tolower [$node2 nodeName]]) [list auto [$node2 getAttribute auto]]
		  } elseif {[$node2 hasAttribute rgb]} {
		    set a([string tolower [$node2 nodeName]]) [list rgb [$node2 getAttribute rgb]]
		  } elseif {[$node2 hasAttribute indexed]} {
		    set a([string tolower [$node2 nodeName]]) [list indexed [$node2 getAttribute indexed]]
		  } elseif {[$node2 hasAttribute theme]} {
		    set a([string tolower [$node2 nodeName]]) [list theme [$node2 getAttribute theme]]
		  }
		}
	      }
	    }
	  }
	}
	set wb(s,fills,$idx) [array get a]
      }
      lappend wb(s,@) fills [incr idx]


      set idx -1
      unset -nocomplain d
      foreach node [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:styleSheet/X:borders/X:border}] {
	incr idx
	set d {left {style {} color {}} right {style {} color {}} top {style {} color {}} bottom {style {} color {}} diagonal {style {} color {} direction {}}}
	foreach node1 [$node childNodes] {
	  if {[$node1 hasAttribute style]} {
	    set style [$node1 getAttribute style]
	  } else {
	    set style {}
	  }
	  set color {}
	  foreach node2 [$node1 childNodes] {
	    if {[$node2 nodeName] eq {color}} {
	      if {[$node2 hasAttribute auto]} {
		set color [list auto [$node2 getAttribute auto]]
	      } elseif {[$node2 hasAttribute rgb]} {
		set color [list rgb [$node2 getAttribute rgb]]
	      } elseif {[$node2 hasAttribute indexed]} {
		set color [list indexed [$node2 getAttribute indexed]]
	      } elseif {[$node2 hasAttribute theme]} {
		set color [list theme [$node2 getAttribute theme]]
	      }
	    }
	  }
	  if {[$node1 nodeName] in {left right top bottom diagonal}} {
	    if {$style ne {}} {
	      dict set d [$node1 nodeName] style $style
	    }







>








>

|

|
|
|
|

|

















>

|

|


|













>

|


|
|











|


|

|














|

|














|















|




|

|

|

|




|




|




|











|






|




|

|

|

|













|




|







|

|

|

|







972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203

  set rels 0
  if {![catch {open xlsx/xl/_rels/workbook.xml.rels r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} rdoc]} {
      set rels 1
      set relsroot [$rdoc documentElement]
      $rdoc selectNodesNamespaces [list X [$relsroot namespaceURI]]
    }
    close $fd
  }

  if {![catch {open xlsx/xl/workbook.xml r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} doc]} {
      set root [$doc documentElement]
      $doc selectNodesNamespaces [list X [$root namespaceURI]]
      set idx -1
      foreach node [$root selectNodes /X:workbook/X:sheets/X:sheet] {
	if {[$node hasAttribute sheetId] && [$node hasAttribute name]} {
	  set sheetId [$node @sheetId]
	  set name [$node @name]
	  set rid [$node @r:id]
	  foreach node [$relsroot selectNodes {/X:Relationships/X:Relationship[@Id=$rid]}] {
	    if {[$node hasAttribute Target]} {
	      lappend sheets [incr idx] $sheetId $name $rid [$node @Target]
	    }
	  }
	}
      }
      $doc delete
    }
    close $fd
  }

  if {$rels} {
    $rdoc delete
  }

  if {![catch {open xlsx/xl/sharedStrings.xml r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} doc]} {
      set root [$doc documentElement]
      $doc selectNodesNamespaces [list X [$root namespaceURI]]
      set idx -1
      foreach shared [$root selectNodes /X:sst/X:si] {
	incr idx
	foreach node [$shared selectNodes X:t/text()] {
	  append sharedStrings($idx) [$node nodeValue]
	}
	foreach node [$shared selectNodes */X:t/text()] {
	  append sharedStrings($idx) [$node nodeValue]
	}
      }
      $doc delete
    }
    close $fd
  }


  if {![catch {open xlsx/xl/styles.xml r} fd]} {
    fconfigure $fd -encoding utf-8
    if {![catch {dom parse [read $fd]} doc]} {
      set root [$doc documentElement]
      $doc selectNodesNamespaces [list X [$root namespaceURI]]
      set idx -1
      foreach node [$root selectNodes /X:styleSheet/X:numFmts/X:numFmt] {
        incr idx
	if {[$node hasAttribute numFmtId] && [$node hasAttribute formatCode]} {
	  set numFmtId [$node @numFmtId]
	  set formatCode [$node @formatCode]
	  set datetime 0
	  foreach tag {*y* *m* *d* *h* *s*} {
	    if {[string match -nocase $tag [string map {Black {} Blue {} Cyan {} Green {} Magenta {} Red {} White {} Yellow {}} $formatCode]]} {
	      set datetime 1
	      break
	    }
	  }
	  set numFmts($numFmtId) [list dt $datetime fmt $formatCode]
	}
      }
      set idx -1
      foreach node [$root selectNodes /X:styleSheet/X:cellXfs/X:xf] {
        incr idx
	if {[$node hasAttribute numFmtId]} {
	  set numFmtId [$node @numFmtId]
	  if {[$node hasAttribute applyNumberFormat]} {
	    set applyNumberFormat [$node @applyNumberFormat]
	  } else {
	    set applyNumberFormat 0
	  }
	  set cellXfs($idx) [list nfi $numFmtId anf $applyNumberFormat]
	}
      }

      ### READING KNOWN FORMATS AND STYLES ###

      set wb(s,@) {}

      array unset a *
      set a(max) 0
      set wb(s,numFmtsIds) {}
      foreach node [$root selectNodes /X:styleSheet/X:numFmts/X:numFmt] {
        if {[$node hasAttribute numFmtId] && [$node hasAttribute formatCode]} {
	  set wb(s,numFmts,[set idx [$node @numFmtId]]) [$node @formatCode]
	  lappend wb(s,numFmtsIds) $idx
	  if {$idx > $a(max)} {
	    set a(max) $idx
	  }
	}
      }
      if {$a(max) < $::ooxml::defaults(numFmts,start)} {
        set a(max) $::ooxml::defaults(numFmts,start)
      }
      lappend wb(s,@) numFmtId [incr a(max)]


      set idx -1
      array unset a *
      foreach node [$root selectNodes /X:styleSheet/X:fonts/X:font] {
	incr idx
	array set a {name {} family {} size {} color {} scheme {} bold 0 italic 0 underline 0 color {}}
	foreach node1 [$node childNodes] {
	  switch -- [$node1 nodeName] {
	    b {
	      set a(bold) 1
	    }
	    i {
	      set a(italic) 1
	    }
	    u {
	      set a(underline) 1
	    }
	    sz {
	      if {[$node1 hasAttribute val]} {
		set a(size) [$node1 @val]
	      }
	    }
	    color {
	      if {[$node1 hasAttribute auto]} {
		set a(color) [list auto [$node1 @auto]]
	      } elseif {[$node1 hasAttribute rgb]} {
		set a(color) [list rgb [$node1 @rgb]]
	      } elseif {[$node1 hasAttribute indexed]} {
		set a(color) [list indexed [$node1 @indexed]]
	      } elseif {[$node1 hasAttribute theme]} {
		set a(color) [list theme [$node1 @theme]]
	      }
	    }
	    name {
	      if {[$node1 hasAttribute val]} {
		set a(name) [$node1 @val]
	      }
	    }
	    family {
	      if {[$node1 hasAttribute val]} {
		set a(family) [$node1 @val]
	      }
	    }
	    scheme {
	      if {[$node1 hasAttribute val]} {
		set a(scheme) [$node1 @val]
	      }
	    }
	  }
	}
	set wb(s,fonts,$idx) [array get a]
      }
      lappend wb(s,@) fonts [incr idx]


      set idx -1
      array unset a *
      foreach node [$root selectNodes /X:styleSheet/X:fills/X:fill] {
	incr idx
	array set a {patterntype {} fgcolor {} bgcolor {}}
	foreach node1 [$node childNodes] {
	  switch -- [$node1 nodeName] {
	    patternFill {
	      if {[$node1 hasAttribute patternType]} {
		set a(patterntype) [$node1 @patternType]
	      }
	      foreach node2 [$node1 childNodes] {
		if {[$node2 nodeName] in { fgColor bgColor}} {
		  if {[$node2 hasAttribute auto]} {
		    set a([string tolower [$node2 nodeName]]) [list auto [$node2 @auto]]
		  } elseif {[$node2 hasAttribute rgb]} {
		    set a([string tolower [$node2 nodeName]]) [list rgb [$node2 @rgb]]
		  } elseif {[$node2 hasAttribute indexed]} {
		    set a([string tolower [$node2 nodeName]]) [list indexed [$node2 @indexed]]
		  } elseif {[$node2 hasAttribute theme]} {
		    set a([string tolower [$node2 nodeName]]) [list theme [$node2 @theme]]
		  }
		}
	      }
	    }
	  }
	}
	set wb(s,fills,$idx) [array get a]
      }
      lappend wb(s,@) fills [incr idx]


      set idx -1
      unset -nocomplain d
      foreach node [$root selectNodes /X:styleSheet/X:borders/X:border] {
	incr idx
	set d {left {style {} color {}} right {style {} color {}} top {style {} color {}} bottom {style {} color {}} diagonal {style {} color {} direction {}}}
	foreach node1 [$node childNodes] {
	  if {[$node1 hasAttribute style]} {
	    set style [$node1 @style]
	  } else {
	    set style {}
	  }
	  set color {}
	  foreach node2 [$node1 childNodes] {
	    if {[$node2 nodeName] eq {color}} {
	      if {[$node2 hasAttribute auto]} {
		set color [list auto [$node2 @auto]]
	      } elseif {[$node2 hasAttribute rgb]} {
		set color [list rgb [$node2 @rgb]]
	      } elseif {[$node2 hasAttribute indexed]} {
		set color [list indexed [$node2 @indexed]]
	      } elseif {[$node2 hasAttribute theme]} {
		set color [list theme [$node2 @theme]]
	      }
	    }
	  }
	  if {[$node1 nodeName] in {left right top bottom diagonal}} {
	    if {$style ne {}} {
	      dict set d [$node1 nodeName] style $style
	    }
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
	set wb(s,borders,$idx) $d
      }
      lappend wb(s,@) borders [incr idx]


      set idx -1
      array unset a *
      foreach node [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:styleSheet/X:cellXfs/X:xf}] {
	incr idx
	array set a {numfmt 0 font 0 fill 0 border 0 xf 0 horizontal {} vertical {} rotate {} wrap {}}
        if {[$node hasAttribute numFmtId]} {
	  set a(numfmt) [$node getAttribute numFmtId]
	}
        if {[$node hasAttribute fontId]} {
	  set a(font) [$node getAttribute fontId]
	}
        if {[$node hasAttribute fillId]} {
	  set a(fill) [$node getAttribute fillId]
	}
        if {[$node hasAttribute borderId]} {
	  set a(border) [$node getAttribute borderId]
	}
        if {[$node hasAttribute xfId]} {
	  set a(xf) [$node getAttribute xfId]
	}
	foreach node1 [$node childNodes] {
	  switch -- [$node1 nodeName] {
	    alignment {
	      if {[$node1 hasAttribute horizontal]} {
		set a(horizontal) [$node1 getAttribute horizontal]
	      }
	      if {[$node1 hasAttribute vertical]} {
		set a(vertical) [$node1 getAttribute vertical]
	      }
	      if {[$node1 hasAttribute textRotation]} {
		set a(rotate) [$node1 getAttribute textRotation]
	      }
	      if {[$node1 hasAttribute wrapText]} {
		set a(wrap) [$node1 getAttribute wrapText]
	      }
	    }
	  }
	}
	set wb(s,styles,$idx) [array get a]
      }
      lappend wb(s,@) styles [incr idx]







|



|


|


|


|


|





|


|


|


|







1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
	set wb(s,borders,$idx) $d
      }
      lappend wb(s,@) borders [incr idx]


      set idx -1
      array unset a *
      foreach node [$root selectNodes /X:styleSheet/X:cellXfs/X:xf] {
	incr idx
	array set a {numfmt 0 font 0 fill 0 border 0 xf 0 horizontal {} vertical {} rotate {} wrap {}}
        if {[$node hasAttribute numFmtId]} {
	  set a(numfmt) [$node @numFmtId]
	}
        if {[$node hasAttribute fontId]} {
	  set a(font) [$node @fontId]
	}
        if {[$node hasAttribute fillId]} {
	  set a(fill) [$node @fillId]
	}
        if {[$node hasAttribute borderId]} {
	  set a(border) [$node @borderId]
	}
        if {[$node hasAttribute xfId]} {
	  set a(xf) [$node @xfId]
	}
	foreach node1 [$node childNodes] {
	  switch -- [$node1 nodeName] {
	    alignment {
	      if {[$node1 hasAttribute horizontal]} {
		set a(horizontal) [$node1 @horizontal]
	      }
	      if {[$node1 hasAttribute vertical]} {
		set a(vertical) [$node1 @vertical]
	      }
	      if {[$node1 hasAttribute textRotation]} {
		set a(rotate) [$node1 @textRotation]
	      }
	      if {[$node1 hasAttribute wrapText]} {
		set a(wrap) [$node1 @wrapText]
	      }
	    }
	  }
	}
	set wb(s,styles,$idx) [array get a]
      }
      lappend wb(s,@) styles [incr idx]
1287
1288
1289
1290
1291
1292
1293

1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
    set wb($sheet,max_row) -1
    set wb($sheet,max_column) -1

    if {![catch {open [file join xlsx/xl $target] r} fd]} {
      fconfigure $fd -encoding utf-8
      if {![catch {dom parse [read $fd]} doc]} {
	set root [$doc documentElement]

	set idx -1
	foreach col [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:worksheet/X:cols/X:col}] {
	  incr idx
	  foreach item {min max width style bestFit customWidth} {
	    if {[$col hasAttribute $item]} {
	      switch -- $item {
	        min - max {
		  lappend wb($sheet,col,$idx) [string tolower $item] [expr {[$col getAttribute $item] - 1}]
		}
		default {
		  lappend wb($sheet,col,$idx) [string tolower $item] [$col getAttribute $item]
		}
	      }
	    } else {
	      lappend wb($sheet,col,$idx) [string tolower $item] 0
	    }
	  }
	  lappend wb($sheet,col,$idx) string 0 nozero 0 calcfit 0
	}
	set wb($sheet,cols) [incr idx]
	foreach cell [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:worksheet/X:sheetData/X:row/X:c}] {
	  if {[$cell hasAttribute t]} {
	    set type [$cell getAttribute t]
	  } else {
	    set type n
	  }
	  set value {}
	  set datetime {}
	  switch -- $type {
	    n - b - d - str {
	      # number (default), boolean, iso-date, formula string
	      if {[set node [$cell selectNodes -namespaces [list X [$cell namespaceURI]] X:v/text()]] ne {}} {
		set value [$node nodeValue]
		if {$type eq {n} && [$cell hasAttribute s] && [string is double -strict $value]} {
		  set idx [$cell getAttribute s]
		  if {[dict exists $cellXfs($idx) nfi]} {
		    set numFmtId [dict get $cellXfs($idx) nfi]
		    if {[info exists numFmts($numFmtId)] && [dict exists $numFmts($numFmtId) dt] && [dict get $numFmts($numFmtId) dt]} {
		      set datetime $value
		      catch {clock format [expr {int(($value - 25569) * 86400.0)}] -format $opts(datefmt) -gmt 1} value
		    }
		  }
		} 
	      } else {
		if {![$cell hasAttribute s]} continue
	      }
	    }
	    s {
	      # shared string
	      if {[set node [$cell selectNodes -namespaces [list X [$cell namespaceURI]] X:v/text()]] ne {}} {
		set index [$node nodeValue]
		if {[info exists sharedStrings($index)]} {
		  set value $sharedStrings($index)
		}
	      } else {
		if {![$cell hasAttribute s]} continue
	      }
	    }
	    inlineStr {
	      # inline string
	      if {[set string [$cell selectNodes -namespaces [list X [$cell namespaceURI]] X:is]] ne {}} {
		foreach node [$string selectNodes -namespaces [list X [$string namespaceURI]] {X:t/text()}] {
		  append value [$node nodeValue]
		}
		foreach node [$string selectNodes -namespaces [list X [$string namespaceURI]] {*/X:t/text()}] {
		  append value [$node nodeValue]
		}
	      } else {
		if {![$cell hasAttribute s]} continue
	      }
	    }
	    e {
	      # error
	    }
	  }

	  if {[$cell hasAttribute r]} {
	    if {!$opts(valuesonly)} {
	      set wb($sheet,c,[StringToRowColumn [$cell getAttribute r]]) [$cell getAttribute r]
	    }
	    if {!$opts(valuesonly)} {
	      if {[$cell hasAttribute s]} {
		set wb($sheet,s,[StringToRowColumn [$cell getAttribute r]]) [$cell getAttribute s]
	      }
	    }
	    if {!$opts(valuesonly)} {
	      if {[$cell hasAttribute t]} {
		set wb($sheet,t,[StringToRowColumn [$cell getAttribute r]]) [$cell getAttribute t]
	      }
	    }
	    set wb($sheet,v,[StringToRowColumn [$cell getAttribute r]]) $value
	    if {!$opts(valuesonly) && $datetime ne {}} {
	      set wb($sheet,d,[StringToRowColumn [$cell getAttribute r]]) $datetime
	    }
	    if {!$opts(valuesonly) && [set node [$cell selectNodes -namespaces [list X [$cell namespaceURI]] X:f/text()]] ne {}} {
	      set wb($sheet,f,[StringToRowColumn [$cell getAttribute r]]) [$node nodeValue]
	    }
	  }
	}
	if {!$opts(valuesonly)} {
	  foreach row [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:worksheet/X:sheetData/X:row}] {
	    if {[$row hasAttribute r] && [$row hasAttribute ht] && [$row hasAttribute customHeight] && [$row getAttribute customHeight] == 1} {
	      dict set wb($sheet,rowheight) [expr {[$row getAttribute r] - 1}] [$row getAttribute ht]
	    }
	  }
	}
	if {!$opts(valuesonly)} {
	  foreach freeze [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:worksheet/X:sheetViews/X:sheetView/X:pane}] {
	    if {[$freeze hasAttribute topLeftCell] && [$freeze hasAttribute state] && [$freeze getAttribute state] eq {frozen}} {
	      set wb($sheet,freeze) [$freeze getAttribute topLeftCell]
	    }
	  }
	}
	if {!$opts(valuesonly)} {
	  foreach filter [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:worksheet/X:autoFilter}] {
	    if {[$filter hasAttribute ref]} {
	      lappend wb($sheet,filter) [$filter getAttribute ref]
	    }
	  }
	}
	if {!$opts(valuesonly)} {
	  foreach merge [$root selectNodes -namespaces [list X [$root namespaceURI]] {/X:worksheet/X:mergeCells/X:mergeCell}] {
	    if {[$merge hasAttribute ref]} {
	      lappend wb($sheet,merge) [$merge getAttribute ref]
	    }
	  }
	}
	$doc delete
      }
      close $fd
    }







>

|





|


|









|

|








|


|














|










|
|


|













|



|




|


|

|

|
|




|
|
|




|
|
|




|

|




|

|







1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
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
1431
    set wb($sheet,max_row) -1
    set wb($sheet,max_column) -1

    if {![catch {open [file join xlsx/xl $target] r} fd]} {
      fconfigure $fd -encoding utf-8
      if {![catch {dom parse [read $fd]} doc]} {
	set root [$doc documentElement]
        $doc selectNodesNamespaces [list X [$root namespaceURI]]
	set idx -1
	foreach col [$root selectNodes /X:worksheet/X:cols/X:col] {
	  incr idx
	  foreach item {min max width style bestFit customWidth} {
	    if {[$col hasAttribute $item]} {
	      switch -- $item {
	        min - max {
		  lappend wb($sheet,col,$idx) [string tolower $item] [expr {[$col @$item] - 1}]
		}
		default {
		  lappend wb($sheet,col,$idx) [string tolower $item] [$col @$item]
		}
	      }
	    } else {
	      lappend wb($sheet,col,$idx) [string tolower $item] 0
	    }
	  }
	  lappend wb($sheet,col,$idx) string 0 nozero 0 calcfit 0
	}
	set wb($sheet,cols) [incr idx]
	foreach cell [$root selectNodes /X:worksheet/X:sheetData/X:row/X:c] {
	  if {[$cell hasAttribute t]} {
	    set type [$cell @t]
	  } else {
	    set type n
	  }
	  set value {}
	  set datetime {}
	  switch -- $type {
	    n - b - d - str {
	      # number (default), boolean, iso-date, formula string
	      if {[set node [$cell selectNodes X:v/text()]] ne {}} {
		set value [$node nodeValue]
		if {$type eq {n} && [$cell hasAttribute s] && [string is double -strict $value]} {
		  set idx [$cell @s]
		  if {[dict exists $cellXfs($idx) nfi]} {
		    set numFmtId [dict get $cellXfs($idx) nfi]
		    if {[info exists numFmts($numFmtId)] && [dict exists $numFmts($numFmtId) dt] && [dict get $numFmts($numFmtId) dt]} {
		      set datetime $value
		      catch {clock format [expr {int(($value - 25569) * 86400.0)}] -format $opts(datefmt) -gmt 1} value
		    }
		  }
		} 
	      } else {
		if {![$cell hasAttribute s]} continue
	      }
	    }
	    s {
	      # shared string
	      if {[set node [$cell selectNodes X:v/text()]] ne {}} {
		set index [$node nodeValue]
		if {[info exists sharedStrings($index)]} {
		  set value $sharedStrings($index)
		}
	      } else {
		if {![$cell hasAttribute s]} continue
	      }
	    }
	    inlineStr {
	      # inline string
	      if {[set string [$cell selectNodes X:is]] ne {}} {
		foreach node [$string selectNodes X:t/text()] {
		  append value [$node nodeValue]
		}
		foreach node [$string selectNodes */X:t/text()] {
		  append value [$node nodeValue]
		}
	      } else {
		if {![$cell hasAttribute s]} continue
	      }
	    }
	    e {
	      # error
	    }
	  }

	  if {[$cell hasAttribute r]} {
	    if {!$opts(valuesonly)} {
	      set wb($sheet,c,[StringToRowColumn [$cell @r]]) [$cell @r]
	    }
	    if {!$opts(valuesonly)} {
	      if {[$cell hasAttribute s]} {
		set wb($sheet,s,[StringToRowColumn [$cell @r]]) [$cell @s]
	      }
	    }
	    if {!$opts(valuesonly)} {
	      if {[$cell hasAttribute t]} {
		set wb($sheet,t,[StringToRowColumn [$cell @r]]) [$cell @t]
	      }
	    }
	    set wb($sheet,v,[StringToRowColumn [$cell @r]]) $value
	    if {!$opts(valuesonly) && $datetime ne {}} {
	      set wb($sheet,d,[StringToRowColumn [$cell @r]]) $datetime
	    }
	    if {!$opts(valuesonly) && [set node [$cell selectNodes X:f/text()]] ne {}} {
	      set wb($sheet,f,[StringToRowColumn [$cell @r]]) [$node nodeValue]
	    }
	  }
	}
	if {!$opts(valuesonly)} {
	  foreach row [$root selectNodes /X:worksheet/X:sheetData/X:row] {
	    if {[$row hasAttribute r] && [$row hasAttribute ht] && [$row hasAttribute customHeight] && [$row @customHeight] == 1} {
	      dict set wb($sheet,rowheight) [expr {[$row @r] - 1}] [$row @ht]
	    }
	  }
	}
	if {!$opts(valuesonly)} {
	  foreach freeze [$root selectNodes /X:worksheet/X:sheetViews/X:sheetView/X:pane] {
	    if {[$freeze hasAttribute topLeftCell] && [$freeze hasAttribute state] && [$freeze @state] eq {frozen}} {
	      set wb($sheet,freeze) [$freeze @topLeftCell]
	    }
	  }
	}
	if {!$opts(valuesonly)} {
	  foreach filter [$root selectNodes /X:worksheet/X:autoFilter] {
	    if {[$filter hasAttribute ref]} {
	      lappend wb($sheet,filter) [$filter @ref]
	    }
	  }
	}
	if {!$opts(valuesonly)} {
	  foreach merge [$root selectNodes /X:worksheet/X:mergeCells/X:mergeCell] {
	    if {[$merge hasAttribute ref]} {
	      lappend wb($sheet,merge) [$merge @ref]
	    }
	  }
	}
	$doc delete
      }
      close $fd
    }
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
	      Tag_mergeCell ref $item {}
	    }
	  }
	}
	Tag_pageMargins left 0.75 right 0.75 top 1 bottom 1 header 0.5 footer 0.5 {}
      }

      if {[set colsNode [$root selectNodes {/worksheet/cols}]] ne {}} {
	if {[info exists obj($ws,cols)] && $obj($ws,cols) > 0} {
	  $colsNode appendFromScript {
	    foreach idx [lsort -dictionary [array names cols $ws,*]] {
	      set attr {}
	      lappend attr min [expr {[dict get $cols($idx) min] + 1}] max [expr {[dict get $cols($idx) max] + 1}]
	      if {[dict get $cols($idx) width] ne {}} {
		lappend attr width [dict get $cols($idx) width]







|







3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
	      Tag_mergeCell ref $item {}
	    }
	  }
	}
	Tag_pageMargins left 0.75 right 0.75 top 1 bottom 1 header 0.5 footer 0.5 {}
      }

      if {[set colsNode [$root selectNodes /worksheet/cols]] ne {}} {
	if {[info exists obj($ws,cols)] && $obj($ws,cols) > 0} {
	  $colsNode appendFromScript {
	    foreach idx [lsort -dictionary [array names cols $ws,*]] {
	      set attr {}
	      lappend attr min [expr {[dict get $cols($idx) min] + 1}] max [expr {[dict get $cols($idx) max] + 1}]
	      if {[dict get $cols($idx) width] ne {}} {
		lappend attr width [dict get $cols($idx) width]
3200
3201
3202
3203
3204
3205
3206




        $spreadsheet column $sheet -index $column -style $left
      }
    }
  }
}

package provide ooxml 1.2











>
>
>
>
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
        $spreadsheet column $sheet -index $column -style $left
      }
    }
  }
}

package provide ooxml 1.2

# Local Variables:
# tcl-indent-level: 2
# End: