Results 1 to 3 of 3

Thread: Perl script sends Excel file to browser

  1. #1
    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.

  2. #2
    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";

  3. #3
    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.

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,627,777.95860 seconds with 16 queries