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

I'm adding another function to a website, basically it will give the clients the ability to view/download their data as Excel spreadsheets.

The rest of the site is ASP, mainly used as SSI, and PerlScript. The authorization system is coupled to the Session object.
Currently I use Spreadsheet::WriteExcel to generate the data using standard perl cgi and it works great. The problem is to make both authorization and spreadsheet generation work together.

1. If I stick to std perl cgi is there any way to get to the Session object ?

2. PerlScript would put me into the problem of transmitting the binary spreadsheet, probably using $Response->BinaryWrite, right ?

The site is currently located at an ISP which probably means that using native Excel through Win32::OLE is out of the question and besides Spreadsheet::WriteExcel does not contain macros thereby eliminating the potential of sending virus-infected data to the clients.

In perl we trust ....

  • Comment on $Session from cgi BinaryWrite from PerlScript

Replies are listed 'Best First'.
Re: $Session from cgi BinaryWrite from PerlScript
by Caillte (Friar) on Oct 05, 2001 at 14:58 UTC

    In answer to question 2, a quick and easy way to transmit the data as a CSV file (comma seperated database format). This can be transmitted as text and Excel sets up CSV as one of it's own file types.

    Thinking about it, this will probably preclude the need for using CGI... you can generate the data from your asp page.

    Of course, not knowing what type of information you wish to send, this is only a guess ;)

    $japh->{'Caillte'} = $me;

      Of course, not knowing what type of information you wish to send, this is only a guess ;)

      That would preclude any formatting to the data, fonts, bold, etc

      Anyway, what "Content-Type" and "Content-Disposition" would your solution entail ?

        Yes, it would preclude fonts etc for it is a data only format. The content-type: text/plain

        $japh->{'Caillte'} = $me;

Re: $Session from cgi BinaryWrite from PerlScript
by trantor (Chaplain) on Oct 05, 2001 at 16:09 UTC

    I've done this in the past using Apache::ASP.

    Choice 1 is highly non-portable, due to the vairous ways of storing session data.

    I would recommend choice 2, there's no need to use $Response->BinaryWrite, but you must set the correct Content-type. Thus you could say:

    $Response->{ContentType} = 'application/vnd.ms-excel'; # Generate your sheet and store it in $sheet print $sheet; # Or $Response->Write($sheet);

    -- TMTOWTDI

      I can't vouch for how portable this solution is, since I believe that it requires certain versions of IE and Excel (and Windows, of course) However, if you want to stay entirely within ASP in order to meet your authorization requirements, try this out. If you know that your users will be using at least IE 5.01 and that they have at least Excel 2000 on their machines, then you can change $Response->{Content-Type} to 'application/vnd.ms-excel' as suggested above and simply $Response->Write the content as normal HTML tables.

      IE and Excel should cooperate via OLE/ActiveX and display the content as an Excel spreadsheet within IE itself, and if the users want to save the file out, they can just select File->Save As from the IE menu, and it will default to saving as an Excel .xls file. As I mentioned, I believe that this requires minimum versions of IE and Excel, although I haven't personally tested it on other versions.

      Also, for formatting purposes, you can use CSS within the various table tags via the "style" attribute. Unfortunately, using a separate CSS stylesheet (whether linked or elsewhere in the HTML) and "class" attributes doesn't seem to be reliable.

      Granted, this is a narrow subset of user requirements, and you're essentially limited to non-dynamic Excel content, i.e. pure data, no formulas or other such things. However, we use a solution like this at my company to provide web-based reports to our marketing department. This allows us to use the same basic presentation code for both the HTML and Excel versions of the reports. The only modifications required to make the reports Excel-friendly are to strip out any sort of UI widgets or other unnecessary sections and then change the Content-Type.

      Now, if we could just wean the marketing department off of Excel, that would be a MUCH better solution. But, alas ...

      -jehuni

Re: $Session from cgi or BinaryWrite from PerlScript
by guha (Priest) on Oct 05, 2001 at 19:00 UTC
    Regarding Q:1 I don't seem to have expressed myself clearly enough.

    The Session object I'm talking about is the $Server-object, that has already been modified by the PerlScripts(ASP) which handles the login/auth stuff.

    As PerlScript(TM) itself is able to interface with this IIS stuff it shouldn't be impossible to read the wanted properties but then on the other hand, right, PerlScript is not pure perl.

    Having two different Sessionhandlers for the site would be a bad thing, perhaps I will have to resort to passing encrypted parameters in the form?.

    This being my first writeup, I didn't notice that my original title "$Session from cgi || BinaryWrite from PerlScript" was changed to something less than intelligeble, however TIMTOWTDI in perl.

Re: $Session from cgi BinaryWrite from PerlScript
by perrin (Chancellor) on Oct 05, 2001 at 18:01 UTC
    You can replace the Session object with CGI::State or Apache::Session (which does not require mod_perl or apache). Some coding is required. The smoothest transition is to Apache::ASP, but that requires mod_perl.