Excel::Template(3pm)
π Excel::Template π
okay bestie, listen β this is Excel::Template(3pm), a Perl module from the User Contributed Perl Documentation collection, and it's literally about making Excel files from templates. let me walk you through it, no cap π¦
β¨ SYNOPSIS β¨
first things first, you gotta make a template. it's an XML file that describes the layout of your spreadsheet. iconic behavior, honestly.
for example, test.xml:
<workbook>
<worksheet name="tester">
<cell text="$HOME" />
<cell text="$PATH" />
</worksheet>
</workbook>
now you write a lil 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');
and if everything worked, you should have a spreadsheet called text.xls in your working directory that looks something like this:
A B C
+----------------+----------------+----------------
1 | /home/me | /bin:/usr/bin |
+----------------+----------------+----------------
2 | | |
+----------------+----------------+----------------
3 | | |
slay π
πΈ 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, because they require replication of logic that's already been done within HTML::Template. so basically: why redo the work when you can just vibe with what already exists? π
π₯ MOTIVATION π₯
okay so here's the tea. the author does a lot of Perl/CGI for reporting purposes. in nearly every place they've been, they'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. they already had the data structure for the other templating modules, but they just didn't have an easy mechanism to get that data structure into an XLS file. tragic, right? not anymore bestie πβ¨
π USAGE π
π new()
this creates a Excel::Template object. main character energy fr.
Parameters
- FILE / FILENAME β
Excel::Templatewill parse the template in the given file or filehandle automatically. (you can also use theparse()method, described below.)
if you want to use the __DATA__ section, you can do so by passing
FILE => \*DATA
- RENDERER β the default rendering engine is
Spreadsheet::WriteExcel. you may, if you choose, change that to another choice. the legal values are:Excel::Template->RENDER_NMLβ this is the default ofSpreadsheet::WriteExcel.Excel::Template->RENDER_BIGβ this attempts to loadSpreadsheet::WriteExcel::Big.Excel::Template->RENDER_XMLβ this attempts to loadSpreadsheet::WriteExcelXML.
- USE_UNICODE β this will use
Unicode::Stringto represent strings instead of Perl's internal string handling. you must already haveUnicode::Stringinstalled on your system.
the USE_UNICODE parameter will be ignored if you are using Perl 5.8 or higher, as Perl's internal string handling is unicode-aware. periodt.
NOTE: certain older versions ofOLE::Storage_Liteandmod_perlclash for some reason. upgrading to the latest version ofOLE::Storage_Liteshould fix the problem. π
Deprecated
- BIG_FILE β instead, use
RENDERER => Excel::Template->RENDER_BIG. bestie, don't use the deprecated one, okay? π«Ά
π 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. dramatic but fair.
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.
- WORKBOOK β this is the node representing the workbook. it is the parent for all other nodes. the mother of the group chat, if you will.
- WORKSHEET β this is the node representing a given worksheet.
- IF β this node represents a conditional expression. its children may or may not be rendered. it behaves just like
HTML::Template'sTMPL_IF. - LOOP β this node represents a loop. it behaves just like
HTML::Template'sTMPL_LOOP. - ROW β this node represents a row of data. this is the 1 in
A1. there is noCOLUMNnode, as of yet. - FORMAT β this node varies the format for its children. all formatting options supported in
Spreadsheet::WriteExcelare supported here. there are also a number of formatting shortcuts, such asBOLDandITALIC. - BACKREF β this refers back to a cell previously named.
- CELL β this is the actual cell in a spreadsheet.
- FORMULA β this is a formula in a spreadsheet.
- RANGE β this is a
BACKREFfor a number of identically-named cells. - VAR β this is a variable. it is generally used when the
'text'attribute isn't sufficient.
π BUGS π
none, that I know of. (bestie said "no bugs, only vibes" π§)
π SUPPORT π
this is production quality software, used in several production web applications. she's literally employed. π
π«Ά MAINTAINERS π«Ά
Jens Gassmann <jegade@cpan.org>
Robert Bohne <rbo@cpan.org>
Rob Kinyon <rkinyon@cpan.org>
π CONTRIBUTORS π
there is a mailing list at http://groups.google.com/group/ExcelTemplate or exceltemplate@googlegroups.com β come hang out!
πΈ Robert Bohne <rbo@cpan.org>
- Swichting to
Module::Install - Add autofilter to worksheet
πΈ Robert Graff
- Finishing formats
- Fixing several bugs in worksheet naming
πΈ Jens Gassmann
- Add
hide_gridlinesto worksheet
β TEST COVERAGE β
the author uses Devel::Cover to test the coverage of the tests. every release, they intend to improve these numbers. we love a growth mindset. π
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. iykyk β¨
---------------------------- ------ ------ ------ ------ ------ ------ ------
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
and that's the whole page bestie π this was Excel::Template, documented for perl v5.34.0, last touched 2022-06-13. go make some spreadsheets, you absolute icon πβ¨
π¦ where this page comes from
- debian bookworm: libexcel-template-perl 0.34-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libexcel-template-perl 0.34-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libexcel-template-perl 0.34-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libexcel-template-perl 0.34-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libexcel-template-perl 0.34-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms