--- loncom/interface/lonquickgrades.pm 2011/06/04 19:49:28 1.101 +++ loncom/interface/lonquickgrades.pm 2011/06/25 20:12:56 1.102 @@ -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::grades; 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 @@ sub endGradeScreen { $r->print(''.&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('
'. + ''.&mt('Your Excel spreadsheet').''."\n"); + $r->rflush(); + &excel_cleanup(); + return; +} + + +# +# CSV data +# +# ----------- + +# +# Go through the complete course and collect data +# sub getData {