Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Using Template::Toolkit with Excel files

by iguanodon (Priest)
on Nov 29, 2018 at 14:18 UTC ( #1226500=note: print w/replies, xml ) Need Help??

in reply to Using Template::Toolkit with Excel files

Have you looked at Excel::Template ?
  • Comment on Re: Using Template::Toolkit with Excel files

Replies are listed 'Best First'.
Re^2: Using Template::Toolkit with Excel files
by llarochelle (Beadle) on Nov 29, 2018 at 15:16 UTC

    Well, it's funny 'cause after writing this post, I realized the benefits of writing down a problem

    a) My post is so unclear which means I don't understand totally what's going on
    b) It forced me to look again what's available out there. Maybe my nose was stuck in my problem.

    So I found Excel::Template and Excel::Template::Plus which allows to change the engine (TT for instance). I know why I overlooked Excel::Template, since at the beginning I thought it would be nice to allow the network guys to consult their template at any time (in the original Excel format) but now that I've played a lot with the Excel modules, and learned a bit more about it's behavior ... I dunno maybe I could create a nice display in a webpage from the xml structure used for the template.

      So I found Excel::Template

      I thought you might head down this path and got to work trying to work up an example, but I have failed. The example I was shooting for was the one right on the cpan site:

      I worked it up two different ways and get the same error, so I'm hoping that my failure is diagnostic for the many contributors to the monastery whose experience in this is greater than mine. So far, I only have 2 failures.

      At first, I thought my input file wasn't correct on the path, but I took the extra measure of stringifying the Path::Tiny values, with the attending certainty and liternalness of a string, and there is a file there with the xml example in it:

      Then I read further on the cpan site that I can get the data from __DATA__ with FILE => \*DATA . I give that a whirl:

      Same error:

      Not a GLOB reference at /usr/local/share/perl/5.26.1/Spreadsheet/Write +Excel/ line 250, <INFILE> line 0.000000. (in cleanup) Not a GLOB reference at /usr/local/share/perl/5.26.1/ +Spreadsheet/WriteExcel/ line 418, <INFILE> line 0.000000.

      I hope we can figure this out....

        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 !


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2022-05-29 10:54 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (101 votes). Check out past polls.