I don't know the answer to your specific question, but...

What I do is output the generated .csv content directly.
You must first send a "Content-Disposition" header so the
browser will handle it correctly.  (Of course the header
is different for IE and Netscape.)

The following subroutine is ASP PerlScript.  You'll have
to convert it if you are working in a CGI environment.

--Steve


sub WriteCSVHeaders {
#===========================================================================
=====
#  usage: <|--#include virtual="/lib/CSV.inc"-->
#         <% WriteCSVHeaders("myfile.csv") %>
#
#  Adds headers to response stream which cause browser to open
#  output as a CSV file in MS Excel (or optionally save file).
#
#  If no filename is passed, "noname.csv" is used.
#
#  If browser is not MSIE, a number is added to the filename to
#  avoid quirky behavior on subsequent downloads of same filename.
#  (i.e. file.csv, file(1).csv, file(2).csv)  These numbers are
#  maintained with a session variable which is reset when the
#  browser closes.
#
#  IIS requires that headers be generated prior to first ouput.
#
#  Written by: [EMAIL PROTECTED]
#===========================================================================
=====
        my $filename = $_[0] || "noname.csv";

        if ($Request->servervariables->{http_user_agent}->item =~ /MSIE/) {
                $Response->{'ContentType'} = "text/csv";
                $Response->AddHeader("Content-Disposition","attachment;
filename=$filename");
        }else{
                $Response->{'ContentType'} = "application/vnd.ms-excel";
                my %csv_files = split "\t",$Session->{csv_files};
                (my $fname=$filename)=~s/\.[^.]+//; # remove extension
                if ($csv_files{$fname}){
                        $Response->AddHeader("Content-Disposition","attachment;
filename=$fname($csv_files{$fname}).csv");
                }else{
                        $Response->AddHeader("Content-Disposition","attachment;
filename=$fname.csv");
                }
                $csv_files{$fname}++;
                $Session->{csv_files} = join "\t",%csv_files;
        }
}
</script>

> Subject: CSV in excel from the web
>
> I have a script that connects to a database and pulls out lots
> of rows...  Now, what I'm doing is outputting that to a CSV
> fromatted file and using CGI's redirect method to send my browser
> to my newly created file....Gonz

_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to