On Mon, 23 Aug 2004 09:48:36 -0700, Tim Howell wrote:
Hi Tim
You probably have enough ideas to go on by now, but I might as well
throw in another.
Firstly a warning re MS Excel. By default, it splits on commas even
when those commas are inside quotes. My users put up with that.
I output CSV files if the user clicks a Download button when they are
already viewing the data.
In other words I prepare the data as below and then display it as
HTML, and the click on the Download button re-executes the CGI script,
which generates exactly the same data, but outputs it as CSV.
Wrap will make this a bit hard to read.
1 Build an array ref of data and convert to HTML:
(The 0 here means Do not download)
my($data) = $self -> build_entity_staff_list_data($entity_id, 0);
$content -> param(person_loop => [map{ {css_class =>
$$_{'css_class'}, td_loop => [map{ {td => $_} } @{$$_{'td_loop'} }]} }
@$data]);
2 The template:
<tmpl_loop name = person_loop>
<tr class = "<tmpl_var name = css_class default = white>">
<tmpl_loop name = td_loop>
<td><tmpl_var name = td></td>
</tmpl_loop>
</tr>
</tmpl_loop>
3 Build an array ref of data and convert to CSV:
(The 1 here means Download)
my($data) = $self -> build_entity_staff_list_data($entity_id, 1);
$self -> header_type('none');
print "Content-Disposition: attachment; filename =
staff-list.csv\n\n";
print map{join(',', map{qq|"$_"|} @{$$_{'td_loop'} }) . "\n"} @$data;
'';
Yes, that's the empty string being returned from this run mode!
4 Generating the data:
(If not downloading, some HTML column headers can be clicked to sort
on that column)
4a The headings, done once:
push @data,
{
css_class => 'head',
td_loop => [],
};
push @{$data[0]{'td_loop'} }, $download ? 'Phone' : $self -> link(1,
'e', "${entity_id}s", 'Phone') if ($self ->
user_display_option('phone_option') );
push @{$data[0]{'td_loop'} }, 'Title';
push @{$data[0]{'td_loop'} }, $download ? 'Name' : $self -> link(1,
'e', "${entity_id}p", 'Name');
push @{$data[0]{'td_loop'} }, 'Email' if ($self ->
user_display_option('email_option') );
push @{$data[0]{'td_loop'} }, $download ? 'Position' : $self ->
link(1, 'e', "${entity_id}j", 'Position') if ($self ->
user_display_option('position_option') );
4b The data, done once per person:
Get data from db...
push @data,
{
css_class => 'white',
td_loop => [],
};
push @{$data[$#data]{'td_loop'} }, $$_{'service_number'}
if ($self -> user_display_option('phone_option') );
push @{$data[$#data]{'td_loop'} }, $$_{'person_title'};
push @{$data[$#data]{'td_loop'} }, $$_{'person_name'};
push @{$data[$#data]{'td_loop'} }, $download ? $$_{'person_email'} :
qq|<nobr><a href =
"mailto:$$_{'person_email'}">$$_{'person_email'}</a></nobr>| if ($self
-> user_display_option('email_option') );
push @{$data[$#data]{'td_loop'} }, $download ? $$_{'position_title'}
: $self -> format_position($$_{'position_title'}) if ($self ->
user_display_option('position_option') );
...
suppressed;
Ie Return an array ref to both callers.
I had problems outputting (ie downloading) the data in the current
browser window, so I _always_ open a new window for the download. The
problems were that after the download, some of the buttons on the
previous (ie underlying) HTML page were no longer clickable, after the
user had saved the download. This could be Yet Another IE Problem, of
course (one of infinitely many).
We had to abandon Firefox, at least in the short term, even though the
corporate standard at that customer has just shifted from IE to
Mozilla: http://savage.net.au/Ron/html/firefox-v-0.9.1-bugs.html
As for Excel::Template (and PDF::Template), I did not know about those
until now. My superficial impression is that there is just a bit too
much overhead (complexity) there (especially for Excel) in solving
what is basically a simple problem, although I do appreciate a great
deal of effort has gone into those modules. I may well use them myself
one day.
--
Ron Savage, suppressed on 24/08/2004. Room EF 312
Deakin University, 221 Burwood Highway, Burwood, VIC 3125, Australia
Phone: +61-3-9251 7067, Fax: +61-3-9251 7604
http://www.deakin.edu.au/~rsav
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.