On Fri, Jan 07, 2005 at 10:45:38AM -0500, Sean T Allen wrote:
> Todd Freeman wrote:
>
> >Can't speak for the others... but personally I would love to be able to do
> >just that... being able to take one data set and do
> >
> >$template->process('pdf');
> >$template->process('html');
> >$template->process('excel');
> >
> >
>
> for any type of file or just a spreadsheet?
>
Well.. I am not thinking about "files" I am talking about taking a chunk of
data and formatting it appropriately for each output type. For example:
my $q = new CGI;
my $format = { blah => { heading => 'Blah $$!', align => 'right'},
de => { heading => 'Delicious!', align => 'center'},
foo => { heading => '# of Foo!', align => 'left'}
};
my $sth = $dbh->prepare($q->param('sql_query');
$sth->execute();
while( my $data = $sth->fetchrow_hashref())
{ push @rows, {%{$hash}}; }
my $vars = { format => $format, rows => [EMAIL PROTECTED], q => $q };
$tt->process('blah_' . $q->param('output_format'), $vars)
So then we have 3 templates:
--- blah_html.tt ---
[% q.start_html();
q.start_table();
q.start_Tr();
FOREACH column = rows.0.keys;
q.th(format.$column.heading);
END;
CGI.end_Tr();
FOREACH row = rows;
q.start_Tr();
FOREACH column = row.keys;
CGI.td({align=>format.$column.align}, row.$column);
END
q.end_Tr();
END;
q.end_table();
q.end_html();
%]
--------------------
--- blah_pdf.tt ---
[%- FILTER latex("pdf") -%]
\documentclass[12pt,letterpaper,landscape,nohead,nofoot]{report}
\usepackage{supertabular}
\begin{document}
\tablehead{ [%- FOREACH heading = rows.0.keys;
format.$heading.heading;
IF (! loop.last );
'&';
END;
END -%] }
\begin{supertabular}{[% FOREACH alignment = rows.0.keys;
format.$alignment.align.chunk(1).0; END [EMAIL PROTECTED]
[%- FOREACH row = rows;
FOREACH column = row.keys;
row.$column;
IF (! loop.last );
'&';
ELSE;
'\\';
END;
END;
END; -%]
\end{supertabular}
\end{document}
[%- END -%]
-------------------
--- blah_csv.tt ---
[%- FOREACH row = rows;
FOREACH column = row.keys;
row.$column;
IF (! loop.last );
"\t";
ELSE;
"\n";
END;
END;
END; -%]
-------------------
Not sure on the syntax for SpreadSheet::WriteExcel off the top of my head...
but I bet you can see how this is going...
Is a dead simple way to drop an SQL query into a program and get a report in
whatever format you want... especially if you let the user define the headings,
alignment and style on the page that they request the report from.
Anyways... yes the syntax is probably not correct... I just dropped this outta
my head on the fly so... don't think a copy paste is gonna work the first time
:P
--
Todd Freeman Ext 6103 .^. Don't fear the penguins!
Programming Department /V\
Andrews University // \\ http://www.linux.org/
http://www.andrews.edu/~freeman/ /( )\ http://www.debian.org/
^^ ^^
signature.asc
Description: Digital signature
