ooxml

Check-in [fd20448a1d]
Login

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

Overview
Comment:merged idomidioms
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fd20448a1d86718794dceb4f45dd06fae0e85aa4bf999812277a38835e90b4a8
User & Date: alex 2019-08-07 19:30:39
Context
2019-08-08
13:32
merged idomidioms check-in: 07a138a2f1 user: alex tags: trunk
2019-08-07
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
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ooxml.tcl.

917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
...
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
....
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
....
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
....
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
....
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
....
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
....
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
....
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
....
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
....
3200
3201
3202
3203
3204
3205
3206




  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]
	    }
	  }
	}
      }
................................................................................
  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
................................................................................
    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]
	}
      }

................................................................................
      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(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]
................................................................................
      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]
................................................................................
      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
	    }
................................................................................

      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]
................................................................................
	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
		    }
		  }
................................................................................
	    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
    }
................................................................................
        $spreadsheet column $sheet -index $column -style $left
      }
    }
  }
}

package provide ooxml 1.2











|
|
|







 







|
|
|


|







 







|
|







 







|

|







 







|







 







|




|

|

|

|




|




|




|







 







|




|

|

|

|







 







|







|

|

|

|







 







|


|


|


|


|





|


|


|


|







 







|


|











|











|







 







|



|




|


|

|


|





|
|





|
|






|






|







 







>
>
>
>
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
...
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
....
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
....
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
....
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
....
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
....
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
....
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
....
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
....
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
....
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
  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 @sheetId]
	  set name [$node @name]
	  set rid [$node @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]
	    }
	  }
	}
      }
................................................................................
  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 @sheetId]
	  set name [$node @name]
	  set rid [$node @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 @Target]
	    }
	  }
	}
      }
      $doc delete
    }
    close $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 @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 -namespaces [list X [$root namespaceURI]] {/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]
	}
      }

................................................................................
      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 @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(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]
................................................................................
      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 @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]
................................................................................
      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 @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
	    }
................................................................................

      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 @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]
................................................................................
	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 @$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 -namespaces [list X [$root namespaceURI]] {/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 -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 @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
		    }
		  }
................................................................................
	    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 -namespaces [list X [$cell namespaceURI]] X:f/text()]] ne {}} {
	      set wb($sheet,f,[StringToRowColumn [$cell @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 @customHeight] == 1} {
	      dict set wb($sheet,rowheight) [expr {[$row @r] - 1}] [$row @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 @state] eq {frozen}} {
	      set wb($sheet,freeze) [$freeze @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 @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 @ref]
	    }
	  }
	}
	$doc delete
      }
      close $fd
    }
................................................................................
        $spreadsheet column $sheet -index $column -style $left
      }
    }
  }
}

package provide ooxml 1.2

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