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: https://metacpan.org/pod/Excel::Template.
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:
$ ./2.excel.pl
abs is /home/bob/Documents/meditations/2.excel.pl
path1 is /home/bob/Documents/meditations
path2 is /home/bob/Documents/meditations/template_stuff
This script will build path2? Abort with ctrl-c.
$VAR1 = {
'monk_tags' => bless( [
'/home/bob/Documents/meditations/tem
+plate_stuff/1.test.xml',
'/home/bob/Documents/meditations/tem
+plate_stuff/1.test.xml'
], 'Path::Tiny' ),
'book' => 'excel template example ',
'output' => bless( [
'/home/bob/Documents/meditations/templa
+te_stuff/output',
'/home/bob/Documents/meditations/templa
+te_stuff/output'
], 'Path::Tiny' )
};
string monk is /home/bob/Documents/meditations/template_stuff/1.test.x
+ml
string save is /home/bob/Documents/meditations/template_stuff/output/3
+0-11-2018-17-15-37.monk.txt
Not a GLOB reference at /usr/local/share/perl/5.26.1/Spreadsheet/Write
+Excel/OLEwriter.pm line 250.
(in cleanup) Not a GLOB reference at /usr/local/share/perl/5.26.1/
+Spreadsheet/WriteExcel/OLEwriter.pm line 418.
$ cat 2.excel.pl
#!/usr/bin/perl -w
use 5.011;
use Path::Tiny;
use POSIX qw(strftime);
use Data::Dumper;
# initialization that must precede main data structure
# User: enter a subdirectory you would like to create
# enter a subdirectory of this^^^ for output
my $ts = "template_stuff";
my $output = "output";
# User: enter a name for a template file
my $template_file = "1.test.xml";
## turning things to Path::Tiny
my $abs = path(__FILE__)->absolute;
my $path1 = Path::Tiny->cwd;
my $path2 = path( $path1, $ts );
say "abs is $abs";
say "path1 is $path1";
say "path2 is $path2";
print "This script will build path2? Abort with ctrl-c.";
my $prompt = <STDIN>;
chomp $prompt;
die if ( $prompt eq "n" );
# Path::Tiny creates $ts directory if necessary
my $abs_to_template = path( $path2, $template_file )->touchpath;
# script params
my %vars = (
monk_tags => path( $path2, $template_file ),
output => path( $path2, $output ),
book => 'excel template example ',
);
my $rvars = \%vars;
print Dumper $rvars;
my $munge = strftime( "%d-%m-%Y-%H-%M-%S", localtime );
$munge .= ".monk.txt";
# use Path::Tiny to create and write to a text in relevant directory
my $save_file = path( $vars{output}, $munge )->touchpath;
## stringify input and output files for export
my $string_monk = $vars{monk_tags}->stringify;
say "string monk is $string_monk";
my $string_save = $save_file->stringify;
say "string save is $string_save";
## end preliminaries
# keep time
my $start = time;
use Excel::Template;
# Create the Excel template
my $template = Excel::Template->new( filename => $string_monk, );
# Add a few parameters
$template->param(
HOME => $ENV{HOME},
PATH => $ENV{PATH},
);
$template->write_file($save_file);
say time - $start, "seconds elapsed during execution";
say "created file $save_file";
system("gedit $save_file &");
__END__
$
Then I read further on the cpan site that I can get the data from __DATA__ with FILE => \*DATA . I give that a whirl:
$ ./3.excel.pl
abs is /home/bob/Documents/meditations/3.excel.pl
path1 is /home/bob/Documents/meditations
path2 is /home/bob/Documents/meditations/template_stuff
This script will build path2. Abort with ctrl-c.$VAR1 = {
'output' => bless( [
'/home/bob/Documents/meditations/templa
+te_stuff/output',
'/home/bob/Documents/meditations/templa
+te_stuff/output'
], 'Path::Tiny' ),
'book' => 'excel template example ',
'monk_tags' => bless( [
'/home/bob/Documents/meditations/tem
+plate_stuff/1.test.xml',
'/home/bob/Documents/meditations/tem
+plate_stuff/1.test.xml'
], 'Path::Tiny' )
};
string monk is /home/bob/Documents/meditations/template_stuff/1.test.x
+ml
string save is /home/bob/Documents/meditations/template_stuff/output/3
+0-11-2018-10-58-04.monk.txt
Not a GLOB reference at /usr/local/share/perl/5.26.1/Spreadsheet/Write
+Excel/OLEwriter.pm line 250, <INFILE> line 0.000000.
(in cleanup) Not a GLOB reference at /usr/local/share/perl/5.26.1/
+Spreadsheet/WriteExcel/OLEwriter.pm line 418, <INFILE> line 0.000000.
$ ./3.excel.pl
abs is /home/bob/Documents/meditations/3.excel.pl
path1 is /home/bob/Documents/meditations
path2 is /home/bob/Documents/meditations/template_stuff
This script will build path2. Abort with ctrl-c or n.standard in waits
+ for you
$VAR1 = {
'monk_tags' => bless( [
'/home/bob/Documents/meditations/tem
+plate_stuff/1.test.xml',
'/home/bob/Documents/meditations/tem
+plate_stuff/1.test.xml'
], 'Path::Tiny' ),
'book' => 'excel template example ',
'output' => bless( [
'/home/bob/Documents/meditations/templa
+te_stuff/output',
'/home/bob/Documents/meditations/templa
+te_stuff/output'
], 'Path::Tiny' )
};
string monk is /home/bob/Documents/meditations/template_stuff/1.test.x
+ml
string save is /home/bob/Documents/meditations/template_stuff/output/3
+0-11-2018-11-07-45.monk.txt
Not a GLOB reference at /usr/local/share/perl/5.26.1/Spreadsheet/Write
+Excel/OLEwriter.pm line 250, <INFILE> line 0.000000.
(in cleanup) Not a GLOB reference at /usr/local/share/perl/5.26.1/
+Spreadsheet/WriteExcel/OLEwriter.pm line 418, <INFILE> line 0.000000.
$ cat 3.excel.pl
#!/usr/bin/perl -w
use 5.011;
use Path::Tiny;
use POSIX qw(strftime);
use Data::Dumper;
# initialization that must precede main data structure
# User: enter a subdirectory you would like to create
# enter a subdirectory of this^^^ for output
my $ts = "template_stuff";
my $output = "output";
# User: enter a name for a template file
my $template_file = "1.test.xml";
## turning things to Path::Tiny
my $abs = path(__FILE__)->absolute;
my $path1 = Path::Tiny->cwd;
my $path2 = path( $path1, $ts );
say "abs is $abs";
say "path1 is $path1";
say "path2 is $path2";
say "This script will build path2. Abort with ctrl-c or n.";
print "standard in waits for you";
my $prompt = <STDIN>;
chomp $prompt;
die if ( $prompt eq "n" );
# Path::Tiny creates $ts directory if necessary
my $abs_to_template = path( $path2, $template_file )->touchpath;
# script params
my %vars = (
monk_tags => path( $path2, $template_file ),
output => path( $path2, $output ),
book => 'excel template example ',
);
my $rvars = \%vars;
print Dumper $rvars;
my $munge = strftime( "%d-%m-%Y-%H-%M-%S", localtime );
$munge .= ".monk.txt";
# use Path::Tiny to create and write to a text in relevant directory
my $save_file = path( $vars{output}, $munge )->touchpath;
## stringify input and output files for export
my $string_monk = $vars{monk_tags}->stringify;
say "string monk is $string_monk";
my $string_save = $save_file->stringify;
say "string save is $string_save";
## end preliminaries
# keep time
my $start = time;
use Excel::Template;
# Create the Excel template
my $template = Excel::Template->new( FILE => \*DATA );
# Add a few parameters
$template->param(
HOME => $ENV{HOME},
PATH => $ENV{PATH},
);
$template->write_file($save_file);
say time - $start, "seconds elapsed during execution";
say "created file $save_file";
system("gedit $save_file &");
__DATA__
<workbook>
<worksheet name="tester">
<cell text="$HOME" />
<cell text="$PATH" />
</worksheet>
</workbook>
$
Same error:
Not a GLOB reference at /usr/local/share/perl/5.26.1/Spreadsheet/Write
+Excel/OLEwriter.pm line 250, <INFILE> line 0.000000.
(in cleanup) Not a GLOB reference at /usr/local/share/perl/5.26.1/
+Spreadsheet/WriteExcel/OLEwriter.pm line 418, <INFILE> line 0.000000.
I hope we can figure this out....