rbholder has asked for the wisdom of the Perl Monks concerning the following question:

Long time listener, first time caller

I am migrating all my Perl CGI web apps from a Rackspace server to an internal corporate server that is running Centos 6. I use Excel::Writer::XLSX to create a spreadsheet in a folder like /var/www/cgi-bin/app/temp/fName.xlsx and then use a statment like

redirect('http://sales.com/cgi-bin/app/temp/'.$fileName);

The intention is to automatically download the xlsx file like it does on the Rackspace server. The file is being created but I get an HTTP 500 error. I have all the AddTypes and AddHandlers on the internal server as I did on the Rackspace server. I am running Perl 5.20 and Apache 2.2. What gives?

Replies are listed 'Best First'.
Re: Redirect to an XLSX spreadsheet
by Your Mother (Archbishop) on Sep 13, 2014 at 16:07 UTC

    Sounds like your server is setup to execute things in the /cgi-bin so it’s treating the .xlsx file as a script the server can run and it’s erroring when it tries. Try saving the file to a plain document directory (where you already have images/html/etc) and redirecting to that location. A more straightforward approach (unless the files are HUGE) might be to serve it directly as an attachment. E.g.,

    print $cgi->header( -type => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' );

    …and then print the file to STDOUT. Search here: https://www.google.com/search?q=site%3Aperlmonks.org+attachment+cgi&oq=site%3Aperlmonks.org+attachment+cgi.

      Thank you for your response, venerable Monk !

      I haven't tried the attachment yet but that sounds intriguing. I cheated and just took the last x off the filename. So I can redirect to /cgi-bin/temp/filename.xls but not /cgi-bin/temp/filename.xlsx. Still think it's an AddHandler or AddType thang. Thanks again for your help.

Re: Redirect to an XLSX spreadsheet
by roboticus (Chancellor) on Sep 13, 2014 at 22:39 UTC

    rbholder:

    Another alternative may be limit your HTML to a set that Excel recognizes, along with an appropriate content header. Then they can see the spreadsheet on the screen, and if they download it, it can save to a file with an .xls extension. I've done it before, and it worked very nicely. I don't recall what the stripped down HTML is, off the top of my head, but I can tell you how I got to it.

    I simply created a spreadsheet with the formatting I wanted, and saved it as HTML. Then, I started chopping out the "cruft" bits (of which there are many), paring it down until Excel would still open it successfully, and simple enough to generate.

    Note: This technique may not be acceptable in todays .CSS / dynamic / whizz-bang web application world, though.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Redirect to an XLSX spreadsheet
by Anonymous Monk on Sep 14, 2014 at 05:38 UTC