ooxml

Check-in [43be3b2012]
Login

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

Overview
Comment:Added credits. Editorial clean-up. Removed the for this now not anymore used helper proc ::ooxml::Zip*.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | populationspeed
Files: files | file ages | folders
SHA3-256: 43be3b2012076d97ed8fd6b1efdb57151744938147fc44a47588102049e0342e
User & Date: rolf 2019-08-14 21:29:03
Context
2019-08-15
06:42
move package require vfs::zip to procs xl_sheets and xl_read because it is only needed to read data check-in: 0ebe84a691 user: alex tags: populationspeed
2019-08-14
21:29
Added credits. Editorial clean-up. Removed the for this now not anymore used helper proc ::ooxml::Zip*. check-in: 43be3b2012 user: rolf tags: populationspeed
15:52
Turns out, that creating the zip (at least as it currently done with vfs) eats up some time. Removed the need for vfs (only for writing!), now the zip is created with core on-board means. This reduces the time per cell needed for writing to 2/3. check-in: e06fcddeb0 user: rolf tags: populationspeed
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ooxml.tcl.

467
468
469
470
471
472
473

474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
...
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
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
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
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
#
#   DOS timestamps are 32 bits split into bit regions as follows:
#                  24                16                 8                 0
#   +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
#   |Y|Y|Y|Y|Y|Y|Y|m| |m|m|m|d|d|d|d|d| |h|h|h|h|h|m|m|m| |m|m|m|s|s|s|s|s|
#   +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
#

  proc ::timet_to_dos {time_t} {
    set s [clock format $time_t -format {%Y %m %e %k %M %S}]
    scan $s {%d %d %d %d %d %d} year month day hour min sec
    expr {(($year-1980) << 25) | ($month << 21) | ($day << 16) 
          | ($hour << 11) | ($min << 5) | ($sec >> 1)}
  }

  # ooxml::add_str_to_archive --
  #
  #        Add a string as a single file with string as content with
  #        argument path to a zip archive. The zipchan channel should
  #        already be open and binary. The return value is the central
  #        directory record that will need to be used when finalizing
  #        the zip archive.
  #


proc ::ooxml::add_str_to_archive {zipchan path data {comment ""}} {
  set mtime [timet_to_dos [clock seconds]]
  set utfpath [encoding convertto utf-8 $path]
  set utfcomment [encoding convertto utf-8 $comment]
  set flags [expr {(1<<11)}] ;# utf-8 comment and path
  set method 0               ;# store 0, deflate 8
  set attr 0                 ;# text or binary (default binary)
................................................................................
	return [list ${Y}-${m}-${d}T${H}:${M}:${S}]
      }
      return [set ole [expr {[clock scan ${Y}${m}${d}T${H}${M}${S} -gmt 1] / 86400.0 + 25569}]]
    }
  }
  return {}
}


proc ::ooxml::ZipInitialize { *v file } {
  upvar ${*v} v

  set fd [open $file w]
  set v(fd) $fd
  set v(base) [tell $fd]
  set v(toc) {}
  fconfigure $fd -translation binary -encoding binary
}


proc ::ooxml::ZipEmit { *v s } {
  upvar ${*v} v

  puts -nonewline $v(fd) $s
}


proc ::ooxml::ZipDosTime { sec } {
  set f [clock format $sec -format {%Y %m %d %H %M %S} -gmt 1]
  regsub -all { 0(\d)} $f { \1} f
  foreach {Y M D h m s} $f break
  set date [expr {(($Y-1980)<<9) | ($M<<5) | $D}]
  set time [expr {($h<<11) | ($m<<5) | ($s>>1)}]
  return [list $date $time]
}


proc ::ooxml::ZipAddEntry { *v name contents {date {}} {force 0} } {
  upvar ${*v} v

  if {$date eq {}} {
    set date [clock seconds]
  }
  lassign [ZipDosTime $date] date time
  set flag 0
  set type 0 ;# stored
  set fsize [string length $contents]
  set csize $fsize
  set fnlen [string length $name]
  
  if {$force > 0 && $force != [string length $contents]} {
    set csize $fsize
    set fsize $force
    set type 8 ;# if we're passing in compressed data, it's deflated
  }
  
  if {[catch {zlib crc32 $contents} crc]} {
    set crc 0
  } elseif {$type == 0} {
    set cdata [zlib deflate $contents 9]
    if {[string length $cdata] < [string length $contents]} {
      set contents $cdata
      set csize [string length $cdata]
      set type 8 ;# deflate
    }
  }
  
  lappend v(toc) "[binary format a2c6ssssiiiss4ii PK {1 2 20 0 20 0} $flag $type $time $date $crc $csize $fsize $fnlen {0 0 0 0} 128 [tell $v(fd)]]$name"
  
  ZipEmit v [binary format a2c4ssssiiiss PK {3 4 20 0} $flag $type $time $date $crc $csize $fsize $fnlen 0]
  ZipEmit v $name
  ZipEmit v $contents
}


proc ::ooxml::ZipAddDirectory { *v name {date {}} {force 0} } {
  upvar ${*v} v

  set name "${name}/"
  if {$date eq {}} {
    set date [clock seconds]
  }
  lassign [ZipDosTime $date] date time
  set flag 0
  set type 0 ;# stored
  set fsize 0
  set csize 0
  set fnlen [string length $name]
  set crc 0
  
  lappend v(toc) "[binary format a2c6ssssiiiss4ii PK {1 2 20 0 20 0} $flag $type $time $date $crc $csize $fsize $fnlen {0 0 0 0} 128 [tell $v(fd)]]$name"
  
  ZipEmit v [binary format a2c4ssssiiiss PK {3 4 20 0} $flag $type $time $date $crc $csize $fsize $fnlen 0]
  ZipEmit v $name
}


proc ::ooxml::ZipFinalize { *v } {
  upvar ${*v} v

  set pos [tell $v(fd)]
  set ntoc [llength $v(toc)]
  foreach x $v(toc) {
    ZipEmit v $x
  }
  set v(toc) {}
  
  set len [expr {[tell $v(fd)] - $pos}]
  incr pos -$v(base)
  
  ZipEmit v [binary format a2c2ssssiis PK {5 6} 0 0 $ntoc $ntoc $len $pos 0]
  
  close $v(fd)
}


proc ::ooxml::Zip { zipfile directory files } {
  array set v { fd {} base {} toc {} }

  # this code is a rewrite and extension of the zipper code found
  # at http://equi4.com/critlib/ and http://wiki.tcl.tk/36689
  # by Tom Krehbiel 2012 krehbiel.tom at gmail dot com


  ZipInitialize v $zipfile
  foreach file $files {
    regsub {^\./} $file {} to
    set from [file join [file normalize $directory] $to]
    if {[file isfile $from]} {
      set fd [open $from r]
      fconfigure $fd -translation binary -encoding binary
      ZipAddEntry v $to [read $fd] [file mtime $from]
      close $fd
    } elseif {[file isdir $from]} {
      ZipAddDirectory v $to [file mtime $from]
      lappend dirs $file
    }
  }
  ZipFinalize v
}


proc ::ooxml::Column { col } {
  set name {}
  while {$col >= 0} {
    set char [binary format c [expr {($col % 26) + 65}]]
    set name $char$name
    set col [expr {$col / 26 -1}]







>
|
|
|
|
|
|

|
|
|
|
|
|
|
|
<
>







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489

490
491
492
493
494
495
496
497
...
740
741
742
743
744
745
746






































































































































747
748
749
750
751
752
753
#
#   DOS timestamps are 32 bits split into bit regions as follows:
#                  24                16                 8                 0
#   +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
#   |Y|Y|Y|Y|Y|Y|Y|m| |m|m|m|d|d|d|d|d| |h|h|h|h|h|m|m|m| |m|m|m|s|s|s|s|s|
#   +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
#
# From tcllib / zipfile::mkzip      
proc ::ooxml::timet_to_dos {time_t} {
  set s [clock format $time_t -format {%Y %m %e %k %M %S}]
  scan $s {%d %d %d %d %d %d} year month day hour min sec
  expr {(($year-1980) << 25) | ($month << 21) | ($day << 16) 
        | ($hour << 11) | ($min << 5) | ($sec >> 1)}
}

# ooxml::add_str_to_archive --
#
#        Add a string as a single file with string as content with
#        argument path to a zip archive. The zipchan channel must
#        already be open and binary. The return value is the central
#        directory record that will need to be used when finalizing
#        the zip archive.
#

# Derived from tcllib / zipfile::mkzip::add_file_to_archive
proc ::ooxml::add_str_to_archive {zipchan path data {comment ""}} {
  set mtime [timet_to_dos [clock seconds]]
  set utfpath [encoding convertto utf-8 $path]
  set utfcomment [encoding convertto utf-8 $comment]
  set flags [expr {(1<<11)}] ;# utf-8 comment and path
  set method 0               ;# store 0, deflate 8
  set attr 0                 ;# text or binary (default binary)
................................................................................
	return [list ${Y}-${m}-${d}T${H}:${M}:${S}]
      }
      return [set ole [expr {[clock scan ${Y}${m}${d}T${H}${M}${S} -gmt 1] / 86400.0 + 25569}]]
    }
  }
  return {}
}







































































































































proc ::ooxml::Column { col } {
  set name {}
  while {$col >= 0} {
    set char [binary format c [expr {($col % 26) + 65}]]
    set name $char$name
    set col [expr {$col / 26 -1}]