in reply to Re^3: Using Template::Toolkit with Excel files
in thread Using Template::Toolkit with Excel files
Hello Aldebaran, I finally got something neat that addresses 2 requirements : being able to access the XML and creating the XLS file for rendering to the user.
I'll share a piece of code below, which might answer your question about file/filename in the New() method.
I'm using 2 modules to achieve my objectives. Template & Excel::Template. I use the Template Toolkit to generate the required XML so that Excel::Template can produce the XLS. So my whole config generator engine benefits from TT and when I need an XLS file it's being treated separately.
use Template; use Excel::Template; sub xml_to_excel { my ($template_conf, $file, $hashref) = @_; # template configuration +from config file, filename based on request number, data for the tem +plate processing my $xml; my $tt = Template->new({ RELATIVE => 1, # in my case I had to use relative path +because of $template_conf->{file} based on CWD. }); $tt->process( $template_conf->{file}, $hashref, \$xml ) || die $tt->e +rror; # write the output to the $xml string open my $xml_fh, "<", \$xml; # create a filehandle from the $xml str +ing so that Excel::Template can read it. my $ET = Excel::Template->new({ file => $xml_fh, # use the filehandle here }); $ET->write_file($file); return $xml || 0; }
Hope this helps !
Luc
|
|---|