Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 21-11-2009
Member
 
Join Date: Oct 2009
Posts: 38
Perl script sends Excel file to browser

Hi Friends
I have a problem regarding my perl program. I am trying this for two weeks but unfortunately did not succeeded. I want to have my web site generate an Ecel file on the fly that is a database export and send it ot the user's web browser. How can I achieve this, does any one have ideas about this or any one has done this before. Please help. Thanks in advance. Waiting for the reply.
Reply With Quote
  #2  
Old 21-11-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: Perl script sends Excel file to browser

Hello
I assume that you need to export a simple sheet containing strings and numbers, and assume you need no formulas. You have to generate a CSV file (this is a comma separated file) and set the mime type to application or octet stream. I assume that if your perl script is named as exportcsv.pl then the downloaded file will be named exportcsv.pl.xls by default. you can also change the default name but I am not showing this in the example. Go through the following code:
Code:
# sending a file simply as an Excel
print "Content-type: application/vnd.ms-excel\n";
print "Content-Disposition: attachment;filename=users.csv\n\n";

# alternative 2:
# sending a CSV file and suggesting 'users.csv' as the file name
print "Content-type: application/octet-stream\n";
print "Content-Disposition: attachment;filename=users.csv\n\n";

# now dump the data
# all values are enclosed by " in case the 
# strings contain a comma
# this dumps 2 rows with 2 columns each
print '"1","Test, first one"' . "\n";
print '"2","Test, last one"' . "\n";
Reply With Quote
  #3  
Old 21-11-2009
Member
 
Join Date: Jul 2009
Posts: 127
Re: Perl script sends Excel file to browser

Hi
I am have a slight different problem, but still I am posting it because it is some what related to the topic. I am trying to call a perl script from a javascript which has to generate a CSV file. I even went thorugh the above posted code but it's not working for me. I am posting my code below, see if any one can help or have a solution for this.
Code:
function testCSV()
{
alert('Got the data');    
new Ajax.Request(cgiPath+'testCSV.pl',
{
method: 'get',
parameters: {
action: 'createCSV',
    type: 'sample',
    ts: new Date().getTime()
    },
onComplete: function() {
    alert('Created CSV');
    }
});
}
Perl Script
use CGI;
use JSON;
$cgi = new CGI();
$action = $cgi->param('action');
if ($action eq 'createCSV')
{
    createCSV();
}
else
{
    die 'Action not specified';
}
sub createCSV
{
    print 'Content-type: application/octet-stream\n';
    print 'Content-Disposition: attachment;filename=users.csv\n\n';
    print ''1','Test, first one'' . '\n';
    print ''2','Test, last one'' . '\n';
}
Any help will be appreciated. Thanks in advance.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Perl script sends Excel file to browser"
Thread Thread Starter Forum Replies Last Post
Getting error when opening excel file using a VB script Madri Software Development 4 18-07-2012 06:27 PM
Is it possible to execute Perl script within another script? RasMus Software Development 2 21-07-2009 10:57 PM
Need Perl script to execute from another. beelow Software Development 2 20-06-2009 09:17 AM
Title of a Perl CGI script !const Software Development 2 26-03-2009 11:43 PM
How to read and modify excel file using PHP script JamesB Software Development 3 17-03-2009 11:59 PM


All times are GMT +5.5. The time now is 04:16 AM.