--- loncom/interface/spreadsheet/Spreadsheet.pm 2005/08/24 18:14:47 1.53 +++ loncom/interface/spreadsheet/Spreadsheet.pm 2005/08/26 20:46:46 1.54 @@ -1,5 +1,5 @@ # -# $Id: Spreadsheet.pm,v 1.53 2005/08/24 18:14:47 albertel Exp $ +# $Id: Spreadsheet.pm,v 1.54 2005/08/26 20:46:46 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -968,25 +968,32 @@ sub formulas { $self->{'formulas'} = $formulas; $self->{'rows'} = []; $self->{'template_cells'} = []; + $self->{'loaded'} = 1; return; } else { - if (!$self->{'loaded'}) { - $self->{'loaded'}=1; - # Load in the spreadsheet definition - if (exists($env{'form.workcopy'}) && - $self->{'type'} eq $env{'form.workcopy'}) { - $self->load_tmp(); - } else { - $self->load(); - } - } + $self->check_formulas_loaded(); return %{$self->{'formulas'}}; } } +sub check_formulas_loaded { + my $self=shift; + if (!$self->{'loaded'}) { + $self->{'loaded'}=1; + # Load in the spreadsheet definition + if (exists($env{'form.workcopy'}) && + $self->{'type'} eq $env{'form.workcopy'}) { + $self->load_tmp(); + } else { + $self->load(); + } + } +} + sub set_formula { my $self = shift; my ($cell,$formula) = @_; + $self->check_formulas_loaded(); $self->{'formulas'}->{$cell}=$formula; return; } @@ -996,7 +1003,7 @@ sub set_formula { ## sub formulas_keys { my $self = shift; - my @keys = keys(%{$self->{'formulas'}}); + $self->check_formulas_loaded(); return keys(%{$self->{'formulas'}}); } @@ -1007,6 +1014,7 @@ sub formulas_keys { sub formula { my $self = shift; my $cell = shift; + $self->check_formulas_loaded(); if (defined($cell) && exists($self->{'formulas'}->{$cell})) { return $self->{'formulas'}->{$cell}; } @@ -1085,6 +1093,7 @@ sub rebuild_stats { my $self = shift; $self->{'rows'}=[]; $self->{'template_cells'}=[]; + $self->check_formulas_loaded(); while (my ($cell,$formula) = each(%{$self->{'formulas'}})) { push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/ && $1 != 0); push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/); @@ -1525,6 +1534,7 @@ sub outsheet_xml { ## Will be rendered for the user ## But not on this day my $Str = ''."\n"; + $self->check_formulas_loaded(); while (my ($cell,$formula) = each(%{$self->{'formulas'}})) { if ($cell =~ /^template_(\w+)/) { my $col = $1; @@ -1674,6 +1684,7 @@ sub load { sub set_row_sources { my $self = shift; + $self->check_formulas_loaded(); while (my ($cell,$value) = each(%{$self->{'formulas'}})) { next if ($cell !~ /^A(\d+)/ || $1 < 1); my $row = $1; @@ -1684,6 +1695,7 @@ sub set_row_sources { sub set_row_numbers { my $self = shift; + $self->check_formulas_loaded(); while (my ($cell,$value) = each(%{$self->{'formulas'}})) { next if ($cell !~ /^A(\d+)$/); next if (! defined($value));