[LON-CAPA-cvs] cvs: loncom /interface lonquickgrades.pm

www www@source.lon-capa.org
Sat, 25 Jun 2011 20:12:56 -0000


www		Sat Jun 25 20:12:56 2011 EDT

  Modified files:              
    /loncom/interface	lonquickgrades.pm 
  Log:
  Starting on Excel output
  
  
Index: loncom/interface/lonquickgrades.pm
diff -u loncom/interface/lonquickgrades.pm:1.101 loncom/interface/lonquickgrades.pm:1.102
--- loncom/interface/lonquickgrades.pm:1.101	Sat Jun  4 19:49:28 2011
+++ loncom/interface/lonquickgrades.pm	Sat Jun 25 20:12:56 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Quick Student Grades Display
 #
-# $Id: lonquickgrades.pm,v 1.101 2011/06/04 19:49:28 www Exp $
+# $Id: lonquickgrades.pm,v 1.102 2011/06/25 20:12:56 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -38,6 +38,22 @@
 use Apache::loncoursedata;
 use Apache::lonstudentassessment;
 
+use Time::HiRes;
+use Spreadsheet::WriteExcel;
+use Spreadsheet::WriteExcel::Utility();
+#
+# Excel data
+#
+my $excel_sheet;
+my $excel_workbook;
+my $filename;
+my $format;
+my $request_aborted;
+my $header_row;
+my $cols_output;
+my %prog_state;
+
+
 sub handler {
     my $r = shift;
     return real_handler($r);
@@ -259,6 +275,68 @@
    $r->print('</div></div></div>'.&Apache::loncommon::end_page());
 }
 
+# -----------
+
+
+sub excel_cleanup {
+    undef ($excel_sheet);
+    undef ($excel_workbook);
+    undef ($filename);
+    undef ($format);
+}
+
+
+sub excel_initialize {
+    my ($r) = @_;
+
+    &excel_cleanup();
+
+    # Create sheet
+    ($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'};
+    $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
+    $excel_sheet = $excel_workbook->addworksheet($sheetname);
+   #
+   # Put the course description in the header
+    $excel_sheet->write($header_row,$cols_output++,
+                   $env{'course.'.$env{'request.course.id'}.'.description'},
+                        $format->{'h1'});
+} 
+
+sub excel_finish {
+    my ($r) = @_;
+    if ($request_aborted || ! defined($excel_sheet)) {
+        &excel_cleanup();
+        return;
+    }
+    #
+    # Write the excel file
+    $excel_workbook->close();
+    #
+    # Close the progress window
+    &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+    #
+    # Tell the user where to get their excel file
+    $r->print('<br />'.
+              '<a href="'.$filename.'">'.&mt('Your Excel spreadsheet').'</a>'."\n");
+    $r->rflush();
+    &excel_cleanup();
+    return;
+}
+
+
+#
+# CSV data
+#
+# -----------
+
+#
+# Go through the complete course and collect data
+#
 
 sub getData {