Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^4: Using Template::Toolkit with Excel files

by llarochelle (Beadle)
on Dec 07, 2018 at 15:40 UTC ( [id://1226898]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1226898]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found