proc mkSheet {w {flag {}}} {

#	builds a spreadsheet inside any frame handed to it

   global CellValues CellFormulae SheetT

#  just in case it is a toplevel

   set wn $w
   if {$w == "."} {set w ""}
   if {$w == ""} {set wn "."}

#   puts stderr "W is $w   WN is $wn"

   frame $w.mb -background bisque
   frame $w.ss -background bisque

#	the sheet widget will be SheetT
  set SheetT $w.ss.grid
  set cfont [getFont {} mediumcou]
  set tfont [getFont {} mediumhelb]


  scrollbar $w.ss.vert -relief sunken -command "$SheetT yview"  -orient vertical \
	-troughcolor bisque -background ivory -activebackground mistyrose
  scrollbar $w.ss.horz -relief sunken -command "$SheetT xview"  -orient horizontal \
	-troughcolor bisque -background ivory -activebackground mistyrose

#	menubar frame is mb (at top)
  menubutton $w.mb.data -menu $w.mb.data.m -text "File..." -background lavender -border 2 -relief raised -activebackground lavender -activeforeground magenta3
  set m [menu $w.mb.data.m -background lavender]
  $m add command -label "Recompute" -command "compSheet $SheetT" -background lavender -activebackground lavender -activeforeground magenta3
  $m add command -label "Export TSV..." -command "fileBox .save_Results * \"\" \"\" \"doSaveSheet $SheetT TSV\"" -background lavender -activebackground lavender -activeforeground magenta3
  $m add command -label "Export TXT..." -command "fileBox .save_Results * \"\" \"\" \"doSaveSheet $SheetT TXT\"" -background lavender -activebackground lavender -activeforeground magenta3
  $m add command -label "Save w/Calc..." -command "fileBox .save_Results * \"\" \"\" \"doSaveSheet $SheetT FOR\"" -background lavender -activebackground lavender -activeforeground magenta3
  $m add command -label "Import TSV..." -command "fileBox .save_Results * \"\" \"\" \"doLoadSheet $SheetT\"" -background lavender -activebackground lavender -activeforeground magenta3

  button $w.mb.eras -text Clear -command "clearSheet $SheetT" -background lemonchiffon -activebackground lemonchiffon -activeforeground red
  button $w.mb.quit -text Quit -command "destroy $wn" -background white -foreground red -activebackground black -activeforeground yellow

  frame $w.ss.c -background bisque
  label $w.ss.c.clab -relief sunken -background ivory -font $tfont \
	-text "Cell Edit:" -width 20
  set SheetEdLab $w.ss.c.clab
  entry $w.ss.c.cell -relief sunken -background white -foreground red \
	-textvariable curVal -border 2 
  button $w.ss.c.adds -background lavender -text "Add2Formula" \
	-command "addCell2Form A $SheetT"
  set SheetAddB $w.ss.c.adds
  bind $w.ss.c.cell <Return> "cellCommit $SheetT"
  table $SheetT -relief sunken -background ivory \
	 -yscroll "$w.ss.vert set" -xscroll "$w.ss.horz set" \
	-cols 10 -rows 25 -variable CellValues -font $cfont \
	-browsecommand "cellSelect %W" -anchor w -titlerows 1 \
	-titlecols 1 -exportselection 1 -selectmode extended 
  $SheetT tag config separator -bg gray
  $SheetT tag config active -fg red -bg yellow
  $SheetT tag config sel -bg yellow
  $SheetT tag config formula -bg seashell
  $SheetT tag config error -bg mistyrose
  $SheetT tag config title -bg papayawhip -font $tfont -fg black \
	-anchor center
  $SheetT tag config heads -bg azure -font $tfont 
  $SheetT width 0 6
  set curRow 1
  keySheet $SheetT
  
  bind $SheetT <Control-u> "clearSheet $SheetT; break"

  set font [getFont {} mediumhelb]
  message $w.ss.msg -text "Spreadsheet ready for use" -justify center -aspect 2000  -width 700 -relief sunken -font $font -background ivory
  pack $w.ss.msg -side bottom -fill x

  pack $w.ss.c.clab -side left
  pack $w.ss.c.adds -side right 
  pack $w.ss.c.cell -side left -fill x -expand true
  pack $w.ss.c -side top -fill x -expand true
  pack $w.ss.vert -side right -fill y
  pack $w.ss.horz -side bottom -fill x
  pack $SheetT -side top -fill both -expand true
  bind $SheetT <Control-x> "clearSheet $SheetT; break"

  pack $w.mb.data -side left
  pack $w.mb.quit -side right
  pack $w.mb.eras -side right
  pack $w.mb -side top -expand true -fill x
  pack $w.ss -side top -expand true -fill both

}
