ooxml

Check-in [a789d06e7e]
Login

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

Overview
Comment:merged from tcltest
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a789d06e7ed04a6031ee9b5a5084a0dfc3599b83f817ab602c0dbe85e7639347
User & Date: alex 2019-11-28 14:25:09
Context
2019-11-28
14:30
Version-1.4 check-in: 2c30d300df user: alex tags: trunk, release, version-1.4
14:25
merged from tcltest check-in: a789d06e7e user: alex tags: trunk
14:21
enable benchmark Closed-Leaf check-in: 8fa48338f7 user: alex tags: tcltest
2019-11-27
14:58
xl_read section columns changed array index ws,col,idx check-in: b72ce0e7de user: alex tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ooxml.tcl.

1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
....
1236
1237
1238
1239
1240
1241
1242







1243
1244
1245
1246
1247
1248
1249
....
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
....
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
....
2438
2439
2440
2441
2442
2443
2444
2445

2446
2447
2448
2449
2450
2451
2452
	    }
	    if {$color ne {}} {
	      dict set d [$node1 nodeName] color $color
	    }
	  }
	}
	if {[$node hasAttribute diagonalUp]} {
	  dict set d diagonal direction up
	} elseif {[$node hasAttribute diagonalDown]} {
	  dict set d diagonal direction down
	}
	set wb(s,borders,$idx) $d
      }
      lappend wb(s,@) borders [incr idx]


      set idx -1
................................................................................
	  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 M:v/text()]] ne {}} {
		set value [$node nodeValue]
		if {$type eq {n} && [$cell hasAttribute s] && [string is double -strict $value]} {
		  set idx [$cell @s]
................................................................................
		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 M:f/text()]] ne {}} {
	      set wb($sheet,f,[StringToRowColumn [$cell @r]]) [$node nodeValue]
	    }
	  }
	}
	if {!$opts(valuesonly)} {
	  foreach row [$root selectNodes /M:worksheet/M:sheetData/M: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]
	    }
	  }
	}
................................................................................
    my variable obj
    my variable cols

    array set opts {
      index {}
      to {}
      width {}
      style {}
      bestfit 0
      customwidth 0
      string 0
      nozero 0
      calcfit 0
    }

................................................................................
	  }
	  set obj($item) [dict get $a(s,@) $item]
	}
      }
    }

    foreach sheet $a(sheets) {
      for {set idx 0} {$idx < $a($sheet,cols)} {incr idx} {

	if {[info exists a($sheet,col,$idx)]} {
	  set cols([expr {$sheet + 1}],$idx) $a($sheet,col,$idx)
	}
      }
      set obj([expr {$sheet + 1}],cols) [llength [array names cols]]
    }








|

|







 







>
>
>
>
>
>
>







 







<
<
|
|
|







 







|







 







|
>







1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
....
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
....
1309
1310
1311
1312
1313
1314
1315


1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
....
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
....
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
	    }
	    if {$color ne {}} {
	      dict set d [$node1 nodeName] color $color
	    }
	  }
	}
	if {[$node hasAttribute diagonalUp]} {
	  dict set d diagonal direction diagonalUp
	} elseif {[$node hasAttribute diagonalDown]} {
	  dict set d diagonal direction diagonalDown
	}
	set wb(s,borders,$idx) $d
      }
      lappend wb(s,@) borders [incr idx]


      set idx -1
................................................................................
	  if {[$cell hasAttribute t]} {
	    set type [$cell @t]
	  } else {
	    set type n
	  }
	  set value {}
	  set datetime {}

	  if {[$cell hasAttribute r]} {
	    if {!$opts(valuesonly) && [set node [$cell selectNodes M:f/text()]] ne {}} {
	      set wb($sheet,f,[StringToRowColumn [$cell @r]]) [$node nodeValue]
	    }
	  }

	  switch -- $type {
	    n - b - d - str {
	      # number (default), boolean, iso-date, formula string
	      if {[set node [$cell selectNodes M:v/text()]] ne {}} {
		set value [$node nodeValue]
		if {$type eq {n} && [$cell hasAttribute s] && [string is double -strict $value]} {
		  set idx [$cell @s]
................................................................................
		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)} {
	  foreach row [$root selectNodes /M:worksheet/M:sheetData/M: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]
	    }
	  }
	}
................................................................................
    my variable obj
    my variable cols

    array set opts {
      index {}
      to {}
      width {}
      style 0
      bestfit 0
      customwidth 0
      string 0
      nozero 0
      calcfit 0
    }

................................................................................
	  }
	  set obj($item) [dict get $a(s,@) $item]
	}
      }
    }

    foreach sheet $a(sheets) {
      foreach item [array names a $sheet,col,*] {
	set idx [lindex [split $item ,] end]
	if {[info exists a($sheet,col,$idx)]} {
	  set cols([expr {$sheet + 1}],$idx) $a($sheet,col,$idx)
	}
      }
      set obj([expr {$sheet + 1}],cols) [llength [array names cols]]
    }

Changes to tests/benchmark.test.

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
      puts $list
      set rc 0
    }
  }

  return $rc
} 1


file delete -force 500-10.xlsx 1000-10.xlsx 3000-10.xlsx 5000-10.xlsx


# cleanup
::tcltest::cleanupTests
return








<








54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
      puts $list
      set rc 0
    }
  }

  return $rc
} 1


file delete -force 500-10.xlsx 1000-10.xlsx 3000-10.xlsx 5000-10.xlsx


# cleanup
::tcltest::cleanupTests
return

Changes to tests/formatcell.test.

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
...
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860


861







































































































































































862
863
864
865
866
867
868
  package require tcltest 2
  namespace import -force ::tcltest::*
  loadTestedCommands
}


package require ooxml
package require vfs::zip


test FormatCellNewSpreatsheet-1.1 {Create New Spreadsheet} -body {
  set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
} -result {::oo::Obj*} -match glob

test FormatCellNewWorksheet-1.2 {Create New Worksheet} {
................................................................................

test FormatCellMerge-7.1 {Merge} {
  $spreadsheet merge $sheet 39,3 42,5
} 0


foreach item {obj cells fonts numFmts styles fills borders cols} {
  array set $item [array get ${spreadsheet}::$item]
}


test FormatCellWriteSpreatsheet-8.1 {Write Spreatsheet} {
  $spreadsheet write formatcell.xlsx
} 0

test FormatCellDestroySpreatsheet-8.2 {Destroy Spreatsheet} {
  $spreadsheet destroy
} 0


#catch {vfs::zip::Mount formatcell.xlsx xlsx} mnt
#vfs::zip::Unmount $mnt xlsx










































































































































































file delete -force formatcell.xlsx


# cleanup
::tcltest::cleanupTests
return








<







 







|












|
|
>
>

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







13
14
15
16
17
18
19

20
21
22
23
24
25
26
...
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
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
896
897
898
899
900
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
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
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
  package require tcltest 2
  namespace import -force ::tcltest::*
  loadTestedCommands
}


package require ooxml



test FormatCellNewSpreatsheet-1.1 {Create New Spreadsheet} -body {
  set spreadsheet [::ooxml::xl_write new -creator {Alexander Schöpe}]
} -result {::oo::Obj*} -match glob

test FormatCellNewWorksheet-1.2 {Create New Worksheet} {
................................................................................

test FormatCellMerge-7.1 {Merge} {
  $spreadsheet merge $sheet 39,3 42,5
} 0


foreach item {obj cells fonts numFmts styles fills borders cols} {
  array set w_$item [array get ${spreadsheet}::$item]
}


test FormatCellWriteSpreatsheet-8.1 {Write Spreatsheet} {
  $spreadsheet write formatcell.xlsx
} 0

test FormatCellDestroySpreatsheet-8.2 {Destroy Spreatsheet} {
  $spreadsheet destroy
} 0


test FormatCellReadWorkbook-9.1 {Read Workbook} {
  array set workbook [ooxml::xl_read formatcell.xlsx]
  return [llength $workbook(sheets)]
} 1

test FormatCellCheckBorders-9.2 {Check Borders} {
  set rc 1
  for {set i 0} {$i < $w_obj(borders)} {incr i} {
    set dw $w_borders($i)
    set dr $workbook(s,borders,$i)
    foreach key {left right top bottom diagonal} {
      array set w [dict get $dw $key]
      array set r [dict get $dr $key]
      foreach {n v} [array get w] {
	if {![info exists r($n)] || $r($n) ne $v} {
	  set rc 0
	}
      }
      unset -nocomplain w r
    }
    unset -nocomplain dw dr
  }
  return $rc
} 1

test FormatCellCheckFills-9.3 {Check Fills} {
  set rc 1
  for {set i 0} {$i < $w_obj(fills)} {incr i} {
    array set w $w_fills($i)
    array set r $workbook(s,fills,$i)
    foreach {n v} [array get w] {
      if {![info exists r($n)] || $r($n) ne $v} {
        set rc 0
      }
    }
    unset -nocomplain w r
  }
  return $rc
} 1

test FormatCellCheckFonts-9.4 {Check Fonts} {
  set rc 1
  for {set i 0} {$i < $w_obj(fonts)} {incr i} {
    array set w $w_fonts($i)
    array set r $workbook(s,fonts,$i)
    foreach {n v} [array get w] {
      if {![info exists r($n)] || $r($n) ne $v} {
        set rc 0
      }
    }
    unset -nocomplain w r
  }
  return $rc
} 1

test FormatCellCheckNumFmts-9.5 {Check NumFmts} {
  set rc 1
  for {set i 166} {$i < $w_obj(numFmts)} {incr i} {
    if {![info exists workbook(s,numFmts,$i)] || $workbook(s,numFmts,$i) ne $w_numFmts($i)} {
      set rc 0
    }
  }
  return $rc
} 1

test FormatCellCheckStyles-9.6 {Check Styles} {
  set rc 1
  for {set i 0} {$i < $w_obj(styles)} {incr i} {
    array set w $w_styles($i)
    array set r $workbook(s,styles,$i)
    foreach {n v} [array get w] {
      if {![info exists r($n)] || $r($n) ne $v} {
        set rc 0
      }
    }
    unset -nocomplain w r
  }
  return $rc
} 1


test FormatCellCheckColumns-10.1 {Check Worksheet Columns} {
  set rc 1
  set idxList {}
  foreach n [array names w_cols 1,*] {
    lappend idxList [lindex [split $n ,] end]
  }
  foreach i $idxList {
    array set w $w_cols(1,$i)
    array set r $workbook(0,col,$i)
    foreach {n v} [array get w] {
      if {![info exists r($n)] || $r($n) ne $v} {
        set rc 0
      }
    }
    unset -nocomplain w r
  }
  return $rc
} 1

test FormatCellCheckFilter-10.2 {Check Worksheet Filter} {
  set rc 1
  if {![info exists workbook(0,filter)] || $workbook(0,filter) ne $w_obj(autofilter,1)} {
    set rc 0
  }
  return $rc
} 1

test FormatCellCheckFreeze-10.3 {Check Worksheet Freeze} {
  set rc 1
  if {![info exists workbook(0,freeze)] || $workbook(0,freeze) ne $w_obj(freeze,1)} {
    set rc 0
  }
  return $rc
} 1

test FormatCellCheckMerge-10.4 {Check Worksheet Merge} {
  set rc 1
  if {![info exists workbook(0,merge)]} {
    set rc 0
  } else {
    foreach item $workbook(0,merge) {
      if {$item ni $w_obj(merge,1)} {
	set rc 0
      }
    }
  }
  return $rc
} 1

test FormatCellCheckRowHeight-10.5 {Check Worksheet RowHeight} {
  set rc 1
  array set w $w_obj(rowHeight,1)
  array set r $workbook(0,rowheight)
  foreach {n v} [array get w] {
    if {![info exists r($n)] || $r($n) ne $v} {
      set rc 0
    }
  }
  unset -nocomplain w r
  return $rc
} 1


test FormatCellCheckRowHeight-10.5 {Check Worksheet RowHeight} {
  set rc 1
  foreach item [lsort -dictionary [array names w_cells 1,*,*]] {
    lassign [split $item ,] sheet row col
    incr sheet -1
    array set w $w_cells($item)
    array unset w t
    array set r {}
    foreach tag {f s t v d} {
      if {[info exists workbook($sheet,$tag,$row,$col)]} {
	if {$tag eq {d}} {
	  # overwrite datetime string with ole date
	  array set r [list v $workbook($sheet,$tag,$row,$col)]
	} else {
	  array set r [list $tag $workbook($sheet,$tag,$row,$col)]
	}
      }
    }
    foreach {n v} [array get w] {
      if {![info exists r($n)] || $r($n) ne $v} {
	set rc 0
      }
    }
    unset -nocomplain w r
  }
  return $rc
} 1

file delete -force formatcell.xlsx


# cleanup
::tcltest::cleanupTests
return