--- loncom/interface/Attic/lonspreadsheet.pm	2002/11/20 16:46:31	1.144
+++ loncom/interface/Attic/lonspreadsheet.pm	2002/11/21 19:05:18	1.146
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.144 2002/11/20 16:46:31 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.146 2002/11/21 19:05:18 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1530,10 +1530,9 @@ A link to the spreadsheet will be availa
 END
     $r->rflush();
     my $starttime = time;
-    foreach (keys(%f)) {
-	next if ($_!~/^A(\d+)/ || $1 == 0 || ($f{$_}=~/^[!~-]/));
+    foreach my $rownum (&sort_indicies($sheet)) {
         $count++;
-        my ($sname,$sdom) = split(':',$f{$_});
+        my ($sname,$sdom) = split(':',$f{'A'.$rownum});
         my $student_excel_worksheet=$workbook->addworksheet($sname.'@'.$sdom);
         # Create a new spreadsheet
         my $studentsheet = &makenewsheet($sname,$sdom,'studentcalc',undef);
@@ -2365,7 +2364,8 @@ sub loadstudent{
     undef @tmp;
     # 
     my @assessdata=();
-    while (my ($cell,$value) = each (%formulas)) {
+    foreach my $cell (keys(%formulas)) {
+        my $value = $formulas{$cell};
         if(defined($c) && ($c->aborted())) {
             last;
         }
@@ -2377,18 +2377,15 @@ sub loadstudent{
                                  $sheet->{'udom'},
                                  'assesscalc',$usy,$ufn,$r);
         my $index=0;
-        foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
-                 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') {
+        foreach my $col ('A','B','C','D','E','F','G','H','I','J','K','L','M',
+                         'N','O','P','Q','R','S','T','U','V','W','X','Y','Z') {
             if (defined($assessdata[$index])) {
-                my $col=$_;
                 if ($assessdata[$index]=~/\D/) {
                     $constants{$col.$row}="'".$assessdata[$index]."'";
                 } else {
                     $constants{$col.$row}=$assessdata[$index];
                 }
-                unless ($col eq 'A') { 
-                    $formulas{$col.$row}='import';
-                }
+                $formulas{$col.$row}='import' if ($col ne 'A');
             }
             $index++;
         }
@@ -2689,6 +2686,7 @@ sub forcedrecalc {
 #
 sub exportsheet {
     my ($sheet,$uname,$udom,$stype,$usymb,$fn,$r)=@_;
+    my $flag = 0;
     $uname = $uname || $sheet->{'uname'};
     $udom  = $udom  || $sheet->{'udom'};
     $stype = $stype || $sheet->{'sheettype'};
@@ -2757,14 +2755,24 @@ sub exportsheet {
                                        [$key],
                                        $sheet->{'cdom'},$sheet->{'cnum'});
         if ($tmp[0]!~/^error/) {
-            %currentlystored = @tmp;
+            # We only got one key, so we will access it directly.
+            foreach (split('___&___',$tmp[1])) {
+                my ($key,$value) = split('___=___',$_);
+                $key = '' if (! defined($key));
+                $currentlystored{$key} = $value;
+            }
         }
     } else {
         my @tmp = &Apache::lonnet::get('nohist_calculatedsheets_'.
                                        $sheet->{'cid'},[$key],
                                        $sheet->{'udom'},$sheet->{'uname'});
         if ($tmp[0]!~/^error/) {
-            %currentlystored = @tmp;
+            # We only got one key, so we will access it directly.
+            foreach (split('___&___',$tmp[1])) {
+                my ($key,$value) = split('___=___',$_);
+                $key = '' if (! defined($key));
+                $currentlystored{$key} = $value;
+            }
         }
     }
     #