in reply to Using Spreadsheet::WriteExcel with mod_perl and Content-Disposition?

Well, it seems to be solved. Sort of. I mean, it works grand, and the patch to OLEwriter.pm and sample code(below) that John sent me did the trick.

#!/usr/bin/perl -w ###################################################################### +# # # Example of how write to alternative filehandles. # # March 2001, John McNamara, jmcnamara@cpan.org # use strict; use Spreadsheet::WriteExcel; use IO::Scalar; # # Example 1. Write an Excel file to a string. # # Refer to the IO::Scalar documentation my $xls_str; tie *XLS, 'IO::Scalar', \$xls_str; my $workbook1 = Spreadsheet::WriteExcel->new(\*XLS); my $worksheet1 = $workbook1->addworksheet(); $worksheet1->write(0, 0, "Hi Excel!"); $workbook1->close(); # This is required # The Excel file is now in $xls_str. # If you write it to a new file remember to binmode() the filehandle. # # Example 2. Write an Excel file to an existing filehandle. # open TEST, "> mytest1.xls"; my $workbook2 = Spreadsheet::WriteExcel->new(\*TEST); my $worksheet2 = $workbook2->addworksheet(); $worksheet2->write(0, 0, "Hi Excel!"); $workbook2->close(); # # Example 3. Write an Excel file to an OO style filehandle. # my $fh = FileHandle->new("> mytest2.xls"); my $workbook3 = Spreadsheet::WriteExcel->new($fh); my $worksheet3 = $workbook3->addworksheet(); $worksheet3->write(0, 0, "Hi Excel!"); $workbook3->close();


Its working beautifully, and seems to have no problem under mod_perl. I'm going to try to use the method below, per John's asking, and see if that works tomorrow when I get to my machine.
# Untested tie *XLS => 'Apache'; my $workbook = Spreadsheet::WriteExcel->new(\*XLS);

But we'll see what happens. Hopefully the next version will have no problems getting released. John's got my support.

_14k4 - webmaster@860.org (www.poorheart.com)

Replies are listed 'Best First'.
Re: Update: Provblem 'solved'
by one4k4 (Hermit) on Mar 20, 2001 at 18:22 UTC
    The code
    # Untested tie *XLS => 'Apache'; my $workbook = Spreadsheet::WriteExcel->new(\*XLS);

    Woohoo. Thanks all!

    _14k4 - webmaster@860.org (www.poorheart.com)

      I am having a similar problem. I have a link on a report detailing some ticket information. That link should regenerate the same data as displayed on the page but as an excel spreadsheet that is passed to the user for download and not saved on the server.

      The link works, a download dialog appears to save the file but for some reason the file appears to be limited to around 400k in size ( a little under 4500 of the 9755 rows that should appear. When I change from a file handle to saving the file to the server it works fine, the problem only happens when it's a direct download. Any help you could offer would be great

          tie *XLS, 'IO::Scalar', \$xls_str;
          my $workbook = Spreadsheet::WriteExcel::Big->new(\*XLS);
          my $worksheet = $workbook->add_worksheet();
      
          # Hardcoded row and column fields
          $worksheet->set_landscape();
          $worksheet->set_row(0,30);
          $worksheet->set_column(0,0, 20);
          $worksheet->set_column(1,1, 20);
          $worksheet->set_column(2,2, 20);
          $worksheet->set_column(3,3, 20);
          $worksheet->set_column(4,4, 20);
          $worksheet->set_column(5,5, 20);
          $worksheet->set_column(6,6, 20);
      
          # Spreadsheet Formating
          my $format = $workbook->add_format();
          my $titleformat = $workbook->add_format();
          $format->set_bold(1);
          $titleformat->set_size(15);
      
          # Counters
          my $rowcount = 1;
      
          # loops for writing
          while ( my @row = $sth->fetchrow_array ) {
            my $row_ref = \@row;
            $worksheet->write_row($rowcount,0,  $row_ref);
            $rowcount++;
          } #end of loop
      
          $workbook->close();
      
          #my $size = (-s $xls_str);
          print "content: myfile.xls\r\n";
          print "content-disposition: inline; filename=myfile.xls\r\n";
          #print "content-length: $size\r\n";
          print "content-type: application/vnd.ms-excel\r\n";
      
          #local $/ = undef;
          #open (F, "<$xls_str");
          #  binmode(F); binmode(STDOUT);
          #  print <F>;
          #close(F);
          print $xls_str;
      

      in the above script if I replace

          tie *XLS, 'IO::Scalar', \$xls_str;
          my $workbook = Spreadsheet::WriteExcel->new(\*XLS);
      
      with
          my $filename = "myfile.xls";
          my $workbook = Spreadsheet::WriteExcel->new($filename);
      
      The file is saved to my server with the correct number of rows

      I believe the problem has something to do with IO::Scalar and/or an apache config but I'm a little lost as to what I could be missing