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

I'm trying to develop a query tool. I'm using CGI scripts right now my Result comes out on a web page as a table.I want that Result as excel spread sheet. Any suggestion how to do it. what function (if any)should I add to my script.

Replies are listed 'Best First'.
Re: Output from CGI script
by IndyZ (Friar) on Feb 10, 2001 at 03:51 UTC
Re: Output from CGI script
by eg (Friar) on Feb 10, 2001 at 03:50 UTC

    I've done this by setting the header to application/msexcel and sending the data as a tab-delimited table (I don't know how to build a "real" Excel table).

    You might also use text/tab-separated-values in the header and set up your computer to open up Excel (or any other spreadsheet you want to use) for that mime type.

    I think I once read that modern versions of Excel can read html tables directly, but as I don't have any version of Excel to test with, I can't confirm ...

    Update: actually I like IndyZ's advice...

Re: Output from CGI script
by Yohimbe (Pilgrim) on Feb 10, 2001 at 03:55 UTC
    Try this: change your content type to text/comma-separated, and train your users to import the file into excel.
    I've done it in the past, and its very easy and effective.
    --
    Jay "Yohimbe" Thorne, alpha geek for UserFriendly
(meonkeys: extracting HTML and producing CSV)
by meonkeys (Chaplain) on Feb 10, 2001 at 07:18 UTC
    Unless you have control over the CGI that's generating the HTML, you have to use something like LWP::Simple to fetch the HTML, and maybe something to parse it.

    Text::CSV_XS is a fast and reliable way to generate comma-separated text that can be easily imported into Excel. Just make sure you strip out any newlines from STDIN (s#\r\n##g or something) because these will confuse Text::CSV_XS .
Re: Output from CGI script
by roXet (Initiate) on Feb 10, 2001 at 10:07 UTC
    If I am not mistaken Win32::OLE will allow you to build Excel spreadsheets and what not