Jens Gassmann > Excel-Template-0.31 > Excel::Template

Download:
Excel-Template-0.31.tar.gz

Dependencies

Annotate this POD

Related Modules

HTML::Template
PDF::Template
CGI::Application
PDF::API2
HTML::Mason
Win32::OLE
HTML::Dashboard
WWW::Mechanize
Class::DBI
GD::Graph
more...
By perlmonks.org

CPAN RT

New  3
Open  1
View/Report Bugs
Module Version: 0.31   Source   Latest Release: Excel-Template-0.34

NAME ^

Excel::Template - Excel::Template

SYNOPSIS ^

First, make a template. This is an XML file, describing the layout of the spreadsheet.

For example, test.xml:

  <workbook>
      <worksheet name="tester">
          <cell text="$HOME" />
          <cell text="$PATH" />
      </worksheet>
  </workbook>

Now, create a small program to use it:

  #!/usr/bin/perl -w

  use strict;

  use Excel::Template;

  # Create the Excel template
  my $template = Excel::Template->new(
      filename => 'test.xml',
  );

  # Add a few parameters
  $template->param(
      HOME => $ENV{HOME},
      PATH => $ENV{PATH},
  );

  $template->write_file('test.xls');

If everything worked, then you should have a spreadsheet called text.xls in your working directory that looks something like:

             A                B                C
    +----------------+----------------+----------------
  1 | /home/me       | /bin:/usr/bin  |
    +----------------+----------------+----------------
  2 |                |                |
    +----------------+----------------+----------------
  3 |                |                |

DESCRIPTION ^

This is a module used for templating Excel files. Its genesis came from the need to use the same datastructure as HTML::Template, but provide Excel files instead. The existing modules don't do the trick, as they require replication of logic that's already been done within HTML::Template.

MOTIVATION ^

I do a lot of Perl/CGI for reporting purposes. In nearly every place I've been, I've been asked for HTML, PDF, and Excel. HTML::Template provides the first, and PDF::Template does the second pretty well. But, generating Excel was the sticking point. I already had the data structure for the other templating modules, but I just didn't have an easy mechanism to get that data structure into an XLS file.

USAGE ^

new()

This creates a Excel::Template object.

Parameters

Deprecated

param()

This method is exactly like HTML::Template's param() method.

parse() / parse_xml()

This method actually parses the template file. It can either be called separately or through the new() call. It will die() if it runs into a situation it cannot handle.

If a filename is passed in (vs. a filehandle), the directory name will be passed in to XML::Parser as the Base parameter. This will allow for XML directives to work as expected.

write_file()

Create the Excel file and write it to the specified filename, if possible. (This is when the actual merging of the template and the parameters occurs.)

output()

It will act just like HTML::Template's output() method, returning the resultant file as a stream, usually for output to the web. (This is when the actual merging of the template and the parameters occurs.)

register()

This allows you to register a class as handling a node. q.v. Excel::Template::Factory for more info.

SUPPORTED NODES ^

This is a partial list of nodes. See the other classes in this distro for more details on specific parameters and the like.

Every node can set the ROW and COL parameters. These are the actual ROW/COL values that the next CELL-type tag will write into.

BUGS ^

None, that I know of.

SUPPORT ^

This is production quality software, used in several production web applications.

AUTHOR ^

    Rob Kinyon (rob.kinyon@gmail.com)

CONTRIBUTORS ^

There is a mailing list at http://groups.google.com/group/ExcelTemplate or exceltemplate@googlegroups.com

Robert Graff

TEST COVERAGE ^

I use Devel::Cover to test the coverage of my tests. Every release, I intend to improve these numbers.

Excel::Template is also part of the CPAN Kwalitee initiative, being one of the top 100 non-core modules downloaded from CPAN. If you wish to help out, please feel free to contribute tests, patches, and/or suggestions.

  ---------------------------- ------ ------ ------ ------ ------ ------ ------
  File                           stmt   bran   cond    sub    pod   time  total
  ---------------------------- ------ ------ ------ ------ ------ ------ ------
  blib/lib/Excel/Template.pm     93.8   60.0   58.8  100.0  100.0   31.8   83.3
  ...ib/Excel/Template/Base.pm   94.4   50.0    n/a  100.0    0.0    4.4   80.0
  ...cel/Template/Container.pm  100.0   50.0   33.3  100.0    0.0    2.0   83.3
  ...emplate/Container/Bold.pm  100.0    n/a    n/a  100.0    0.0    0.1   95.0
  .../Container/Conditional.pm   95.9   90.0   66.7  100.0    0.0    0.3   91.0
  ...plate/Container/Format.pm  100.0    n/a    n/a  100.0    0.0    1.5   96.8
  ...plate/Container/Hidden.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
  ...plate/Container/Italic.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
  ...ainer/KeepLeadingZeros.pm  100.0  100.0    n/a  100.0    0.0    0.0   96.3
  ...plate/Container/Locked.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
  ...emplate/Container/Loop.pm   96.8   50.0   50.0  100.0    0.0    0.1   82.7
  ...late/Container/Outline.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
  ...Template/Container/Row.pm  100.0   75.0    n/a  100.0    0.0    0.1   90.6
  ...mplate/Container/Scope.pm  100.0    n/a    n/a  100.0    n/a    0.0  100.0
  ...plate/Container/Shadow.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
  ...te/Container/Strikeout.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.0
  ...ate/Container/Workbook.pm  100.0    n/a    n/a  100.0    n/a    7.0  100.0
  ...te/Container/Worksheet.pm   95.5   87.5  100.0  100.0    0.0    1.1   90.2
  ...Excel/Template/Context.pm   98.0   80.0   75.0  100.0   73.3   17.0   90.7
  ...Excel/Template/Element.pm  100.0    n/a    n/a  100.0    n/a    0.1  100.0
  ...mplate/Element/Backref.pm  100.0   50.0   33.3  100.0    0.0    0.1   87.1
  .../Template/Element/Cell.pm   97.9   75.0   80.0  100.0    0.0    5.6   88.6
  ...mplate/Element/Formula.pm  100.0    n/a    n/a  100.0    0.0    0.0   94.1
  ...te/Element/FreezePanes.pm  100.0    n/a    n/a  100.0    0.0    0.0   95.5
  ...Template/Element/Image.pm  100.0  100.0    n/a  100.0    0.0    0.0   94.3
  ...Template/Element/Range.pm  100.0   66.7    n/a  100.0    0.0    0.1   88.9
  ...l/Template/Element/Var.pm  100.0    n/a    n/a  100.0    0.0    0.0   94.1
  ...Excel/Template/Factory.pm  100.0   73.1   66.7  100.0  100.0   22.3   91.4
  .../Excel/Template/Format.pm   98.4   75.0   33.3  100.0   66.7    2.6   90.5
  ...xcel/Template/Iterator.pm   98.6   80.0   70.6  100.0   50.0    0.3   88.8
  ...el/Template/TextObject.pm   92.9   62.5   33.3  100.0    0.0    3.3   80.9
  Total                          97.8   74.7   64.6  100.0   35.7  100.0   89.4
  ---------------------------- ------ ------ ------ ------ ------ ------ ------

COPYRIGHT ^

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO ^

perl(1), HTML::Template, Spreadsheet::WriteExcel

syntax highlighting: