Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Using Perlscript in ASP to create excel file

by chooper (Initiate)
on Sep 25, 2012 at 14:17 UTC ( #995560=perlquestion: print w/ replies, xml ) Need Help??
chooper has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I am struggling with opening an excel application and writing data to it from perlscript in a .asp webpage. I have test example .pl file which does the job nicely...opening up excel and the file. See below code:

#!/usr/bin/perl -w ###################################################################### +######### # # Example of how to use the Spreadsheet::WriteExcel module to send an +Excel # file to a browser in a CGI program. # # On Windows the hash-bang line should be something like: # # #!C:\Perl\bin\perl.exe # # The "Content-Disposition" line will cause a prompt to be generated t +o save # the file. If you want to stream the file to the browser instead, com +ment out # that line as shown below. # # reverse(''), March 2001, John McNamara, jmcnamara@cpan.org # use strict; use Spreadsheet::WriteExcel; # Set the filename and send the content type my $filename ="cgitest.xls"; print "Content-type: application/vnd.ms-excel\n"; # The Content-Disposition will generate a prompt to save the file. If +you want # to stream the file to the browser, comment out the following line. print "Content-Disposition: attachment; filename=$filename\n"; print "\n"; # Create a new workbook and add a worksheet. The special Perl filehand +le - will # redirect the output to STDOUT # my $workbook = Spreadsheet::WriteExcel->new("-"); my $worksheet = $workbook->add_worksheet(); # Set the column width for column 1 $worksheet->set_column(0, 0, 20); # Create a format my $format = $workbook->add_format(); $format->set_bold(); $format->set_size(15); $format->set_color('blue'); # Write to the workbook $worksheet->write(0, 0, "Hi Excel!", $format); __END__

This next bit is where I come unstuck. When I put this code in a .asp file with <%@ Language=PerlScript %> tags in it then it doesn't work. So the code in .pl file opens Excel fine but with the code in the .asp file nothing happens. This is what I tried to do:

<%@ Language=PerlScript %> <% use strict; use Spreadsheet::WriteExcel; # Set the filename and send the content type my $filename ="cgitest.xls"; print "Content-type: application/vnd.ms-excel\n"; # The Content-Disposition will generate a prompt to save the file. If +you want # to stream the file to the browser, comment out the following line. print "Content-Disposition: attachment; filename=$filename\n"; print "\n"; # Create a new workbook and add a worksheet. The special Perl filehand +le - will # redirect the output to STDOUT # my $workbook = Spreadsheet::WriteExcel->new("-"); my $worksheet = $workbook->add_worksheet(); # Set the column width for column 1 $worksheet->set_column(0, 0, 20); # Create a format my $format = $workbook->add_format(); $format->set_bold(); $format->set_size(15); $format->set_color('blue'); # Write to the workbook $worksheet->write(0, 0, "Hi Excel!", $format); __END__ %>

Probably, needless to say I am a novice. I am stumped on this and would value some guidance. Kind regards, Catherine

Comment on Using Perlscript in ASP to create excel file
Select or Download Code
Re: Using Perlscript in ASP to create excel file
by Anonymous Monk on Sep 25, 2012 at 19:56 UTC

    but with the code in the .asp file nothing happens

    What do you expect to happen?

Re: Using Perlscript in ASP to create excel file
by Anonymous Monk on Sep 26, 2012 at 02:08 UTC

    Hi

    I'm not sure what you are trying to do, but I feel that a look at Template::Toolkit or similar may be of use to you.

    Or maybe check the web for Ajax.

    J.C.

      Thanks for checking anyway. I appreciate that. Probably my lack of knowledge in PerlScript running in .asp combined with not explaining myself well has resulted in a no solution yet for me. I'm still looking in to it. But just briefly I have asp running perlscript. i.e.
      <%@ Language=PerlScript %> <% for($i=0; $i<=10; $i++) { # # my Perl code here # } %>
      I use a lot of Perl modules on the asp pages in perlscript language Win32::ODBC etc.. and all works fine and I just can't understand why opening an excel application and writing to it should be any different. I'll keep going...hopefully in the right direction...just need to ask the right questions really....
        Opening an excel application? Where do you attempt that?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2014-09-21 00:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls