Downloading Excel File


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Downloading Excel File
# 1  
Old 01-15-2008
Downloading Excel File

Hello All,

Currently working with CGI scripts in perl which involves
a) uploading
b) processing
c) downloading the file back to the user

uploading and processing quite trivial and they are done

Third part is kind of being tricky.
Excel file in binary format is getting displayed in the html page itself and not popping up a download window for downloading file to the client's machine

Code snippet
Code:
my @fileholder;

open(EXCLFILE, "<", $file_path) or die "Unable to download file $file_path\n";
 binmode EXCLFILE;
 @fileholder = <EXCLFILE>;
close (EXCLFILE);

print "Content-Type:application/vnd.ms-excel\n";
print "Content-Disposition:attachment;filename=$file_path\n\n";
print @fileholder;

Any pointers to proceed with this is much appreciated.

Thanks Smilie

Last edited by matrixmadhan; 01-15-2008 at 12:43 PM..
# 2  
Old 01-15-2008
put "application/octet-stream" instead of "vnd.ms-excel" , it should work. Else, look at these thread, it may help.
# 3  
Old 01-15-2008
This is completely running over my head.

I did went through the link provided in perlmonks and tried it,
but its refusing to work Smilie

Please find the snippet below

Code:
my $cgi = new CGI;

  open(DLFILE, "<$abs_path") || die "Unable to download file $abs_path\n";
  print $cgi->header(
    '-type' => "application/octet-stream; name=$filename",
    '-Content-Disposition' => "attachment; filename=$abs_path",
    '-Content-Transfer-Encoding' => "binary");
    binmode DLFILE;
    print while(<DLFILE>);
  close (DLFILE);

Ex:
Code:
$abs_path = "/home/matrix/file.xls";
$filename = "file.xls";

No way, a download pop up window is up
and all the binary contents of the excel file is displayed as such in the html page.

Any pointers again, much appreciated Smilie
# 4  
Old 01-16-2008
Code:
use strict;
use CGI qw /:standard /;
my $query = new CGI;
print $query->header(-type=>"application/vnd.ms-excel",-attachment=>"path/file.xls",-Content_length=>" -s path/file.xls");
open (FH, "path/file.xls");
print $_ while <FH>;
close (FH);

- found it on internet, i'm not sure if it's going to work. Strange, that the content type is not honored, even though it's forced to be binary-octet-stream. Another try : setup wrong type like :"bad-file-type" and this should pop-up. Last resort is to put MIME type in apache's config -
Code:
AddType application/vnd.ms-excel .xls

# 5  
Old 01-16-2008
Thanks for the reply Sysgate.

I already have the specified MIME type in mime configuration file
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

File downloading

I saved to disk using lynx, under ls it shows up but no matter what I have done back comes the statment no such file. How do you erase these ls false readings or open what ls shows? (9 Replies)
Discussion started by: Jackbird
9 Replies

2. Shell Programming and Scripting

How to check if downloading of a file is completed?

Hello All. We are getting one zip file from another server daily. The size of the zip file will be around 4.5 gb that takes time to download completely. I have to process that file furthest once get downloaded completely. I have written one code for that, but i need suggestion whether it is a... (7 Replies)
Discussion started by: looney
7 Replies

3. Shell Programming and Scripting

Downloading file from mainframe to UNIX

Hi All , I need a help regarding file ftp ing from mainframe to unix.Our source file is mainframe file.I need to download the mainframe file to local unix server through unix script.If anyone can help me how we can do it through unix script ,it will be really helpful.Thanks. (7 Replies)
Discussion started by: STCET22
7 Replies

4. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

5. Shell Programming and Scripting

Perl script to Merge contents of 2 different excel files in a single excel file

All, I have an excel sheet Excel1.xls that has some entries. I have one more excel sheet Excel2.xls that has entries only in those cells which are blank in Excel1.xls These may be in different workbooks. They are totally independent made by 2 different users. I have placed them in a... (1 Reply)
Discussion started by: Anamika08
1 Replies

6. Shell Programming and Scripting

Writing excel file using perl : Excel file formatting changed

I am trying to create a program where user can input data in certain excel cells using user interface on internet....the programming is on perl and server is unix But when i parse data into excel the formatting of sheets is turned to default and all macro coding removed. What to do...Please... (7 Replies)
Discussion started by: mud_born
7 Replies

7. Shell Programming and Scripting

File downloading help in perl

Im trying to write a perl code to do the following task. I have a website which is located in a diffirent country. I want to download a file from that site everyday. The file name keeps on changing everyday. say the file name is CTP-latest-5.3.0.37.iso next day it may change to... (0 Replies)
Discussion started by: srijith
0 Replies

8. Shell Programming and Scripting

File downloading

Hi, I am newbie in Perl/CGI and I need your help to develop a little script to help me to download some files located in a FTP server via HTTP to a disk. I need to authenticate with username/password via a HTTP page and I can choose the files to download from the web page to my disk. Can... (2 Replies)
Discussion started by: imad77
2 Replies

9. Shell Programming and Scripting

Downloading file from internet

Hi, I need to write a script to download a file (say http: //www.mysite.com/myfile.txt) from the internet (please note that the file is on http not ftp). Please let me know if there is any method other than wget. Thanks, Chetan (4 Replies)
Discussion started by: chetanpc
4 Replies

10. Shell Programming and Scripting

Downloading a csv file automatically

I want to automatically download a CSV file daily which can be found here: London Stock Exchange - Search and the link is named "Click to download covered warrants (100Kb)" on the right hand side. What commands can I use to invoke clicking on this link and initiating the download? And also... (2 Replies)
Discussion started by: figaro
2 Replies
Login or Register to Ask a Question