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

I have this CGI application that needs to take a server-side XML file, and launch MS Excel on the client machine and feed the file to it.

I've been looking at MIME::Type and MIME::Entity, but I'm not sure that they are exactly what I need, and I haven't managed to find any exaples of this functionality.

What would the monks suggest as an approach here, and has anyone seen any examples of this?

Thanks.

Replies are listed 'Best First'.
Re: Launching Excel from a CGI
by derby (Abbot) on Oct 30, 2006 at 17:51 UTC

    Set the Cotent-Type Content-Type appropriately (application/vnd.ms-excel) and then just output CSV - that would be my starting point.

    -derby

    Update: err ... Content-Type not Cotent-Type. Thks cog.

      I was going to say "Hey, it's not 'Cotent-Type'", but then I noticed he asked for 'exaples', so I guess you're talking the same language O:-)
      Think I got it:
      sub retrieveFile { my $file = shift; if(not -e $file) { croak "Could not locate file: $file)"; } if(not open(FH, $file)) { croak "Could not open file: $file"; } my $filesize = -s $file; ## Note type will need to change based on the type of file that is ## returned. print $cgi->header(-type=>'application/vnd.ms-excel', -Content-Disposition=>"attachment; filename=$fi +le", -Content_Length=>$filesize); while(<FH>) { print; } close FH; }
Re: Launching Excel from a CGI
by Popcorn Dave (Abbot) on Oct 30, 2006 at 21:28 UTC
    I found this while looking for a spreadsheet that I could embed in a CGI app. It's an ajax spreadsheet based on Dojo 0.3.1. I don't know if it's going to be as advanced as you'll need for your spreadsheets, but I believe it works on your machine with your storage, not online storage. Plus you can download it, so you get all source.

    Not a Perl solution but it may work for you just the same.

    HTH!

    Revolution. Today, 3 O'Clock. Meet behind the monkey bars.
Re: Launching Excel from a CGI
by rashley (Scribe) on Oct 30, 2006 at 18:46 UTC
    Ah, one hitch. As is, the default file name when you go to open/save it is the name of the CGI doing the work. How can I control that name?

      Use something like LiveHTTPHeaders (or wget) to see if your Content-Disposition is being set correctly -- I haven't tested it but I think you may need to do Content_Disposition. Or just use the -attachment parameter:

      print $cgi->header( -type => 'application/vnd.ms-excel', -attachment => $file, -Content_Length => $filesize );

      -derby

      update: Either using -Content_Disposition or -attachment works for me.

Re: Launching Excel from a CGI
by themage (Friar) on Oct 31, 2006 at 11:04 UTC