[LON-CAPA-cvs] cvs: loncom /interface londropadd.pm /interface/spreadsheet Spreadsheet.pm assesscalc.pm classcalc.pm studentcalc.pm /interface/statistics lonproblemstatistics.pm lonstudentassessment.pm

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 10 Mar 2005 17:33:58 -0000


This is a MIME encoded message

--matthew1110476038
Content-Type: text/plain

matthew		Thu Mar 10 12:33:58 2005 EDT

  Modified files:              
    /loncom/interface	londropadd.pm 
    /loncom/interface/spreadsheet	Spreadsheet.pm assesscalc.pm 
                                 	classcalc.pm studentcalc.pm 
    /loncom/interface/statistics	lonproblemstatistics.pm 
                                	lonstudentassessment.pm 
  Log:
  Updated to use loncommon::create_workbook.  Spreadsheets were slightly
  modified to use formats.
  
  
--matthew1110476038
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20050310123358.txt"

Index: loncom/interface/londropadd.pm
diff -u loncom/interface/londropadd.pm:1.125 loncom/interface/londropadd.pm:1.126
--- loncom/interface/londropadd.pm:1.125	Thu Feb 17 03:29:42 2005
+++ loncom/interface/londropadd.pm	Thu Mar 10 12:33:57 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to drop and add students in courses 
 #
-# $Id: londropadd.pm,v 1.125 2005/02/17 08:29:42 albertel Exp $
+# $Id: londropadd.pm,v 1.126 2005/03/10 17:33:57 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1326,14 +1326,9 @@
         }
     } elsif ($mode eq 'excel') {
         # Create the excel spreadsheet
-        $excel_filename = '/prtspool/'.
-            $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
-                time.'_'.rand(1000000000).'.xls';
-        $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.
-                                                       $excel_filename);
-        $excel_workbook->set_tempdir('/home/httpd/perl/tmp');
-        #
-        $format = &Apache::loncommon::define_excel_formats($excel_workbook);
+        ($excel_workbook,$excel_filename,$format) = 
+            &Apache::loncommon::create_workbook($r);
+        return if (! defined($excel_workbook));
         $excel_sheet = $excel_workbook->addworksheet('classlist');
         #
         my $description = 'Class List for '.
Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.39 loncom/interface/spreadsheet/Spreadsheet.pm:1.40
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.39	Thu Mar  3 12:52:36 2005
+++ loncom/interface/spreadsheet/Spreadsheet.pm	Thu Mar 10 12:33:57 2005
@@ -1,5 +1,5 @@
 #
-# $Id: Spreadsheet.pm,v 1.39 2005/03/03 17:52:36 matthew Exp $
+# $Id: Spreadsheet.pm,v 1.40 2005/03/10 17:33:57 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1433,31 +1433,6 @@
     return;
 }
 
-sub create_excel_spreadsheet {
-    my $self = shift;
-    my ($r) = @_;
-    my $filename = '/prtspool/'.
-        $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
-        time.'_'.rand(1000000000).'.xls';
-    my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
-    if (! defined($workbook)) {
-        $r->log_error("Error creating excel spreadsheet $filename: $!");
-        $r->print(&mt("Problems creating new Excel file.  ".
-                  "This error has been logged.  ".
-                  "Please alert your LON-CAPA administrator"));
-        return undef;
-    }
-    #
-    # The excel spreadsheet stores temporary data in files, then put them
-    # together.  If needed we should be able to disable this (memory only).
-    # The temporary directory must be specified before calling 'addworksheet'.
-    # File::Temp is used to determine the temporary directory.
-    $workbook->set_tempdir('/home/httpd/perl/tmp');
-    #
-    # Determine the name to give the worksheet
-    return ($workbook,$filename);
-}
-
 #
 # This routine is just a stub 
 sub outsheet_htmlclasslist {
@@ -1478,8 +1453,8 @@
     #
     $r->print("<h2>".&mt('Preparing Excel Spreadsheet')."</h2>");
     #
-    # Create excel worksheet
-    my ($workbook,$filename) = $self->create_excel_spreadsheet($r);
+    # Create excel workbook
+    my ($workbook,$filename,$format)=&Apache::loncommon::create_workbook($r);
     return if (! defined($workbook));
     #
     # Create main worksheet
@@ -1490,16 +1465,18 @@
     # Write excel header
     foreach my $value ($self->get_title()) {
         $cols_output = 0;
-        $worksheet->write($rows_output++,$cols_output,$value);
+        $worksheet->write($rows_output++,$cols_output,$value,$format->{'h1'});
     }
     $rows_output++;    # skip a line
     #
     # Write summary/export row
     $cols_output = 0;
-    $self->excel_output_row($worksheet,0,$rows_output++,'Summary');
+    $self->excel_output_row($worksheet,0,$rows_output++,'Summary',
+                            $format->{'b'});
     $rows_output++;    # skip a line
     #
-    $self->excel_rows($connection,$worksheet,$cols_output,$rows_output);
+    $self->excel_rows($connection,$worksheet,$cols_output,$rows_output,
+                      $format);
     #
     #
     # Close the excel file
Index: loncom/interface/spreadsheet/assesscalc.pm
diff -u loncom/interface/spreadsheet/assesscalc.pm:1.37 loncom/interface/spreadsheet/assesscalc.pm:1.38
--- loncom/interface/spreadsheet/assesscalc.pm:1.37	Thu Mar  3 12:52:36 2005
+++ loncom/interface/spreadsheet/assesscalc.pm	Thu Mar 10 12:33:57 2005
@@ -1,5 +1,5 @@
 #
-# $Id: assesscalc.pm,v 1.37 2005/03/03 17:52:36 matthew Exp $
+# $Id: assesscalc.pm,v 1.38 2005/03/10 17:33:57 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -562,15 +562,15 @@
     # writes the meat of the spreadsheet to an excel worksheet.  Called
     # by Spreadsheet::outsheet_excel;
     my $self = shift;
-    my ($connection,$worksheet,$cols_output,$rows_output) = @_;
+    my ($connection,$worksheet,$cols_output,$rows_output,$format) = @_;
     return if (! ref($worksheet));
     #
     # Write a header row
     $cols_output = 0;
     foreach my $value ('Parameter','Description','Value') {
-        $worksheet->write($rows_output,$cols_output++,$value);
+        $worksheet->write($rows_output,$cols_output++,$value,$format->{'h4'});
     }
-    $rows_output++;    
+    $rows_output++;
     #
     # Write each row
     foreach my $rownum (sort {$a <=> $b} ($self->rows())) {
Index: loncom/interface/spreadsheet/classcalc.pm
diff -u loncom/interface/spreadsheet/classcalc.pm:1.21 loncom/interface/spreadsheet/classcalc.pm:1.22
--- loncom/interface/spreadsheet/classcalc.pm:1.21	Tue Jun  8 11:55:38 2004
+++ loncom/interface/spreadsheet/classcalc.pm	Thu Mar 10 12:33:57 2005
@@ -1,5 +1,5 @@
 #
-# $Id: classcalc.pm,v 1.21 2004/06/08 15:55:38 matthew Exp $
+# $Id: classcalc.pm,v 1.22 2005/03/10 17:33:57 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -228,12 +228,12 @@
     # writes the meat of the spreadsheet to an excel worksheet.  Called
     # by Spreadsheet::outsheet_excel;
     my $self = shift;
-    my ($connection,$worksheet,$cols_output,$rows_output) = @_;
+    my ($connection,$worksheet,$cols_output,$rows_output,$format) = @_;
     #
     # Write a header row
     $cols_output = 0;
     foreach my $value ('Fullname','Username','Domain','Section','Status','ID') {
-        $worksheet->write($rows_output,$cols_output++,&mt($value));
+        $worksheet->write($rows_output,$cols_output++,&mt($value),$format->{'h4'});
     }
     $rows_output++;    
     #
Index: loncom/interface/spreadsheet/studentcalc.pm
diff -u loncom/interface/spreadsheet/studentcalc.pm:1.28 loncom/interface/spreadsheet/studentcalc.pm:1.29
--- loncom/interface/spreadsheet/studentcalc.pm:1.28	Thu Mar  3 12:52:36 2005
+++ loncom/interface/spreadsheet/studentcalc.pm	Thu Mar 10 12:33:57 2005
@@ -1,5 +1,5 @@
 #
-# $Id: studentcalc.pm,v 1.28 2005/03/03 17:52:36 matthew Exp $
+# $Id: studentcalc.pm,v 1.29 2005/03/10 17:33:57 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -387,12 +387,12 @@
     # writes the meat of the spreadsheet to an excel worksheet.  Called
     # by Spreadsheet::outsheet_excel;
     my $self = shift;
-    my ($connection,$worksheet,$cols_output,$rows_output) = @_;
+    my ($connection,$worksheet,$cols_output,$rows_output,$format) = @_;
     #
     # Write a header row
     $cols_output = 0;
     foreach my $value ('Container','Assessment title') {
-        $worksheet->write($rows_output,$cols_output++,&mt($value));
+        $worksheet->write($rows_output,$cols_output++,&mt($value),$format->{'h4'});
     }
     $rows_output++;    
     #
Index: loncom/interface/statistics/lonproblemstatistics.pm
diff -u loncom/interface/statistics/lonproblemstatistics.pm:1.100 loncom/interface/statistics/lonproblemstatistics.pm:1.101
--- loncom/interface/statistics/lonproblemstatistics.pm:1.100	Tue Mar  8 12:40:39 2005
+++ loncom/interface/statistics/lonproblemstatistics.pm	Thu Mar 10 12:33:57 2005
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemstatistics.pm,v 1.100 2005/03/08 17:40:39 matthew Exp $
+# $Id: lonproblemstatistics.pm,v 1.101 2005/03/10 17:33:57 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1264,30 +1264,13 @@
     &compute_all_statistics($r);
     my $c = $r->connection;
     return if ($c->aborted());
+    #
+    my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
     ##
     ## Create the excel workbook
-    my $filename = '/prtspool/'.
-        $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
-        time.'_'.rand(1000000000).'.xls';
-    my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
-    #
-    # Create sheet
-    my $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
-    #
-    # Check for errors
-    if (! defined($excel_workbook)) {
-        $r->log_error("Error creating excel spreadsheet $filename: $!");
-        $r->print(&mt("Problems creating new Excel file.  ".
-                  "This error has been logged.  ".
-                  "Please alert your LON-CAPA administrator."));
-        return 0;
-    }
-    #
-    # The excel spreadsheet stores temporary data in files, then put them
-    # together.  If needed we should be able to disable this (memory only).
-    # The temporary directory must be specified before calling 'addworksheet'.
-    # File::Temp is used to determine the temporary directory.
-    $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
+    my ($excel_workbook,$filename,$format) =
+        &Apache::loncommon::create_workbook($r);
+    return if (! defined($excel_workbook));
     #
     # Add a worksheet
     my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
@@ -1296,8 +1279,6 @@
     }
     my $excel_sheet = $excel_workbook->addworksheet(
         &Apache::loncommon::clean_excel_name($sheetname));
-    #
-    my $format = &Apache::loncommon::define_excel_formats($excel_workbook);
     ##
     ## Begin creating excel sheet
     ##
Index: loncom/interface/statistics/lonstudentassessment.pm
diff -u loncom/interface/statistics/lonstudentassessment.pm:1.116 loncom/interface/statistics/lonstudentassessment.pm:1.117
--- loncom/interface/statistics/lonstudentassessment.pm:1.116	Mon Feb 28 12:23:11 2005
+++ loncom/interface/statistics/lonstudentassessment.pm	Thu Mar 10 12:33:58 2005
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonstudentassessment.pm,v 1.116 2005/02/28 17:23:11 matthew Exp $
+# $Id: lonstudentassessment.pm,v 1.117 2005/03/10 17:33:58 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -939,6 +939,7 @@
 
 my $excel_sheet;
 my $excel_workbook;
+my $format;
 
 my $filename;
 my $rows_output;
@@ -1005,9 +1006,6 @@
     }
     return if ($request_aborted);
     #
-    $filename = '/prtspool/'.
-        $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
-            time.'_'.rand(1000000000).'.xls';
     #
     $excel_workbook = undef;
     $excel_sheet = undef;
@@ -1035,24 +1033,9 @@
     my $first_data_row = $rows_output++;
     #
     # Create sheet
-    $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
-    #
-    # Check for errors
-    if (! defined($excel_workbook)) {
-        $r->log_error("Error creating excel spreadsheet $filename: $!");
-        $r->print("Problems creating new Excel file.  ".
-                  "This error has been logged.  ".
-                  "Please alert your LON-CAPA administrator");
-        return ;
-    }
-    #
-    # The excel spreadsheet stores temporary data in files, then put them
-    # together.  If needed we should be able to disable this (memory only).
-    # The temporary directory must be specified before calling 'addworksheet'.
-    # File::Temp is used to determine the temporary directory.
-    $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
-    #
-    my $format = &Apache::loncommon::define_excel_formats($excel_workbook);
+    ($excel_workbook,$filename,$format)=
+        &Apache::loncommon::create_workbook($r);
+    return if (! defined($excel_workbook));
     #
     # Add a worksheet
     my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};

--matthew1110476038--