Subject: | Specification of Content-Disposition and downloaded filename |
Sometimes the user will need to set a flag on the downloaded data so
that it is not viewed inline, but forced to be downloaded, and specify a
proposed filename for the download. This code adds this funcionality:
(Catalyst/View/Excel/Template/Plus.pm, near line 69):
...
$excel->param( $self->get_template_params($c) );
#### JGV 2011/03/10
my $excel_filename = $c->stash->{excel_filename} || (split '/',$c-
Show quoted text
>req->path)[-1] || 'index.xls';
$excel_filename .= '.xls' unless ($excel_filename =~ /\.xls$/i);
my $excel_disposition = $c->stash->{excel_disposition} || 'inline';
$c->response->headers->header("Content-Disposition" =>
qq{$excel_disposition; filename="$excel_filename"});
#### END JGV
$c->response->content_type('application/x-msexcel');
$c->response->body($excel->output);
}
...
Proposed code is between the #### JGV lines. Feel free to remove them
from the definitive code :-)
This code does the following:
- If no 'excel_filename' key has been stashed, a proposed filename of
"index.xls" will be selected, otherwise the specified one will be used.
- User can select the disposition ('attachment' or 'inline') with the
stash key 'excel_disposition'. If none is selected, 'inline' will be
used as the default.
Again, thanks for a usefull module :-)
Regards
Jorge