ooxml

Check-in [801207f631]
Login

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

Overview
Comment:merged from xquery
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 801207f6318101227630758189743de9db38a3d5f01b33327111c3c68d090658
User & Date: alex 2019-11-10 21:26:28
Context
2019-11-16
10:37
merged from namespaces check-in: 6931dd69d4 user: alex tags: trunk
2019-11-13
16:54
all xmlns into an array check-in: e740ca7fe6 user: alex tags: namespaces
2019-11-10
21:26
merged from xquery check-in: 801207f631 user: alex tags: trunk
2019-11-08
13:08
revise xQuery xl_read Closed-Leaf check-in: b460a8bb8b user: alex tags: xquery
2019-11-05
21:58
merged from tcltest check-in: d7bececf50 user: alex tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ooxml.tcl.

772
773
774
775
776
777
778
779


780
781
782
783
784
785
786
787
788



789
790
791
792
793
794
795
796
797
798
799
800
801
802
...
865
866
867
868
869
870
871
872


873
874
875
876
877
878
879
880
881



882
883
884
885
886
887
888
889
890
891
892
893
894
895
...
901
902
903
904
905
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
937
938
...
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
...
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
...
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
....
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
....
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
....
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
....
1186
1187
1188
1189
1190
1191
1192
1193





1194
1195
1196
1197
1198
1199
1200
1201
1202
....
1207
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
....
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
....
1281
1282
1283
1284
1285
1286
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

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

  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
................................................................................
    $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]]} {
................................................................................
	      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
................................................................................
      ### 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
	  }
	}
................................................................................
        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
	    }
................................................................................
	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]
................................................................................
	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 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]
................................................................................
    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}]
		}
................................................................................
	    } 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
................................................................................
		} 
	      } 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 {
................................................................................
		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
      }







|
>
>








|
>
>
>

|




|







 







|
>
>








|
>
>
>

|




|







 







|
>
>

|

|


|













|
>
>
>
>
>

|







 







|







 







|







 







|







 







|







 







|







 







|







 







|
>
>
>
>
>

|







 







|










|







 







|










|
|


|







 







|





|






|






|






|







772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
...
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
...
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
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
...
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
...
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
...
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
....
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
....
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
....
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
....
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
....
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
....
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
....
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

  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 {
        G http://schemas.openxmlformats.org/package/2006/relationships
      }
    }
    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 {
	G http://schemas.openxmlformats.org/spreadsheetml/2006/main
	r http://schemas.openxmlformats.org/officeDocument/2006/relationships
      }
      set idx -1
      foreach node [$root selectNodes /G:workbook/G:sheets/G: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 {/G:Relationships/G:Relationship[@Id=$rid]}] {
	    if {[$node hasAttribute Target]} {
	      lappend sheets [incr idx] [list sheetId $sheetId name $name rId $rid]
	    }
	  }
	}
      }
      $doc delete
................................................................................

  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 {
        G http://schemas.openxmlformats.org/package/2006/relationships
      }
    }
    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 {
        G http://schemas.openxmlformats.org/spreadsheetml/2006/main
        r http://schemas.openxmlformats.org/officeDocument/2006/relationships
      }
      set idx -1
      foreach node [$root selectNodes /G:workbook/G:sheets/G: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 {/G:Relationships/G:Relationship[@Id=$rid]}] {
	    if {[$node hasAttribute Target]} {
	      lappend sheets [incr idx] $sheetId $name $rid [$node @Target]
	    }
	  }
	}
      }
      $doc delete
................................................................................
    $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 {
        G http://schemas.openxmlformats.org/spreadsheetml/2006/main
      }
      set idx -1
      foreach shared [$root selectNodes /G:sst/G:si] {
	incr idx
	foreach node [$shared selectNodes G:t/text()] {
	  append sharedStrings($idx) [$node nodeValue]
	}
	foreach node [$shared selectNodes */G: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 {
        G http://schemas.openxmlformats.org/spreadsheetml/2006/main
	mc http://schemas.openxmlformats.org/markup-compatibility/2006
	x14ac http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac
	x16r2 http://schemas.microsoft.com/office/spreadsheetml/2015/02/main
      }
      set idx -1
      foreach node [$root selectNodes /G:styleSheet/G:numFmts/G: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]]} {
................................................................................
	      break
	    }
	  }
	  set numFmts($numFmtId) [list dt $datetime fmt $formatCode]
	}
      }
      set idx -1
      foreach node [$root selectNodes /G:styleSheet/G:cellXfs/G:xf] {
        incr idx
	if {[$node hasAttribute numFmtId]} {
	  set numFmtId [$node @numFmtId]
	  if {[$node hasAttribute applyNumberFormat]} {
	    set applyNumberFormat [$node @applyNumberFormat]
	  } else {
	    set applyNumberFormat 0
................................................................................
      ### READING KNOWN FORMATS AND STYLES ###

      set wb(s,@) {}

      array unset a *
      set a(max) 0
      set wb(s,numFmtsIds) {}
      foreach node [$root selectNodes /G:styleSheet/G:numFmts/G: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
	  }
	}
................................................................................
        set a(max) $::ooxml::defaults(numFmts,start)
      }
      lappend wb(s,@) numFmtId [incr a(max)]


      set idx -1
      array unset a *
      foreach node [$root selectNodes /G:styleSheet/G:fonts/G: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
	    }
................................................................................
	set wb(s,fonts,$idx) [array get a]
      }
      lappend wb(s,@) fonts [incr idx]


      set idx -1
      array unset a *
      foreach node [$root selectNodes /G:styleSheet/G:fills/G: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]
................................................................................
	set wb(s,fills,$idx) [array get a]
      }
      lappend wb(s,@) fills [incr idx]


      set idx -1
      unset -nocomplain d
      foreach node [$root selectNodes /G:styleSheet/G:borders/G: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 wb(s,borders,$idx) $d
      }
      lappend wb(s,@) borders [incr idx]


      set idx -1
      array unset a *
      foreach node [$root selectNodes /G:styleSheet/G:cellXfs/G: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]
................................................................................
    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 {
	  G http://schemas.openxmlformats.org/spreadsheetml/2006/main
	  r http://schemas.openxmlformats.org/officeDocument/2006/relationships
	  mc http://schemas.openxmlformats.org/markup-compatibility/2006
	  x14ac http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac
	}
	set idx -1
	foreach col [$root selectNodes /G:worksheet/G:cols/G: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}]
		}
................................................................................
	    } 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 /G:worksheet/G:sheetData/G:row/G: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 G: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
................................................................................
		} 
	      } else {
		if {![$cell hasAttribute s]} continue
	      }
	    }
	    s {
	      # shared string
	      if {[set node [$cell selectNodes G: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 G:is]] ne {}} {
		foreach node [$string selectNodes G:t/text()] {
		  append value [$node nodeValue]
		}
		foreach node [$string selectNodes */G:t/text()] {
		  append value [$node nodeValue]
		}
	      } else {
		if {![$cell hasAttribute s]} continue
	      }
	    }
	    e {
................................................................................
		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 G:f/text()]] ne {}} {
	      set wb($sheet,f,[StringToRowColumn [$cell @r]]) [$node nodeValue]
	    }
	  }
	}
	if {!$opts(valuesonly)} {
	  foreach row [$root selectNodes /G:worksheet/G:sheetData/G: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 /G:worksheet/G:sheetViews/G:sheetView/G: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 /G:worksheet/G:autoFilter] {
	    if {[$filter hasAttribute ref]} {
	      lappend wb($sheet,filter) [$filter @ref]
	    }
	  }
	}
	if {!$opts(valuesonly)} {
	  foreach merge [$root selectNodes /G:worksheet/G:mergeCells/G:mergeCell] {
	    if {[$merge hasAttribute ref]} {
	      lappend wb($sheet,merge) [$merge @ref]
	    }
	  }
	}
	$doc delete
      }