Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Excel::Template final XML file

by llarochelle (Beadle)
on Dec 05, 2018 at 15:30 UTC ( [id://1226770]=perlquestion: print w/replies, xml ) Need Help??

llarochelle has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, I finally gave a try to Excel::Template and I can create xls files easily. I wonder if there's a way to access ( print, save ) the generated XML used to produce the XLS file ? I've looked into the methods and could't find out.

Replies are listed 'Best First'.
Re: Excel::Template final XML file
by poj (Abbot) on Dec 05, 2018 at 17:58 UTC
    I've looked into the methods and could't find out.

    Looking at the source, you should be able to access the tempfile name using $template->{tempfile}

    #!/usr/bin/perl use strict; use Excel::Template::TT; # some TT options my $config = { INTERPOLATE => 1, EVAL_PERL => 1, }; # set variables for replacement my $vars = { host => { cmts => { name => 'name' }, interfaces => [ { bundle => 'bundle1', subBundle => 'subBundle1', secondaries => [ { ipAddress => '198.168.0.1', subnetMask => '255.255.255.0', },],},],}, }; # create object my $template = Excel::Template::TT->new( filename => 'sample.xml', config => $config, VARS => $vars, ); # xml template file created my $xml = $template->{tempfile}; open IN,'<',$xml or die "$!"; print $_ for <IN>; close IN; $template->write_file('sample.xls'); system('excel sample.xls')
    poj
      Hi poj, well I looked into the documentation ... I have to develop this reflex and look into the source code !

      This is great news, I tried that piece of code and it's working out perfectly

      Many thanks
Re: Excel::Template final XML file
by marto (Cardinal) on Dec 05, 2018 at 15:42 UTC

    Doesn't Excel::Template simply use an XML file as the template input? What's preventing you from accessing this in the normal way? John McNamara has produced a lot of tools over the years for making working with Excel in a perlish way simple, for example Excel::Writer::XLSX.

      Hi marto, you're absolutely right. But since the template contains loop instructions, I'd like to be able to give the user a preview with some sample data. My objective is to use the XML of a sample template to display in a webpage. My actual XML template is not intelligible.

      Edit : I forgot to mention, I'm using the wrapper Excel::Template::TT

      <workbook> <worksheet name="Configuration"><format color="black"> <row><bold><cell text="!!!!!!!!! [% host.cmts.name %] !!!!!!!!!!" +/></bold></row> <row /> [% FOREACH int IN host.interfaces %] <row><cell text="interface ip-bundle [% int.bundle %].[% int.subBu +ndle %]" /></row> [%- FOREACH ip IN int.secondaries %] <row><cell text=" ip address [% ip.ipAddress %] [% ip.subnetMask % +] secondary" /></row> [%- END %] [% END %] <row /> <row><bold><cell text="!!!!!!!!! END : [% host.cmts.name %] !!!!!! +!!!!" /></bold></row> </format> </worksheet> </workbook>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-18 00:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found