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

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 10 Mar 2005 00:21:49 -0000


matthew		Wed Mar  9 19:21:49 2005 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  &define_excel_formats: Added 'h4' format
  Added &create_workbook which takes care of the boring part of creating an
      Excel workbook.
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.254 loncom/interface/loncommon.pm:1.255
--- loncom/interface/loncommon.pm:1.254	Wed Mar  2 15:35:46 2005
+++ loncom/interface/loncommon.pm	Wed Mar  9 19:21:48 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.254 2005/03/02 20:35:46 matthew Exp $
+# $Id: loncommon.pm,v 1.255 2005/03/10 00:21:48 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -897,6 +897,7 @@
     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
+    $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
     $format->{'i'}    = $workbook->add_format(italic=>1);
     $format->{'date'} = $workbook->add_format(num_format=>
                                             'mm/dd/yyyy hh:mm:ss');
@@ -908,6 +909,49 @@
 
 =pod
 
+=item &create_workbook
+
+Create an Excel worksheet.  If it fails, output message on the
+request object and return undefs.
+
+Inputs: Apache request object
+
+Returns (undef) on failure, 
+    Excel worksheet object, scalar with filename, and formats 
+    from &Apache::loncommon::define_excel_formats on success
+
+=cut
+
+###############################################################
+###############################################################
+sub create_workbook {
+    my ($r) = @_;
+        #
+    # Create the excel spreadsheet
+    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('<p>'.&mt("Unable to create new Excel file.  ".
+                            "This error has been logged.  ".
+                            "Please alert your LON-CAPA administrator").
+                  '</p>');
+        return (undef);
+    }
+    #
+    $workbook->set_tempdir('/home/httpd/perl/tmp');
+    #
+    my $format = &Apache::loncommon::define_excel_formats($workbook);
+    return ($workbook,$filename,$format);
+}
+
+###############################################################
+###############################################################
+
+=pod
+
 =item * change_content_javascript():
 
 This and the next function allow you to create small sections of an