Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re^2: Update: Provblem 'solved' by Anonymous Monk
in thread Using Spreadsheet::WriteExcel with mod_perl and Content-Disposition? by one4k4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-24 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found