Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Excel generation

by Anonymous Monk
on Sep 11, 2004 at 00:00 UTC ( [id://390211]=perlquestion: print w/replies, xml ) Need Help??

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

I am trying to use a a CGI script to output an excel generation using Win::OLE. The interface and database are run on the same machine. When I run the script/page from the command prompt it generates both page content and also loads Microsoft Excel with the required parametres. I am using apache as the webserver.Why will the same code not generate the excel output when run through my webserver. Is it an issue with rights and permissions. Any advise would be great. This one has me really confused and stumped. Thankyou for your time.

Replies are listed 'Best First'.
Re: Excel generation
by Your Mother (Archbishop) on Sep 11, 2004 at 00:33 UTC

    Try this at the top of your script before you output the data:

    use CGI (); # <<--update print CGI::header(-type => 'application/vnd.ms-excel');
Re: Excel generation
by rjbs (Pilgrim) on Sep 11, 2004 at 16:42 UTC
    As a side note, please consult Q257757, which gives some good reasons to not run Office programs behind the scenes on a non-interactive session, like a CGI script. It points you at the OWC (Office Web Componants) which can be used for similar effect. Also consider Spreadsheet::WriteExcel, which will let you produce Excel files without the bloat of Excel itself.

    I do a lot of Excel automation in interactive mode, but doing so in a CGI is risky and not advisable.
    rjbs
Re: Excel generation
by Anonymous Monk on Sep 11, 2004 at 01:02 UTC

    Thankyou very much for your time and advise. This seems to work nicely. Using the code you provided, do i simply just use a series of 'print' commands to generate output rather than using Win::OLE code such as

    $worksheet->Cells(5,1)->{Value} = "Dunedin 9001";

    This embeeds excel into my application (great), but how can i allow my client to print the page contents? I know good old Ctrl + P works fine, but is not really feasible. Can i also embeed the Main menu of excel into my page? Thankyou again for your help. I would be lost without you guys. Digger

    Also when i run this script from a button on a previous page, it pops up a dialog box asking to open or save. Can i avoid this unwanted step

      We're going to need a little more about how you have your webserver set up, what you're really trying to do, and how you expect your users to do it.

      When I output an Excel version of reports that users run on my webapp, I just print it out to the browser with the appropriate Content-Type header and the browser does the right thing. At that point, the user is welcome to look at it, save it, or print it ... as they see fit.

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      I shouldn't have to say this, but any code, unless otherwise stated, is untested

Re: Excel generation
by Anonymous Monk on Sep 11, 2004 at 10:19 UTC
    The project involves a Microsoft SQL Database and a perl cgi interface, on a Win XP machine, running the apache webserver. I learned about avaliable GUI's for perl, (Tk etc) as this is a system run on a single machine, but did not have the time to learn (Is it worth learning for applications?). I am reading values from the database and now I am wanting to print this information. I looked at Javascripts but found they added unwanted text to my printed page. This is why Win::OLE plus it adds the ability to save this information as an xls document. I have read information that apache does not let external programs run, and this is why my scripts only run when ran from a command prompt. Thankyou for the code to embeed excel into my application. Just now want to be able to allow printing from this page (Ctrl + P) and save.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://390211]
Approved by jdtoronto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found